javascript - Can't understand zone.js example -


here's code demonstrating zone.js capabilities here:

zone.current.fork({}).run(function () {     zone.current.inthezone = true;      settimeout(function () {         console.log('in zone: ' + !!zone.current.inthezone);     }, 0); });  console.log('in zone: ' + !!zone.current.inthezone); 

the above log:

'in zone: false'  'in zone: true' 

i don't understand zone doing here , how's related intercepting events this video talks about.

it outputs false first time because zone.current.inthezone undefined, , since changed zone.current.inthezone = true; value ouputted second time. what's special zone doing here?

zone allows persist properties across asynchronous operations encapsulated within zone. here shows there's no inthezone property attached current zone. when executed zone.fork().run() callback executed in new forked zone , async task settimeout executed in forked zone well. , inthezone property inside zone won't accessible in other zones. here better example:

zone.current.fork({}).run(function () {     zone.current.inthezone = true;      settimeout(function () {         console.log('in zone: ' + !!zone.current.inthezone); // true     }, 2000); });  settimeout(function () {     console.log('in zone: ' + !!zone.current.inthezone); // false }, 1000); 

as can see there 2 async tasks here. , settimeout current zone executed earlier timeout forked zone. run() synchrounous inthezone should set true before first settimetout executed. it's logged false because current zone can't access property forked zone.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -