Date: Tue, 22 Aug 2017 10:00:00 +0000
<div class="trix-content"> <div><strong>JSJ 275: Zones in Node with Austin McDaniel</strong></div><div>The panel for this week on JavaScript Jabber is Cory House, Aimee Knight, and Charles Max Wood. They speak with special guest Austin McDaniel about Zones in Node. Tune in to learn more about this topic!</div><div><strong>[00:01:11] Introduction to Austin </strong></div><div>Austin has worked in JavaScript for the past ten years. He currently works in Angular development and is a panelist on Angular Air. He has spent most of his career doing work in front-end development but has recently begun working with back-end development. With his move to back-end work he has incorporated front-end ideas with Angular into a back-end concept.</div><div><strong>[00:02:00] The Way it Works</strong></div><div>NodeJS is an event loop. There is no way to scope the context of a call stack. So for example, Austin makes a Node request to a server and wants to track the life cycle of that Node request. Once deep in the scope, or deep in the code, it is not easy to get the unique id. Maybe he wants to get the user from Passport JS. Other languages – Python, Java – have a concept called thread local storage. They can associate context with the thread and throughout the life cycle of that request, he can retrieve that context.</div><div>There is a TC39 proposal for zones<strong>. </strong>A zone allows you to do what was just described. They can create new zones and associate data with them. Zones can also associate unique ids for requests and can associate the user so they can see who requested later in the stack. Zones also allow to scope and create a context. And then it allows scoping requests and capturing contacts all the way down.</div><div><strong>[00:05:40] Zone Uses</strong></div><div>One way Zone is being used is to capture stack traces, and associating unique ids with the requests. If there is an error, then Zone can capture a stack request and associate that back to the request that happened. Otherwise, the error would be vague.</div><div>Zones are a TC39 proposal. Because it is still a proposal people are unsure how they can use it. Zones are not a new concept. Austin first saw Zones being used back when Angular 2 was first conceived. If an event happened and they wanted to isolate a component and create a scope for it, they used Zones to do so. Not a huge fan of how it worked out (quirky). He used the same library that Angular uses in his backend. It is a specific implementation for Node. Monkey patches all of the functions and creates a scope and passes it down to your functions, which does a good job capturing the information.</div><div><strong>[00:08:40] Is installing the library all you need to get this started?</strong></div><div>Yes, go to npminstallzone.js and install the library. There is a middler function for kla. To fork the zone, typing zone.current. This takes the Zone you are in and creates a new isolated Zone for that fork. A name can then be created for the Zone so it can be associated back with a call stack and assigned properties. Later, any properties can be retrieved no matter what level you are at.</div><div><strong>[00:09:50] So did you create the Zone library or did Google?</strong></div><div>The Google team created the Zone library. It was introduced in 2014 with Angular 2. It is currently used in front-end development.</div><div><strong>[00:10:12] Is the TC39 proposal based on the Zone library?</strong></div><div>While Austin has a feeling that the TC39 proposal came out of the Zone library, he cannot say for sure.</div><div><strong>[00:10:39] What stage is the proposal in right now?</strong></div><div>Zone is in Stage Zero right now. Zone JS is the most popular version because of its forced adoption to Angular. He recommends people use the Angular version because it is the most tested as it has a high number of people using it for front-end development.</d... Support this podcast at — https://redcircle.com/javascript-jabber/donations Advertising Inquiries: https://redcircle.com/brands Privacy & Opt-Out: https://redcircle.com/privacy