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-beta6 to 0.13.0-beta7

34

dist/derivable.js

@@ -147,7 +147,3 @@ 'use strict';

}
reactorss.forEach(function (reactors) {
reactors.forEach(function (r) {
r._maybeReact();
});
});
reactorss.forEach(processReactors);
}

@@ -196,2 +192,17 @@

function processReactors(reactors, throwing) {
for (var i = 0; i < reactors.length;) {
var r = reactors[i];
if (r._reacting && throwing === true) {
throw new Error('cyclical update detected!');
} else {
r._maybeReact();
}
// maybe this reactor or another one to the left was sliced away
if (r === reactors[i]) {
i++;
}
}
}
var parentsStack = [];

@@ -282,10 +293,3 @@

this._set(value);
for (var i = 0; i < this._reactors.length;) {
var r = this._reactors[i];
r._maybeReact();
// maybe this reactor or another one to the left was sliced away
if (r === this._reactors[i]) {
i++;
}
}
processReactors(this._reactors, true);
}

@@ -415,5 +419,3 @@ }

_maybeReact: function () {
if (this._reacting) {
throw Error('cyclical update detected!!');
} else if (this._active) {
if (!this._reacting && this._active) {
if (this._yielding) {

@@ -420,0 +422,0 @@ throw Error('reactor dependency cycle detected');

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

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