metal-promise
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -52,3 +52,5 @@ 'use strict'; | ||
/** | ||
* Invokes any listeners that have been attached via the progress` method. | ||
* Overwrites `CancellablePromise.prototype.addChildPromise_` so that it | ||
* implements another `ProgressPromise` as a child. | ||
* @inheritdoc | ||
*/ | ||
@@ -58,8 +60,67 @@ | ||
_createClass(ProgressPromise, [{ | ||
key: 'addChildPromise_', | ||
value: function addChildPromise_(onFulfilled, onRejected, opt_context) { | ||
var callbackEntry = { | ||
child: null, | ||
onFulfilled: null, | ||
onRejected: null | ||
}; | ||
callbackEntry.child = new ProgressPromise(function (resolve, reject) { | ||
callbackEntry.onFulfilled = onFulfilled ? function (value) { | ||
try { | ||
var result = onFulfilled.call(opt_context, value); | ||
resolve(result); | ||
} catch (err) { | ||
reject(err); | ||
} | ||
} : resolve; | ||
callbackEntry.onRejected = onRejected ? function (reason) { | ||
try { | ||
var result = onRejected.call(opt_context, reason); | ||
if (!isDef(result) && reason.IS_CANCELLATION_ERROR) { | ||
reject(reason); | ||
} else { | ||
resolve(result); | ||
} | ||
} catch (err) { | ||
reject(err); | ||
} | ||
} : reject; | ||
}); | ||
callbackEntry.child.parent_ = this; | ||
this.addCallbackEntry_(callbackEntry); | ||
return callbackEntry.child; | ||
} | ||
/** | ||
* Invokes any listeners that have been attached to child promises. | ||
* @param {!number} progress A percentage between 0 and 1 | ||
*/ | ||
}, { | ||
key: 'callChildProgressListeners_', | ||
value: function callChildProgressListeners_(progress) { | ||
var _this2 = this; | ||
if (this.callbackEntries_ && this.callbackEntries_.length) { | ||
this.callbackEntries_.forEach(function (callback) { | ||
_this2.callProgressListeners_(progress, callback.child.listeners_); | ||
}); | ||
} | ||
} | ||
/** | ||
* Invokes any listeners that have been attached via the `progress` method. | ||
* @param {!number} progress A percentage between 0 and 1 | ||
* @param {!Array} listeners Array of listeners | ||
*/ | ||
}, { | ||
key: 'callProgressListeners_', | ||
value: function callProgressListeners_() { | ||
var progress = this.progress_; | ||
if (this.listeners_.length) { | ||
this.listeners_.forEach(function (listener) { | ||
value: function callProgressListeners_(progress, listeners) { | ||
if (listeners.length) { | ||
listeners.forEach(function (listener) { | ||
listener(progress); | ||
@@ -112,3 +173,5 @@ }); | ||
this.progress_ = progress; | ||
this.callProgressListeners_(); | ||
this.callProgressListeners_(progress, this.listeners_); | ||
this.callChildProgressListeners_(progress); | ||
} | ||
@@ -115,0 +178,0 @@ }]); |
{ | ||
"name": "metal-promise", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Promises polyfill from Google's Closure Library in ES6", | ||
@@ -5,0 +5,0 @@ "license": "BSD", |
@@ -30,9 +30,62 @@ 'use strict'; | ||
/** | ||
* Invokes any listeners that have been attached via the progress` method. | ||
* Overwrites `CancellablePromise.prototype.addChildPromise_` so that it | ||
* implements another `ProgressPromise` as a child. | ||
* @inheritdoc | ||
*/ | ||
callProgressListeners_() { | ||
const progress = this.progress_; | ||
addChildPromise_(onFulfilled, onRejected, opt_context) { | ||
var callbackEntry = { | ||
child: null, | ||
onFulfilled: null, | ||
onRejected: null | ||
}; | ||
if (this.listeners_.length) { | ||
this.listeners_.forEach(listener => { | ||
callbackEntry.child = new ProgressPromise(function(resolve, reject) { | ||
callbackEntry.onFulfilled = onFulfilled ? function(value) { | ||
try { | ||
var result = onFulfilled.call(opt_context, value); | ||
resolve(result); | ||
} catch (err) { | ||
reject(err); | ||
} | ||
} : resolve; | ||
callbackEntry.onRejected = onRejected ? function(reason) { | ||
try { | ||
var result = onRejected.call(opt_context, reason); | ||
if (!isDef(result) && reason.IS_CANCELLATION_ERROR) { | ||
reject(reason); | ||
} else { | ||
resolve(result); | ||
} | ||
} catch (err) { | ||
reject(err); | ||
} | ||
} : reject; | ||
}); | ||
callbackEntry.child.parent_ = this; | ||
this.addCallbackEntry_(callbackEntry); | ||
return callbackEntry.child; | ||
} | ||
/** | ||
* Invokes any listeners that have been attached to child promises. | ||
* @param {!number} progress A percentage between 0 and 1 | ||
*/ | ||
callChildProgressListeners_(progress) { | ||
if (this.callbackEntries_ && this.callbackEntries_.length) { | ||
this.callbackEntries_.forEach(callback => { | ||
this.callProgressListeners_(progress, callback.child.listeners_); | ||
}); | ||
} | ||
} | ||
/** | ||
* Invokes any listeners that have been attached via the `progress` method. | ||
* @param {!number} progress A percentage between 0 and 1 | ||
* @param {!Array} listeners Array of listeners | ||
*/ | ||
callProgressListeners_(progress, listeners) { | ||
if (listeners.length) { | ||
listeners.forEach(listener => { | ||
listener(progress); | ||
@@ -76,3 +129,5 @@ }); | ||
this.progress_ = progress; | ||
this.callProgressListeners_(); | ||
this.callProgressListeners_(progress, this.listeners_); | ||
this.callChildProgressListeners_(progress); | ||
} | ||
@@ -79,0 +134,0 @@ } |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
75327
1971
0