@checle/zones
Advanced tools
+1
-1
@@ -16,3 +16,3 @@ /// <reference path='node_modules/@types/core-js/index.d.ts' /> | ||
| interface Zone extends EventTarget, Node { | ||
| name: string | ||
| readonly name: string | ||
| onerror?: Function | ||
@@ -19,0 +19,0 @@ onfinish?: Function |
+18
-11
@@ -159,7 +159,19 @@ 'use strict'; | ||
| enter(zone) { | ||
| global.zone = zone; | ||
| } | ||
| run(entry, thisArg = undefined, ...args) { | ||
| let lastZone; | ||
| let enter = () => (lastZone = zone, zone = this); | ||
| let exit = () => zone = lastZone; | ||
| let enter = () => { | ||
| lastZone = global.zone; | ||
| this.enter(this); | ||
| }; | ||
| let exit = () => { | ||
| if (lastZone) this.enter(lastZone); | ||
| }; | ||
| try { | ||
@@ -182,3 +194,3 @@ enter(); | ||
| return new Promise((resolve, reject) => { | ||
| let child = zone.appendChild(new Zone(entry.name)); | ||
| let child = this.appendChild(new Zone(entry.name)); | ||
| let promise = child.run(...arguments); | ||
@@ -196,3 +208,4 @@ | ||
| Object.assign(Zone.prototype, { | ||
| onfinish: null | ||
| onfinish: null, | ||
| onerror: null | ||
| }); | ||
@@ -203,8 +216,2 @@ | ||
| let zone = new Zone(); | ||
| Object.defineProperty(typeof global === 'undefined' ? self : global, 'zone', { | ||
| get() { | ||
| return zone; | ||
| } | ||
| }); | ||
| global.zone = new Zone(); |
+1
-1
| { | ||
| "name": "@checle/zones", | ||
| "version": "0.7.0", | ||
| "version": "0.7.1", | ||
| "description": "Simplistic, promise-based zones", | ||
@@ -5,0 +5,0 @@ "main": "dist/main.js", |
+30
-24
@@ -53,3 +53,3 @@ # zones | ||
| * [Extend zones](#extend-zones) | ||
| * [Override run()](#override-run) | ||
| * [Override enter()](#override-enter) | ||
| * [Run untrusted code asynchronously](#run-untrusted-code-asynchronously) | ||
@@ -127,3 +127,3 @@ | ||
| Add custom properties to `Zone.current` by inheritance. | ||
| Add custom properties to `zone` by inheritance. | ||
@@ -140,4 +140,4 @@ ```javascript | ||
| function routine () { | ||
| if (Zone.current instanceof CustomEnvironment) { | ||
| console.log('My environment was created at ' + this.created) | ||
| if (global.zone instanceof CustomEnvironment) { | ||
| console.log('My environment was created at ' + global.zone.created) | ||
| } else { | ||
@@ -153,18 +153,19 @@ console.log("I think I've been running forever") | ||
| ### Override run() | ||
| ### Override enter() | ||
| You can hook into zone operations overriding `run()`. | ||
| You can hook into zone operations overriding `enter()`. | ||
| ```javascript | ||
| let lastDomain | ||
| class MozillaZone extends Zone { | ||
| run (func) { | ||
| let previousDomain = global.domain | ||
| enter (zone) { | ||
| if (zone instanceof MozillaZone) { | ||
| lastDomain = global.domain | ||
| global.domain = 'mozilla.org' | ||
| } else { | ||
| global.domain = lastDomain | ||
| } | ||
| try { | ||
| global.domain = 'mozilla.org' // Switch global domain during run() | ||
| return super.run(func) | ||
| } finally { | ||
| global.domain = previousDomain // Restore global domain | ||
| } | ||
| super.enter(zone) | ||
| } | ||
@@ -216,3 +217,3 @@ } | ||
| ```typescript | ||
| zone: Zone // Gets the current zone | ||
| zone: Zone // Get the current zone | ||
@@ -224,13 +225,13 @@ interface Task extends Event { | ||
| interface Zone extends EventTarget, Node { | ||
| name: string | ||
| root: Zone | ||
| onerror?: Function | ||
| onfinish?: Function | ||
| onerror?: Function // Set 'error' event handler | ||
| onfinish?: Function // Set 'finish' event handler | ||
| readonly tasks: Map<any, Task> | ||
| readonly children: Zone[] | ||
| readonly root: Zone | ||
| readonly name: any // Optional name, e.g., for debugging | ||
| readonly tasks: Map<any, Task> // Pending tasks | ||
| readonly children: Zone[] // Associated children, modifiable by the DOM | ||
| readonly root: Zone // Root zone - all error events bubble towards this zone | ||
| constructor (nameOrSpec?: any) | ||
| // Add and manage custom tasks | ||
| addTask (task: Task): number | ||
@@ -243,5 +244,7 @@ setTask (id: any, task: Task): this | ||
| // Run function inside zone | ||
| run (entry: Function, thisArg?: any, ...args: any[]): any | ||
| // Bind function to zone | ||
| bind (fn: Function): Function | ||
| // Cancels all tasks and child zones by default | ||
| // Cancels all child zones and pending tasks | ||
| cancel (): Promise<void> | ||
@@ -251,6 +254,9 @@ // Spawns a new child zone, runs `entry` in it and resolves when all new tasks have been worked off | ||
| // Add event listeners | ||
| addEventListener (type: 'finish' | 'error', listener: Function, options: any): void | ||
| // Modify the DOM - affects which children will be cancelled on `cancel()` and where 'error' events will bubble to | ||
| appendChild (node: Zone): this | ||
| } | ||
| // Zone-enabled standard API | ||
| function setTimeout (handler, timeout, ...args) | ||
@@ -257,0 +263,0 @@ function setInterval (handler, timeout, ...args) |
+18
-11
@@ -153,7 +153,19 @@ import {CustomEvent, DOMException, Node} from './dom.js' | ||
| enter (zone) { | ||
| global.zone = zone | ||
| } | ||
| run (entry, thisArg = undefined, ...args) { | ||
| let lastZone | ||
| let enter = () => (lastZone = zone, zone = this) | ||
| let exit = () => (zone = lastZone) | ||
| let enter = () => { | ||
| lastZone = global.zone | ||
| this.enter(this) | ||
| } | ||
| let exit = () => { | ||
| if (lastZone) this.enter(lastZone) | ||
| } | ||
| try { | ||
@@ -176,3 +188,3 @@ enter() | ||
| return new Promise((resolve, reject) => { | ||
| let child = zone.appendChild(new Zone(entry.name)) | ||
| let child = this.appendChild(new Zone(entry.name)) | ||
| let promise = child.run(...arguments) | ||
@@ -189,3 +201,4 @@ | ||
| Object.assign(Zone.prototype, { | ||
| onfinish: null | ||
| onfinish: null, | ||
| onerror: null, | ||
| }) | ||
@@ -195,8 +208,2 @@ | ||
| let zone = new Zone() | ||
| Object.defineProperty(typeof global === 'undefined' ? self : global, 'zone', { | ||
| get () { | ||
| return zone | ||
| } | ||
| }) | ||
| global.zone = new Zone() |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
29144
1.67%723
1.12%264
2.33%0
-100%