4 ms·
Seriously zone.js is enough to just walk away
by bythreads 5y ago
Seriously zone.js is enough to just walk away
- rezonant 5y agoZone.js is very useful. You can observe the life time of a chain of asynchronous operations without requiring that they return promises or use callbacks. This makes it very useful for providing "no code" SSR of an otherwise frontend framework. You can reliably know when the page has completed rendering, because the zone has become "stable", that is to say it no longer has any way to run any handlers for future events. Zone locals also allow you to maintain "task-specific" state, for instance allowing you to access the current request being processed without it being passed around. Another use case is having your logger show context information- Frameworks like RoR have done this forever- they show the request ID on each log message that results from processing that request. I don't think there's any good way short of passing the logger around everywhere to pull that off in Javascript short of using Zones. What it does to Promise and other parts is definitely an annoyance, but the benefits you get for it are a lot. If Zones were a standard part of the JS runtime none of that "patch the world" would be needed, as the JS runtime would support it out the gate. Zone.js was always meant to be a polyfill of the Zone concept on the way to standardization. It is unfortunate that standardization has failed because I think it's a very useful idea and there isn't any real alternative to achieve the same goals.
- josteink 5y agoAnd don’t get me started on silently hijacking my clean ES-promises and turning them into Angular’s own ZoneAwarePromise, managed by its own terrible, undebuggable microqueue. It’s literally impossible to write clean code which compiles to clean code with Angular.