@pnp/core
Advanced tools
Comparing version
@@ -9,2 +9,15 @@ import { ObserverAction, ObserverFunction, Timeline } from "./timeline.js"; | ||
/** | ||
* Defines a moment that executes each observer asynchronously in parallel awaiting all promises to resolve or reject before continuing | ||
* | ||
* @returns The final set of arguments | ||
*/ | ||
export declare function asyncBroadcast<T extends ObserverFunction<void>>(): (observers: T[], ...args: [...Parameters<T>]) => Promise<any[]>; | ||
/** | ||
* Defines a moment that executes each observer synchronously, passing the returned arguments as the arguments to the next observer. | ||
* This is very much like the redux pattern taking the arguments as the state which each observer may modify then returning a new state | ||
* | ||
* @returns The final set of arguments | ||
*/ | ||
export declare function reduce<T extends ObserverFunction<[...Parameters<T>]>>(): (observers: T[], ...args: [...Parameters<T>]) => [...Parameters<T>]; | ||
/** | ||
* Defines a moment that executes each observer asynchronously, awaiting the result and passes the returned arguments as the arguments to the next observer. | ||
@@ -11,0 +24,0 @@ * This is very much like the redux pattern taking the arguments as the state which each observer may modify then returning a new state |
@@ -16,2 +16,39 @@ import { isArray } from "./util.js"; | ||
/** | ||
* Defines a moment that executes each observer asynchronously in parallel awaiting all promises to resolve or reject before continuing | ||
* | ||
* @returns The final set of arguments | ||
*/ | ||
export function asyncBroadcast() { | ||
return async function (observers, ...args) { | ||
// get our initial values | ||
const r = args; | ||
const obs = [...observers]; | ||
const promises = []; | ||
// process each handler which updates our "state" in order | ||
for (let i = 0; i < obs.length; i++) { | ||
promises.push(Reflect.apply(obs[i], this, r)); | ||
} | ||
return Promise.all(promises); | ||
}; | ||
} | ||
/** | ||
* Defines a moment that executes each observer synchronously, passing the returned arguments as the arguments to the next observer. | ||
* This is very much like the redux pattern taking the arguments as the state which each observer may modify then returning a new state | ||
* | ||
* @returns The final set of arguments | ||
*/ | ||
export function reduce() { | ||
return function (observers, ...args) { | ||
// get our initial values | ||
let r = args; | ||
const obs = [...observers]; | ||
// process each handler which updates our "state" in order | ||
// returning the new "state" as a tuple [...Parameters<T>] | ||
for (let i = 0; i < obs.length; i++) { | ||
r = Reflect.apply(obs[i], this, r); | ||
} | ||
return r; | ||
}; | ||
} | ||
/** | ||
* Defines a moment that executes each observer asynchronously, awaiting the result and passes the returned arguments as the arguments to the next observer. | ||
@@ -18,0 +55,0 @@ * This is very much like the redux pattern taking the arguments as the state which each observer may modify then returning a new state |
{ | ||
"name": "@pnp/core", | ||
"version": "3.3.2", | ||
"description": "pnp - provides shared functionality across all pnp libraries", | ||
"main": "./index.js", | ||
"typings": "./index", | ||
"dependencies": { | ||
"tslib": "2.3.1" | ||
}, | ||
"funding": { | ||
"type": "individual", | ||
"url": "https://github.com/sponsors/patrick-rodgers/" | ||
}, | ||
"type": "module", | ||
"engines": { | ||
"node": ">=14.15.1" | ||
}, | ||
"author": { | ||
"name": "Microsoft and other contributors" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/pnp/pnpjs/issues" | ||
}, | ||
"homepage": "https://github.com/pnp/pnpjs", | ||
"repository": { | ||
"type": "git", | ||
"url": "git:github.com/pnp/pnpjs" | ||
} | ||
"name": "@pnp/core", | ||
"version": "3.4.0-v3nightly.20220613", | ||
"description": "pnp - provides shared functionality across all pnp libraries", | ||
"main": "./index.js", | ||
"typings": "./index", | ||
"dependencies": { | ||
"tslib": "2.4.0" | ||
}, | ||
"funding": { | ||
"type": "individual", | ||
"url": "https://github.com/sponsors/patrick-rodgers/" | ||
}, | ||
"type": "module", | ||
"engines": { | ||
"node": ">=14.15.1" | ||
}, | ||
"author": { | ||
"name": "Microsoft and other contributors" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/pnp/pnpjs/issues" | ||
}, | ||
"homepage": "https://github.com/pnp/pnpjs", | ||
"repository": { | ||
"type": "git", | ||
"url": "git:github.com/pnp/pnpjs" | ||
} | ||
} |
@@ -131,12 +131,11 @@ import { broadcast, lifecycle } from "./moments.js"; | ||
*/ | ||
async start(init) { | ||
try { | ||
// initialize our timeline | ||
this.emit.init(); | ||
// execute the timeline | ||
// (this await is required to ensure dispose is called AFTER execute completes) | ||
// we do not catch here so that any promise rejects in execute bubble up to the caller | ||
return await this.execute(init); | ||
} | ||
finally { | ||
start(init) { | ||
// initialize our timeline | ||
this.emit.init(); | ||
// execute the timeline and get a ref to the promise | ||
// this gives the implementation of execute the ability to mutate the promise object, which | ||
// enabled us to add the cancel behavior, and opens up another piece of flexibility in the framework | ||
const p = this.execute(init); | ||
// attach our dispose logic | ||
p.finally(() => { | ||
try { | ||
@@ -153,3 +152,4 @@ // provide an opportunity for cleanup of the timeline | ||
} | ||
} | ||
}); | ||
return p; | ||
} | ||
@@ -156,0 +156,0 @@ /** |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
82000
4.51%1305
3.98%1
Infinity%+ Added
- Removed
Updated