arbitrary-promise
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -69,2 +69,4 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
function ArbitraryPromise(passReceivePairs) { | ||
var shouldSaveCalls = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; | ||
_classCallCheck(this, ArbitraryPromise); | ||
@@ -76,3 +78,3 @@ | ||
passReceivePairs.forEach(this._processPassReceivePair.bind(this)); | ||
passReceivePairs.forEach(this._processPassReceivePair.bind(this, shouldSaveCalls)); | ||
} | ||
@@ -89,2 +91,5 @@ | ||
} | ||
// initialize state on prototype | ||
}, { | ||
@@ -95,2 +100,5 @@ key: '_createState', | ||
} | ||
// free up the state | ||
}, { | ||
@@ -105,5 +113,8 @@ key: '_resetState', | ||
} | ||
// attach the handlers / memory | ||
}, { | ||
key: '_processPassReceivePair', | ||
value: function _processPassReceivePair(pair) { | ||
value: function _processPassReceivePair(shouldSaveCalls, pair) { | ||
var _this2 = this; | ||
@@ -126,3 +137,3 @@ | ||
// Get all data previously called from pass funk | ||
_this2._state[stateKey].forEach(function (args) { | ||
if (shouldSaveCalls) _this2._state[stateKey].forEach(function (args) { | ||
return handler.apply(undefined, _toConsumableArray(args)); | ||
@@ -144,3 +155,3 @@ }); | ||
// Call receive function with data | ||
_this2[handlerKey] && _this2[handlerKey].apply(_this2, args); | ||
if (shouldSaveCalls) _this2[handlerKey] && _this2[handlerKey].apply(_this2, args); | ||
@@ -151,2 +162,5 @@ // return this for chaining | ||
} | ||
// Make sure user has passed in valid pairs | ||
}, { | ||
@@ -153,0 +167,0 @@ key: '_validatePassReceivePairs', |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.arbitraryPromise=e():t.arbitraryPromise=e()}(this,function(){return function(t){function e(n){if(r[n])return r[n].exports;var a=r[n]={exports:{},id:n,loaded:!1};return t[n].call(a.exports,a,a.exports,e),a.loaded=!0,a.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e){"use strict";function r(t){if(Array.isArray(t)){for(var e=0,r=Array(t.length);e<t.length;e++)r[e]=t[e];return r}return Array.from(t)}function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var a=function(){function t(t,e){var r=[],n=!0,a=!1,i=void 0;try{for(var o,u=t[Symbol.iterator]();!(n=(o=u.next()).done)&&(r.push(o.value),!e||r.length!==e);n=!0);}catch(t){a=!0,i=t}finally{try{!n&&u.return&&u.return()}finally{if(a)throw i}}return r}return function(e,r){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),i=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),o=function(){function t(e){if(n(this,t),!this._validatePassReceivePairs(e))throw new Error("must pass in tuples of function names like [['handleData', 'onData'], ...]");this._createState(),e.forEach(this._processPassReceivePair.bind(this))}return i(t,[{key:"clear",value:function(){this._resetState()}},{key:"_createState",value:function(){this._state={}}},{key:"_resetState",value:function(){var t=this;Object.keys(this._state).forEach(function(e){t._state[e]=[]})}},{key:"_processPassReceivePair",value:function(t){var e=this,n=a(t,2),i=n[0],o=n[1],u="__state_"+i,s="__handler_"+o;this._state[u]=[],this[o]=function(t){return e[s]=t,e._state[u].forEach(function(e){return t.apply(void 0,r(e))}),e},this[i]=function(){for(var t=arguments.length,r=Array(t),n=0;n<t;n++)r[n]=arguments[n];return e._state[u].push(r),e[s]&&e[s].apply(e,r),e}}},{key:"_validatePassReceivePairs",value:function(t){var e=Array.isArray(t);if(!e)return!1;var r=t.length>=1;if(!r)return!1;var n=t.every(function(t){return 2===t.length});if(!n)return!1;var a=t.every(function(t){return"string"==typeof t[0]&&"string"==typeof t[1]});return!!a}}]),t}();t.exports=o}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.arbitraryPromise=e():t.arbitraryPromise=e()}(this,function(){return function(t){function e(n){if(r[n])return r[n].exports;var a=r[n]={exports:{},id:n,loaded:!1};return t[n].call(a.exports,a,a.exports,e),a.loaded=!0,a.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e){"use strict";function r(t){if(Array.isArray(t)){for(var e=0,r=Array(t.length);e<t.length;e++)r[e]=t[e];return r}return Array.from(t)}function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var a=function(){function t(t,e){var r=[],n=!0,a=!1,i=void 0;try{for(var o,u=t[Symbol.iterator]();!(n=(o=u.next()).done)&&(r.push(o.value),!e||r.length!==e);n=!0);}catch(t){a=!0,i=t}finally{try{!n&&u.return&&u.return()}finally{if(a)throw i}}return r}return function(e,r){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),i=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),o=function(){function t(e){var r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(n(this,t),!this._validatePassReceivePairs(e))throw new Error("must pass in tuples of function names like [['handleData', 'onData'], ...]");this._createState(),e.forEach(this._processPassReceivePair.bind(this,r))}return i(t,[{key:"clear",value:function(){this._resetState()}},{key:"_createState",value:function(){this._state={}}},{key:"_resetState",value:function(){var t=this;Object.keys(this._state).forEach(function(e){t._state[e]=[]})}},{key:"_processPassReceivePair",value:function(t,e){var n=this,i=a(e,2),o=i[0],u=i[1],s="__state_"+o,f="__handler_"+u;this._state[s]=[],this[u]=function(e){return n[f]=e,t&&n._state[s].forEach(function(t){return e.apply(void 0,r(t))}),n},this[o]=function(){for(var e=arguments.length,r=Array(e),a=0;a<e;a++)r[a]=arguments[a];return n._state[s].push(r),t&&n[f]&&n[f].apply(n,r),n}}},{key:"_validatePassReceivePairs",value:function(t){var e=Array.isArray(t);if(!e)return!1;var r=t.length>=1;if(!r)return!1;var n=t.every(function(t){return 2===t.length});if(!n)return!1;var a=t.every(function(t){return"string"==typeof t[0]&&"string"==typeof t[1]});return!!a}}]),t}();t.exports=o}])}); | ||
//# sourceMappingURL=arbitrary-promise.min.js.map |
@@ -13,2 +13,4 @@ 'use strict'; | ||
function ArbitraryPromise(passReceivePairs) { | ||
var shouldSaveCalls = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; | ||
_classCallCheck(this, ArbitraryPromise); | ||
@@ -20,3 +22,3 @@ | ||
passReceivePairs.forEach(this._processPassReceivePair.bind(this)); | ||
passReceivePairs.forEach(this._processPassReceivePair.bind(this, shouldSaveCalls)); | ||
} | ||
@@ -33,2 +35,5 @@ | ||
} | ||
// initialize state on prototype | ||
}, { | ||
@@ -39,2 +44,5 @@ key: '_createState', | ||
} | ||
// free up the state | ||
}, { | ||
@@ -49,5 +57,8 @@ key: '_resetState', | ||
} | ||
// attach the handlers / memory | ||
}, { | ||
key: '_processPassReceivePair', | ||
value: function _processPassReceivePair(pair) { | ||
value: function _processPassReceivePair(shouldSaveCalls, pair) { | ||
var _this2 = this; | ||
@@ -70,3 +81,3 @@ | ||
// Get all data previously called from pass funk | ||
_this2._state[stateKey].forEach(function (args) { | ||
if (shouldSaveCalls) _this2._state[stateKey].forEach(function (args) { | ||
return handler.apply(undefined, _toConsumableArray(args)); | ||
@@ -88,3 +99,3 @@ }); | ||
// Call receive function with data | ||
_this2[handlerKey] && _this2[handlerKey].apply(_this2, args); | ||
if (shouldSaveCalls) _this2[handlerKey] && _this2[handlerKey].apply(_this2, args); | ||
@@ -95,2 +106,5 @@ // return this for chaining | ||
} | ||
// Make sure user has passed in valid pairs | ||
}, { | ||
@@ -97,0 +111,0 @@ key: '_validatePassReceivePairs', |
{ | ||
"name": "arbitrary-promise", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "ArbitraryPromise is a simple Promise library that allows you to make your own arbitrarily named resolve/then functions.", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -50,2 +50,15 @@ # arbitrary-promise | ||
Unless, that is, you don't want it to: | ||
```js | ||
import ArbitraryPromise from 'arbitrary-promise' | ||
const promise = new ArbitraryPromise([['handleData', 'onData']], false) | ||
promise.handleData('Whoa! Algebraic!') | ||
promise.onData(console.log) | ||
``` | ||
-> Zilch. | ||
Check out [the tests](./test/module.spec.js) for all the info, of which there is not much more than what you already know :) |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
62302
278
64