canjs / can-zone

A context for tracking asynchronous activity in JavaScript applications.
https://v4.canjs.com/doc/can-zone.html
MIT License
92 stars 4 forks source link

Zone implementation discussion #57

Closed matthewp closed 8 years ago

matthewp commented 8 years ago

@justinbmeyer today mentioned an alternative implementation. Want to break down the current implementation and compare it to the other, to discuss their strengths and weaknesses.

1. Wrap when each task is run

This is how it is currently implemented. Each time a Task is run we setup the globals and after the Task completes we restore the original values.

Strength

ourSetTimeout(someOtherSetTimeout(realSetTimeout()))

This is important so that we can ensure all Tasks run within a Zone.

Weakness

This would be if the wrapping only happen

Strength

I think this is probably possible, use method 1 to ensure our versions are the outer layer of the onion and method 2 to ensure local references are covered.

matthewp commented 8 years ago

It's possible #2 would work on it's own. Even if code does override globals, it eventually does have to call something asynchronous, so eventually one of our globals would be used (global.Promise might be overridden but underlying that it would use MutationObserver). It's worth giving a shot.

matthewp commented 8 years ago

Closed by #63