@libre/atom
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -43,3 +43,5 @@ let nextAtomUid = 0; | ||
Object.keys(changeHandlersByAtomId[atom["$$id"]]).forEach(k => { | ||
changeHandlersByAtomId[atom["$$id"]][k]({ previous, current }); | ||
if (typeof changeHandlersByAtomId[atom["$$id"]][k] === "function") { | ||
changeHandlersByAtomId[atom["$$id"]][k]({ previous, current }); | ||
} | ||
}); | ||
@@ -46,0 +48,0 @@ } |
@@ -1,2 +0,2 @@ | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(n["@libre/atom"]={})}(this,function(n){"use strict";var i=0,e=Object.create(null),r=Object.create(null),a={};function d(n){return e[n.$$id]}function u(n,t){e[n.$$id]=t}function f(n){return r[n.$$id]}function c(n,t){r[n.$$id]=t}function s(t,e,r){Object.keys(a[t.$$id]).forEach(function(n){a[t.$$id][n]({previous:e,current:r})})}var t="Expected an Atom instances, but got:";function l(n){return JSON.stringify(n,null," ")}function v(n){if(!(n instanceof o))throw TypeError(t+"\n\n"+l(n))}var o=function(){function e(n,t){var e=(void 0===t?{}:t).validator;if((e=e||function(){return!0})(n))return Object.defineProperty(this,"$$id",{value:i++}),u(this,n),c(this,e),a[this.$$id]={},this;var r="Atom initialized with invalid state:\n\n"+l(n)+"\n\naccording to validator function:\n"+e+"\n\n",o=Error(r);throw o.name="AtomInvalidStateError",o}return e.of=function(n,t){return new e(n,t)},e.prototype.toString=function(){return"Atom<"+l(d(this))+">"},e.prototype.inspect=function(){return this.toString()},e}();function h(n){return v(n),d(n)}n.addChangeHandler=function(n,t,e){!function(n,t,e){if("function"==typeof a[n.$$id][t])throw new Error('Change handler already registered for key "'+t+'" on '+n+".\nRemove the existing handler before registering a new one.");a[n.$$id][t]=e}(n,t,e)},n.removeChangeHandler=function(n,t){var e;e=t,delete a[n.$$id][e]},n.Atom=o,n.deref=h,n.getValidator=function(n){return v(n),f(n)},n.set=function(n,t){v(n);var e=f(n);if(!e(t)){var r="Attempted to set the state of\n\n"+n+"\n\nwith:\n\n"+l(t)+"\n\nbut it did not pass validator:\n"+e+"\n\n",o=Error(r);throw o.name="AtomInvalidStateError",o}var i=h(n);u(n,t),s(n,i,t)},n.setValidator=function(n,t){if(v(n),!t(d(n))){var e=Error("Could not set validator on\n\n"+n+"\n\nbecause current state would be invalid according to new validator:\n"+t+"\n\n");throw e.name="AtomInvalidStateError",e}c(n,t)},n.swap=function(n,t){v(n);var e=d(n),r=t(e),o=f(n);if(!o(r)){var i="swap updateFn\n"+t+"\n\nattempted to swap the state of\n\n"+n+"\n\nwith:\n\n"+l(r)+"\n\nbut it did not pass validator:\n"+o+"\n\n",a=Error(i);throw a.name="AtomInvalidStateError",a}u(n,r),s(n,e,r)},Object.defineProperty(n,"__esModule",{value:!0})}); | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(n["@libre/atom"]={})}(this,function(n){"use strict";var i=0,e=Object.create(null),r=Object.create(null),a={};function d(n){return e[n.$$id]}function u(n,t){e[n.$$id]=t}function f(n){return r[n.$$id]}function c(n,t){r[n.$$id]=t}function s(t,e,r){Object.keys(a[t.$$id]).forEach(function(n){"function"==typeof a[t.$$id][n]&&a[t.$$id][n]({previous:e,current:r})})}var t="Expected an Atom instances, but got:";function l(n){return JSON.stringify(n,null," ")}function v(n){if(!(n instanceof o))throw TypeError(t+"\n\n"+l(n))}var o=function(){function e(n,t){var e=(void 0===t?{}:t).validator;if((e=e||function(){return!0})(n))return Object.defineProperty(this,"$$id",{value:i++}),u(this,n),c(this,e),a[this.$$id]={},this;var r="Atom initialized with invalid state:\n\n"+l(n)+"\n\naccording to validator function:\n"+e+"\n\n",o=Error(r);throw o.name="AtomInvalidStateError",o}return e.of=function(n,t){return new e(n,t)},e.prototype.toString=function(){return"Atom<"+l(d(this))+">"},e.prototype.inspect=function(){return this.toString()},e}();function h(n){return v(n),d(n)}n.addChangeHandler=function(n,t,e){!function(n,t,e){if("function"==typeof a[n.$$id][t])throw new Error('Change handler already registered for key "'+t+'" on '+n+".\nRemove the existing handler before registering a new one.");a[n.$$id][t]=e}(n,t,e)},n.removeChangeHandler=function(n,t){var e;e=t,delete a[n.$$id][e]},n.Atom=o,n.deref=h,n.getValidator=function(n){return v(n),f(n)},n.set=function(n,t){v(n);var e=f(n);if(!e(t)){var r="Attempted to set the state of\n\n"+n+"\n\nwith:\n\n"+l(t)+"\n\nbut it did not pass validator:\n"+e+"\n\n",o=Error(r);throw o.name="AtomInvalidStateError",o}var i=h(n);u(n,t),s(n,i,t)},n.setValidator=function(n,t){if(v(n),!t(d(n))){var e=Error("Could not set validator on\n\n"+n+"\n\nbecause current state would be invalid according to new validator:\n"+t+"\n\n");throw e.name="AtomInvalidStateError",e}c(n,t)},n.swap=function(n,t){v(n);var e=d(n),r=t(e),o=f(n);if(!o(r)){var i="swap updateFn\n"+t+"\n\nattempted to swap the state of\n\n"+n+"\n\nwith:\n\n"+l(r)+"\n\nbut it did not pass validator:\n"+o+"\n\n",a=Error(i);throw a.name="AtomInvalidStateError",a}u(n,r),s(n,e,r)},Object.defineProperty(n,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=index.umd.js.map |
@@ -92,3 +92,3 @@ { | ||
"unpkg": "https://unpkg.com/@libre/atom", | ||
"version": "1.3.0" | ||
"version": "1.3.1" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
62911
560