Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

derivable

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

derivable - npm Package Compare versions

Comparing version 0.13.0-beta2 to 0.13.0-beta3

13

dist/derivable.js

@@ -318,9 +318,12 @@ // UMD loader

}
var nextValue = this._derivable.get();
if (this._derivable._epoch !== this._lastEpoch &&
// maybe the reactor was stopped by the parent
if (this._active) {
var nextValue = this._derivable.get();
if (this._derivable._epoch !== this._lastEpoch &&
!this._derivable.__equals(nextValue, this._lastValue)) {
this._force(nextValue);
this._force(nextValue);
}
this._lastEpoch = this._derivable._epoch;
this._lastValue = nextValue;
}
this._lastEpoch = this._derivable._epoch;
this._lastValue = nextValue;
}

@@ -327,0 +330,0 @@ },

@@ -1,7 +0,7 @@

!function(t,n){"use strict";t&&"function"==typeof t.define&&t.define.amd?t.define(["exports"],n):n("undefined"!=typeof exports?exports:t.Derivable={})}(this,function(t){"use strict";function n(t){for(var n=1;arguments.length>n;n++)for(var r=arguments[n],e=V(r),i=e.length;i--;){var o=e[i];t[o]=r[o]}return t}function r(t,n){return t===n?0!==t||1/t===1/n:t!==t&&n!==n}function e(t,n){return r(t,n)||t&&"function"==typeof t.equals&&t.equals(n)}function i(t,n){var r=t.indexOf(n);0>r&&t.push(n)}function o(t,n){var r=t.indexOf(n);r>=0&&t.splice(r,1)}function u(){return F++}function c(t,n){return Array.prototype.slice.call(t,n)}function a(t){return null!==t&&void 0!==t}function s(t){I=!!t}function f(t,n){return t._equals=n,t}function h(t){var n=z.length;z.push([]);try{return t(),z[n]}finally{z.pop()}}function l(t){if(z.length>0){var n=z[z.length-1];return n.push(t,0),n.length-1}return-1}function p(t,n){z.length>0&&(z[z.length-1][t]=n)}function _(){throw H}function v(t){this.parent=t,this.id2txnAtom={},this.globalEpoch=N,this.modifiedAtoms=[]}function d(){return null!==J}function g(t){y();try{t.call(null,_)}catch(n){if(E(),n!==H)throw n;return}m()}function y(){J=new v(J)}function m(){var t=J;J=t.parent;var n=[];t.modifiedAtoms.forEach(function(r){null!==J?r.set(t.id2txnAtom[r._id]._value):(r._set(t.id2txnAtom[r._id]._value),n.push(r._reactors))}),null===J?N=t.globalEpoch:J.globalEpoch=t.globalEpoch,n.forEach(function(t){t.forEach(function(t){t._maybeReact()})})}function E(){var t=J;J=t.parent,null===J?N=t.globalEpoch+1:J.globalEpoch=t.globalEpoch+1}function b(){y();var t=!1;return{tick:function(){if(t)throw new Error("can't tick disposed ticker");m(),y()},stop:function(){if(t)throw new Error("ticker already disposed");t=!0,m()},resetState:function(){if(t)throw new Error("ticker already disposed");E(),y()}}}function k(t,n){this._derivable=n,t&&(this.react=t),this._atoms=[],this._parent=null,this._active=!1,this._yielding=!1,this._reacting=!1,this._type=B,I&&(this.stack=Error().stack)}function w(t,n){if(t._type===L)i(n,t);else for(var r=0,e=t._lastParentsEpochs.length;e>r;r+=2)w(t._lastParentsEpochs[r],n);
}function A(t,n){var r={derive:function(n,r,e,i,o){var u=this;switch(arguments.length){case 0:return u;case 1:switch(typeof n){case"function":return t.derivation(function(){return n(u.get())});case"string":case"number":return t.derivation(function(){return u.get()[t.unpack(n)]});default:if(n instanceof Array)return n.map(function(t){return u.derive(t)});if(n instanceof RegExp)return t.derivation(function(){return u.get().match(n)});if(t.isDerivable(n))return t.derivation(function(){var r=n.get(),e=u.get();switch(typeof r){case"function":return r(e);case"string":case"number":return e[r];default:if(r instanceof RegExp)return e.match(r);throw Error("type error")}return u.get()[t.unpack(n)]});throw Error("type error")}break;case 2:return t.derivation(function(){return n(u.get(),t.unpack(r))});case 3:return t.derivation(function(){return n(u.get(),t.unpack(r),t.unpack(e))});case 4:return t.derivation(function(){return n(u.get(),t.unpack(r),t.unpack(e),t.unpack(i))});case 5:return t.derivation(function(){return n(u.get(),t.unpack(r),t.unpack(e),t.unpack(i),t.unpack(o))});default:var a=[u].concat(c(arguments,1));return t.derivation(function(){return n.apply(null,a.map(t.unpack))})}},reactor:function(t){if("function"==typeof t)return new Q(t,this);if(t instanceof Q){if("function"!=typeof t.react)throw new Error("reactor missing .react method");return t._derivable=this,t}if(t&&t.react)return Object.assign(new Q(null,this),t);throw new Error("Unrecognized type for reactor "+t)},react:function(n,r){function e(n,r){if(!t.isDerivable(n))if("function"==typeof n)n=t.derivation(n);else{if("boolean"!=typeof n)throw Error("react "+r+" condition must be derivable");n=t.atom(n)}return n.derive(function(t){return!!t})}if("function"!=typeof n)throw Error("the first argument to .react must be a function");r=Object.assign({once:!1,from:!0,until:!1,when:!0,skipFirst:!1},r);var i=this.reactor({react:function(t){r.skipFirst?r.skipFirst=!1:(n(t),r.once&&(this.stop(),o.stop()))},onStart:r.onStart,onStop:r.onStop}),o=t.struct({until:e(r.until,"until"),
when:e(r.when,"when")}).reactor(function(t){t.until?(i.stop(),this.stop()):t.when?i.isActive()||i.start().force():i.isActive()&&i.stop()});e(r.from,"from").reactor(function(t){t&&(o.start().force(),this.stop())}).start().force()},is:function(r){return t.lift(this._equals||n.equals)(this,r)},and:function(n){return this.derive(function(r){return r&&t.unpack(n)})},or:function(n){return this.derive(function(r){return r||t.unpack(n)})},then:function(n,r){return this.derive(function(e){return t.unpack(e?n:r)})},mThen:function(n,r){return this.derive(function(e){return t.unpack(a(e)?n:r)})},mOr:function(t){return this.mThen(this,t)},mDerive:function(t){if(1===arguments.length&&t instanceof Array){var n=this;return t.map(function(t){return n.mDerive(t)})}return this.mThen(this.derive.apply(this,arguments))},mAnd:function(t){return this.mThen(t,this)},not:function(){return this.derive(function(t){return!t})},withEquality:function(t){if(t){if("function"!=typeof t)throw new Error("equals must be function")}else t=null;return f(this._clone(),t)},__equals:function(t,r){return(this._equals||n.equals)(t,r)}};return r["switch"]=function(){var r=arguments;return this.derive(function(e){var i;for(i=0;r.length-1>i;i+=2)if(n.equals(e,t.unpack(r[i])))return t.unpack(r[i+1]);return i===r.length-1?t.unpack(r[i]):void 0})},r}function q(t,n){return{_clone:function(){return f(t.derivation(this._deriver),this._equals)},_forceEval:function(){var t=this,n=null,r=h(function(){if(I)try{n=t._deriver()}catch(r){throw console.error(t.stack),r}else n=t._deriver()});this.__equals(n,this._value)||this._epoch++,this._lastParentsEpochs=r,this._value=n},_update:function(){var t=null===J?N:J.globalEpoch;if(this._lastGlobalEpoch!==t){if(this._value===G)this._forceEval();else for(var n=0,r=this._lastParentsEpochs.length;r>n;n+=2){var e,i=this._lastParentsEpochs[n],o=this._lastParentsEpochs[n+1];if(i._type===L?e=i._getEpoch():(i._update(),e=i._epoch),e!==o)return void this._forceEval()}this._lastGlobalEpoch=t}},get:function(){var t=l(this);return this._update(),
p(t,this._epoch),this._value}}}function O(t,n){return t._deriver=n,t._lastParentsEpochs=[],t._lastGlobalEpoch=N-1,t._epoch=0,t._type=M,t._value=G,t._equals=null,I&&(t.stack=Error().stack),t}function x(t,n){return{swap:function(t){var n=c(arguments,0);return n[0]=this.get(),this.set(t.apply(null,n))},lens:function(n){var r=this;return t.lens({get:function(){return n.get(r.get())},set:function(t){r.set(n.set(r.get(),t))}})}}}function D(t,n){return{_clone:function(){return f(t.lens(this._lensDescriptor),this._equals)},set:function(n){var r=this;return t.atomically(function(){r._lensDescriptor.set(n)}),this}}}function j(t,n){return t._lensDescriptor=n,t._type=U,t}function R(t,n){return{_clone:function(){return f(t.atom(this._value),this._equals)},set:function(t){if(null!==J){var n=void 0;void 0!==(n=J.id2txnAtom[this._id])&&t!==n._value?(J.globalEpoch++,n._epoch++,n._value=t):this.__equals(t,this._value)||(J.globalEpoch++,n=this._clone(),n._value=t,n._id=this._id,n._epoch=this._epoch+1,J.id2txnAtom[this._id]=n,i(J.modifiedAtoms,this))}else this.__equals(t,this._value)||(this._set(t),this._reactors.forEach(function(t){return t._maybeReact()}))},_set:function(t){N++,this._epoch++,this._value=t},get:function(){for(var t,n=J;null!==n;){if(t=n.id2txnAtom[this._id],void 0!==t)return p(l(this),t._epoch),t._value;n=n.parent}return p(l(this),this._epoch),this._value},_getEpoch:function(){for(var t,n=J;null!==n;){if(t=n.id2txnAtom[this._id],void 0!==t)return t._epoch;n=n.parent}return this._epoch}}}function S(t,n){return t._id=u(),t._reactors=[],t._epoch=0,t._value=n,t._type=L,t._equals=null,t}function P(t){return function(){var n,r=c(arguments,0),e=this;return g(function(){n=t.apply(e,r)}),n}}function T(){W?W.refCount++:(W=b(),W.refCount=1);var t=!1;return{tick:function(){if(t)throw new Error("tyring to use ticker after release");W.tick()},release:function(){if(t)throw new Error("ticker already released");0===--W.refCount&&(W.stop(),W=null),t=!0}}}function C(t){function r(t){if(f.isDerivable(t))return t.get();if(t instanceof Array)return t.map(r);
if(t.constructor===Object){for(var n={},e=V(t),i=e.length;i--;){var o=e[i];n[o]=r(t[o])}return n}return t}function i(t){return function(){var n=arguments;return f.derivation(function(){for(var r,e=0;n.length>e&&(r=f.unpack(n[e]),!t(r));e++);return r})}}function o(t){return t}function u(t){return function(n){return!t(n)}}t=n({},X,t||{});var f={transact:g,defaultEquals:e,setDebugMode:s,transaction:P,ticker:T,Reactor:Q,isAtom:function(t){return t&&(t._type===L||t._type===U)},isDerivable:function(t){return t&&(t._type===L||t._type===U||t._type===M)},isDerivation:function(t){return t&&(t._type===M||t._type===U)},isLensed:function(t){return t&&t._type===U},isReactor:function(t){return t&&t._type===B}},h=A(f,t),l=x(f,t),p=n({},l,h,R(f,t)),_=n({},h,q(f,t)),v=n({},l,_,D(f,t));return f.atom=function(t){return S(Object.create(p),t)},f.atomic=function(t){return function(){var n,r=this,e=arguments;return f.atomically(function(){n=t.apply(r,e)}),n}},f.atomically=function(t){d()?t():f.transact(t)},f.derivation=function(t){return O(Object.create(_),t)},f.derive=function(t){var n=c(arguments,1);return f.derivation(function(){for(var r="",e=0;t.length>e;e++)r+=t[e],n.length>e&&(r+=f.unpack(n[e]));return r})},f.lens=function(t){return j(O(Object.create(v),t.get),t)},f.unpack=function(t){return f.isDerivable(t)?t.get():t},f.lift=function(t){return function(){var n=arguments,r=this;return f.derivation(function(){return t.apply(r,Array.prototype.map.call(n,f.unpack))})}},f.struct=function(t){if(t.constructor===Object||t instanceof Array)return f.derivation(function(){return r(t)});throw new Error("`struct` expects plain Object or Array")},f.or=i(o),f.mOr=i(a),f.and=i(u(o)),f.mAnd=i(u(a)),f}var V=Object.keys,F=0,G=Object.freeze({equals:function(){return!1}}),I=!1,N=0,z=[],L="ATOM",M="DERIVATION",U="LENS",B="REACTION",H={},J=null,K=[],Q=k;Object.assign(Q.prototype,{start:function(){this._lastValue=this._derivable.get(),this._lastEpoch=this._derivable._epoch,this._atoms=[],w(this._derivable,this._atoms);var t=this;this._atoms.forEach(function(n){
i(n._reactors,t)});var n=K.length;return n>0&&(this._parent=K[n-1]),this._active=!0,this.onStart&&this.onStart(),this},_force:function(t){try{K.push(this),this._reacting=!0,this.react(t);var n=this._atoms,r=[];this._atoms=r,w(this._derivable,r);var e=this;r.forEach(function(t){var r=n.indexOf(t);-1===r?i(t._reactors,e):n[r]=null}),n.forEach(function(t){null!==t&&o(t._reactors,e)})}catch(u){throw I&&console.error(this.stack),u}finally{this._reacting=!1,K.pop()}},force:function(){return this._force(this._derivable.get()),this},_maybeReact:function(){if(this._reacting)throw Error("cyclical update detected!!");if(this._active){if(this._yielding)throw Error("reactor dependency cycle detected");null!==this._parent&&(this._yielding=!0,this._parent._maybeReact(),this._yielding=!1);var t=this._derivable.get();this._derivable._epoch===this._lastEpoch||this._derivable.__equals(t,this._lastValue)||this._force(t),this._lastEpoch=this._derivable._epoch,this._lastValue=t}},stop:function(){var t=this;return this._atoms.forEach(function(n){return o(n._reactors,t)}),this._atoms=[],this._parent=null,this._active=!1,this.onStop&&this.onStop(),this},orphan:function(){return this._parent=null,this},adopt:function(t){return t._parent=this,this},isActive:function(){return this._active}});var W=null,X={equals:e};n(t,C()),t.withEquality=function(t){return C({equals:t})},t["default"]=t});
!function(t,n){"use strict";t&&"function"==typeof t.define&&t.define.amd?t.define(["exports"],n):n("undefined"!=typeof exports?exports:t.Derivable={})}(this,function(t){"use strict";function n(t){for(var n=1;arguments.length>n;n++)for(var e=arguments[n],r=V(e),i=r.length;i--;){var o=r[i];t[o]=e[o]}return t}function e(t,n){return t===n?0!==t||1/t===1/n:t!==t&&n!==n}function r(t,n){return e(t,n)||t&&"function"==typeof t.equals&&t.equals(n)}function i(t,n){var e=t.indexOf(n);0>e&&t.push(n)}function o(t,n){var e=t.indexOf(n);e>=0&&t.splice(e,1)}function u(){return F++}function c(t,n){return Array.prototype.slice.call(t,n)}function a(t){return null!==t&&void 0!==t}function s(t){I=!!t}function f(t,n){return t._equals=n,t}function h(t){var n=z.length;z.push([]);try{return t(),z[n]}finally{z.pop()}}function l(t){if(z.length>0){var n=z[z.length-1];return n.push(t,0),n.length-1}return-1}function p(t,n){z.length>0&&(z[z.length-1][t]=n)}function _(){throw H}function v(t){this.parent=t,this.id2txnAtom={},this.globalEpoch=N,this.modifiedAtoms=[]}function d(){return null!==J}function g(t){y();try{t.call(null,_)}catch(n){if(E(),n!==H)throw n;return}m()}function y(){J=new v(J)}function m(){var t=J;J=t.parent;var n=[];t.modifiedAtoms.forEach(function(e){null!==J?e.set(t.id2txnAtom[e._id]._value):(e._set(t.id2txnAtom[e._id]._value),n.push(e._reactors))}),null===J?N=t.globalEpoch:J.globalEpoch=t.globalEpoch,n.forEach(function(t){t.forEach(function(t){t._maybeReact()})})}function E(){var t=J;J=t.parent,null===J?N=t.globalEpoch+1:J.globalEpoch=t.globalEpoch+1}function b(){y();var t=!1;return{tick:function(){if(t)throw new Error("can't tick disposed ticker");m(),y()},stop:function(){if(t)throw new Error("ticker already disposed");t=!0,m()},resetState:function(){if(t)throw new Error("ticker already disposed");E(),y()}}}function k(t,n){this._derivable=n,t&&(this.react=t),this._atoms=[],this._parent=null,this._active=!1,this._yielding=!1,this._reacting=!1,this._type=B,I&&(this.stack=Error().stack)}function w(t,n){if(t._type===L)i(n,t);else for(var e=0,r=t._lastParentsEpochs.length;r>e;e+=2)w(t._lastParentsEpochs[e],n);
}function A(t,n){var e={derive:function(n,e,r,i,o){var u=this;switch(arguments.length){case 0:return u;case 1:switch(typeof n){case"function":return t.derivation(function(){return n(u.get())});case"string":case"number":return t.derivation(function(){return u.get()[t.unpack(n)]});default:if(n instanceof Array)return n.map(function(t){return u.derive(t)});if(n instanceof RegExp)return t.derivation(function(){return u.get().match(n)});if(t.isDerivable(n))return t.derivation(function(){var e=n.get(),r=u.get();switch(typeof e){case"function":return e(r);case"string":case"number":return r[e];default:if(e instanceof RegExp)return r.match(e);throw Error("type error")}return u.get()[t.unpack(n)]});throw Error("type error")}break;case 2:return t.derivation(function(){return n(u.get(),t.unpack(e))});case 3:return t.derivation(function(){return n(u.get(),t.unpack(e),t.unpack(r))});case 4:return t.derivation(function(){return n(u.get(),t.unpack(e),t.unpack(r),t.unpack(i))});case 5:return t.derivation(function(){return n(u.get(),t.unpack(e),t.unpack(r),t.unpack(i),t.unpack(o))});default:var a=[u].concat(c(arguments,1));return t.derivation(function(){return n.apply(null,a.map(t.unpack))})}},reactor:function(t){if("function"==typeof t)return new Q(t,this);if(t instanceof Q){if("function"!=typeof t.react)throw new Error("reactor missing .react method");return t._derivable=this,t}if(t&&t.react)return Object.assign(new Q(null,this),t);throw new Error("Unrecognized type for reactor "+t)},react:function(n,e){function r(n,e){if(!t.isDerivable(n))if("function"==typeof n)n=t.derivation(n);else{if("boolean"!=typeof n)throw Error("react "+e+" condition must be derivable");n=t.atom(n)}return n.derive(function(t){return!!t})}if("function"!=typeof n)throw Error("the first argument to .react must be a function");e=Object.assign({once:!1,from:!0,until:!1,when:!0,skipFirst:!1},e);var i=this.reactor({react:function(t){e.skipFirst?e.skipFirst=!1:(n(t),e.once&&(this.stop(),o.stop()))},onStart:e.onStart,onStop:e.onStop}),o=t.struct({until:r(e.until,"until"),
when:r(e.when,"when")}).reactor(function(t){t.until?(i.stop(),this.stop()):t.when?i.isActive()||i.start().force():i.isActive()&&i.stop()});r(e.from,"from").reactor(function(t){t&&(o.start().force(),this.stop())}).start().force()},is:function(e){return t.lift(this._equals||n.equals)(this,e)},and:function(n){return this.derive(function(e){return e&&t.unpack(n)})},or:function(n){return this.derive(function(e){return e||t.unpack(n)})},then:function(n,e){return this.derive(function(r){return t.unpack(r?n:e)})},mThen:function(n,e){return this.derive(function(r){return t.unpack(a(r)?n:e)})},mOr:function(t){return this.mThen(this,t)},mDerive:function(t){if(1===arguments.length&&t instanceof Array){var n=this;return t.map(function(t){return n.mDerive(t)})}return this.mThen(this.derive.apply(this,arguments))},mAnd:function(t){return this.mThen(t,this)},not:function(){return this.derive(function(t){return!t})},withEquality:function(t){if(t){if("function"!=typeof t)throw new Error("equals must be function")}else t=null;return f(this._clone(),t)},__equals:function(t,e){return(this._equals||n.equals)(t,e)}};return e["switch"]=function(){var e=arguments;return this.derive(function(r){var i;for(i=0;e.length-1>i;i+=2)if(n.equals(r,t.unpack(e[i])))return t.unpack(e[i+1]);return i===e.length-1?t.unpack(e[i]):void 0})},e}function q(t,n){return{_clone:function(){return f(t.derivation(this._deriver),this._equals)},_forceEval:function(){var t=this,n=null,e=h(function(){if(I)try{n=t._deriver()}catch(e){throw console.error(t.stack),e}else n=t._deriver()});this.__equals(n,this._value)||this._epoch++,this._lastParentsEpochs=e,this._value=n},_update:function(){var t=null===J?N:J.globalEpoch;if(this._lastGlobalEpoch!==t){if(this._value===G)this._forceEval();else for(var n=0,e=this._lastParentsEpochs.length;e>n;n+=2){var r,i=this._lastParentsEpochs[n],o=this._lastParentsEpochs[n+1];if(i._type===L?r=i._getEpoch():(i._update(),r=i._epoch),r!==o)return void this._forceEval()}this._lastGlobalEpoch=t}},get:function(){var t=l(this);return this._update(),
p(t,this._epoch),this._value}}}function O(t,n){return t._deriver=n,t._lastParentsEpochs=[],t._lastGlobalEpoch=N-1,t._epoch=0,t._type=M,t._value=G,t._equals=null,I&&(t.stack=Error().stack),t}function x(t,n){return{swap:function(t){var n=c(arguments,0);return n[0]=this.get(),this.set(t.apply(null,n))},lens:function(n){var e=this;return t.lens({get:function(){return n.get(e.get())},set:function(t){e.set(n.set(e.get(),t))}})}}}function D(t,n){return{_clone:function(){return f(t.lens(this._lensDescriptor),this._equals)},set:function(n){var e=this;return t.atomically(function(){e._lensDescriptor.set(n)}),this}}}function j(t,n){return t._lensDescriptor=n,t._type=U,t}function R(t,n){return{_clone:function(){return f(t.atom(this._value),this._equals)},set:function(t){if(null!==J){var n=void 0;void 0!==(n=J.id2txnAtom[this._id])&&t!==n._value?(J.globalEpoch++,n._epoch++,n._value=t):this.__equals(t,this._value)||(J.globalEpoch++,n=this._clone(),n._value=t,n._id=this._id,n._epoch=this._epoch+1,J.id2txnAtom[this._id]=n,i(J.modifiedAtoms,this))}else this.__equals(t,this._value)||(this._set(t),this._reactors.forEach(function(t){return t._maybeReact()}))},_set:function(t){N++,this._epoch++,this._value=t},get:function(){for(var t,n=J;null!==n;){if(t=n.id2txnAtom[this._id],void 0!==t)return p(l(this),t._epoch),t._value;n=n.parent}return p(l(this),this._epoch),this._value},_getEpoch:function(){for(var t,n=J;null!==n;){if(t=n.id2txnAtom[this._id],void 0!==t)return t._epoch;n=n.parent}return this._epoch}}}function S(t,n){return t._id=u(),t._reactors=[],t._epoch=0,t._value=n,t._type=L,t._equals=null,t}function P(t){return function(){var n,e=c(arguments,0),r=this;return g(function(){n=t.apply(r,e)}),n}}function T(){W?W.refCount++:(W=b(),W.refCount=1);var t=!1;return{tick:function(){if(t)throw new Error("tyring to use ticker after release");W.tick()},release:function(){if(t)throw new Error("ticker already released");0===--W.refCount&&(W.stop(),W=null),t=!0}}}function C(t){function e(t){if(f.isDerivable(t))return t.get();if(t instanceof Array)return t.map(e);
if(t.constructor===Object){for(var n={},r=V(t),i=r.length;i--;){var o=r[i];n[o]=e(t[o])}return n}return t}function i(t){return function(){var n=arguments;return f.derivation(function(){for(var e,r=0;n.length>r&&(e=f.unpack(n[r]),!t(e));r++);return e})}}function o(t){return t}function u(t){return function(n){return!t(n)}}t=n({},X,t||{});var f={transact:g,defaultEquals:r,setDebugMode:s,transaction:P,ticker:T,Reactor:Q,isAtom:function(t){return t&&(t._type===L||t._type===U)},isDerivable:function(t){return t&&(t._type===L||t._type===U||t._type===M)},isDerivation:function(t){return t&&(t._type===M||t._type===U)},isLensed:function(t){return t&&t._type===U},isReactor:function(t){return t&&t._type===B}},h=A(f,t),l=x(f,t),p=n({},l,h,R(f,t)),_=n({},h,q(f,t)),v=n({},l,_,D(f,t));return f.atom=function(t){return S(Object.create(p),t)},f.atomic=function(t){return function(){var n,e=this,r=arguments;return f.atomically(function(){n=t.apply(e,r)}),n}},f.atomically=function(t){d()?t():f.transact(t)},f.derivation=function(t){return O(Object.create(_),t)},f.derive=function(t){var n=c(arguments,1);return f.derivation(function(){for(var e="",r=0;t.length>r;r++)e+=t[r],n.length>r&&(e+=f.unpack(n[r]));return e})},f.lens=function(t){return j(O(Object.create(v),t.get),t)},f.unpack=function(t){return f.isDerivable(t)?t.get():t},f.lift=function(t){return function(){var n=arguments,e=this;return f.derivation(function(){return t.apply(e,Array.prototype.map.call(n,f.unpack))})}},f.struct=function(t){if(t.constructor===Object||t instanceof Array)return f.derivation(function(){return e(t)});throw new Error("`struct` expects plain Object or Array")},f.or=i(o),f.mOr=i(a),f.and=i(u(o)),f.mAnd=i(u(a)),f}var V=Object.keys,F=0,G=Object.freeze({equals:function(){return!1}}),I=!1,N=0,z=[],L="ATOM",M="DERIVATION",U="LENS",B="REACTION",H={},J=null,K=[],Q=k;Object.assign(Q.prototype,{start:function(){this._lastValue=this._derivable.get(),this._lastEpoch=this._derivable._epoch,this._atoms=[],w(this._derivable,this._atoms);var t=this;this._atoms.forEach(function(n){
i(n._reactors,t)});var n=K.length;return n>0&&(this._parent=K[n-1]),this._active=!0,this.onStart&&this.onStart(),this},_force:function(t){try{K.push(this),this._reacting=!0,this.react(t);var n=this._atoms,e=[];this._atoms=e,w(this._derivable,e);var r=this;e.forEach(function(t){var e=n.indexOf(t);-1===e?i(t._reactors,r):n[e]=null}),n.forEach(function(t){null!==t&&o(t._reactors,r)})}catch(u){throw I&&console.error(this.stack),u}finally{this._reacting=!1,K.pop()}},force:function(){return this._force(this._derivable.get()),this},_maybeReact:function(){if(this._reacting)throw Error("cyclical update detected!!");if(this._active){if(this._yielding)throw Error("reactor dependency cycle detected");if(null!==this._parent&&(this._yielding=!0,this._parent._maybeReact(),this._yielding=!1),this._active){var t=this._derivable.get();this._derivable._epoch===this._lastEpoch||this._derivable.__equals(t,this._lastValue)||this._force(t),this._lastEpoch=this._derivable._epoch,this._lastValue=t}}},stop:function(){var t=this;return this._atoms.forEach(function(n){return o(n._reactors,t)}),this._atoms=[],this._parent=null,this._active=!1,this.onStop&&this.onStop(),this},orphan:function(){return this._parent=null,this},adopt:function(t){return t._parent=this,this},isActive:function(){return this._active}});var W=null,X={equals:r};n(t,C()),t.withEquality=function(t){return C({equals:t})},t["default"]=t});
//# sourceMappingURL=derivable.min.js.map
{
"name": "derivable",
"version": "0.13.0-beta2",
"version": "0.13.0-beta3",
"description": "Functional Reactive State for JavaScript & TypeScript",

@@ -5,0 +5,0 @@ "author": "David Sheldrick",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc