Comparing version 1.0.0-beta to 1.0.0-beta10
@@ -661,2 +661,3 @@ 'use strict'; | ||
var __Reactor$1 = Reactor; | ||
var transact$2 = transact$1; | ||
@@ -789,2 +790,3 @@ var setDebugMode$2 = setDebugMode$1; | ||
var derivable = Object.freeze({ | ||
__Reactor: __Reactor$1, | ||
transact: transact$2, | ||
@@ -1021,2 +1023,3 @@ setDebugMode: setDebugMode$2, | ||
var __Reactor = __Reactor$1; | ||
var transact = transact$2; | ||
@@ -1046,2 +1049,3 @@ var setDebugMode = setDebugMode$2; | ||
exports.__Reactor = __Reactor; | ||
exports.transact = transact; | ||
@@ -1048,0 +1052,0 @@ exports.setDebugMode = setDebugMode; |
@@ -1,8 +0,8 @@ | ||
"use strict";function t(t){for(var e=1;e<arguments.length;e++)for(var n=arguments[e],r=Y(n||{}),i=r.length;i--;){var s=r[i];t[s]=n[s]}return t}function e(t,e){return t===e?0!==t||1/t===1/e:t!==t&&e!==e}function n(t,n){return e(t,n)||t&&"function"==typeof t.equals&&t.equals(n)}function r(t,e){var n=t.indexOf(e);n<0&&t.push(e)}function i(t,e){var n=t.indexOf(e);n>=0&&t.splice(n,1)}function s(){return Z++}function o(t,e){return Array.prototype.slice.call(t,e)}function u(t){return null!==t&&void 0!==t}function a(t){tt=!!t}function c(t,e){return t._equals=e,t}function f(t){return t&&(t._type===nt||t._type===et||t._type===rt)}function h(t){return t&&(t._type===et||t._type===rt)}function l(t){return t&&(t._type===nt||t._type===rt)}function p(t){return t&&t._type===rt}function _(t,e){ct.push({parents:e,offset:0,child:t}),ft=t}function v(){return ct[ct.length-1]}function d(){ct.pop(),ft=0===ct.length?null:ct[ct.length-1].child}function g(t){if(null!==ft){var e=ct[ct.length-1];if(e.parents[e.offset]===t)e.offset++;else{var n=e.parents.indexOf(t);if(n===-1)void 0!==ft&&r(t._activeChildren,ft),e.offset===e.parents.length?e.parents.push(t):(e.parents.push(e.parents[e.offset]),e.parents[e.offset]=t),e.offset++;else if(n>e.offset){var i=e.parents[n];e.parents[n]=e.parents[e.offset],e.parents[e.offset]=i,e.offset++}}}}function y(t,e){for(var n=0,r=t._activeChildren.length;n<r;n++){var i=t._activeChildren[n];switch(i._type){case nt:case rt:i._state!==st&&(i._state=st,y(i,e));break;case it:e.push(i)}}}function m(t){for(var e=0,n=t.length;e<n;e++){var r=t[e];if(r._reacting)throw new Error("Synchronous cyclical reactions disallowed. Use setImmediate.");r._maybeReact()}}function w(){throw ht}function x(t){this.parent=t,this.id2originalValue={},this.modifiedAtoms=[]}function b(t){null!==lt&&(t._id in lt.id2originalValue||(lt.modifiedAtoms.push(t),lt.id2originalValue[t._id]=t._value))}function E(){return null!==lt}function k(t){D();try{t.call(null,w)}catch(e){if(R(),e!==ht)throw e;return}C()}function A(t){E()?t():k(t)}function q(t){return function(){ | ||
var e,n=o(arguments,0),r=this;return k(function(){e=t.apply(r,n)}),e}}function O(t){return function(){var e,n=o(arguments,0),r=this;return A(function(){e=t.apply(r,n)}),e}}function D(){lt=new x(lt)}function C(){var t=lt;if(lt=t.parent,null===lt){var e=[];t.modifiedAtoms.forEach(function(n){n.__equals(n._value,t.id2originalValue[n._id])?n._state=ut:(n._state=ot,y(n,e))}),m(e),t.modifiedAtoms.forEach(function(t){t._state=ut})}}function R(){var t=lt;lt=t.parent,t.modifiedAtoms.forEach(function(e){e._value=t.id2originalValue[e._id],e._state=ut,y(e,[])})}function T(){0===pt&&D(),pt++;var t=!1;return{tick:function(){if(t)throw new Error("trying to use ticker after release");C(),D()},reset:function(){if(t)throw new Error("trying to use ticker after release");R(),D()},release:function(){if(t)throw new Error("ticker already released");pt--,t=!0,0===pt&&C()}}}function j(t){this._deriver=t,this._parents=null,this._type=nt,this._value=$,this._equals=null,this._activeChildren=[],this._state=at,tt&&(this.stack=Error().stack)}function V(t,e){if(i(t._activeChildren,e),0===t._activeChildren.length&&null!=t._parents){for(var n=t._parents.length,r=0;r<n;r++)V(t._parents[r],t);t._parents=null,t._state=at}}function S(t){return new j(t)}function M(t,e,n){this._parent=t,this.react=e,this._governor=n||null,this._active=!1,this._reacting=!1,this._type=it,tt&&(this.stack=Error().stack)}function I(e,n,r){function i(t,e){if(!f(t)){if("function"==typeof t)return S(t);if("boolean"==typeof t)return S(function(){return t});throw Error("react "+e+" condition must be derivable, got: "+JSON.stringify(t))}return t}if("function"!=typeof n)throw Error("the first argument to .react must be a function");r=t({once:!1,from:!0,until:!1,when:!0,skipFirst:!1},r);var s=r.skipFirst,o=new M(e,function(t){s?s=!1:(n(t),r.once&&(this.stop(),h.stop()))}),u=i(r.until,"until"),a=i(r.when,"when"),c=S(function(){return{until:u.get(),when:a.get()}}),h=new M(c,function(t){t.until?(o.stop(),this.stop()):t.when?o._active||o.start().force():o._active&&o.stop()});o._governor=h; | ||
var l=i(r.from,"from"),p=new M(l,function(t){t&&(h.start().force(),this.stop())});p.start().force()}function L(t){return this._id=s(),this._activeChildren=[],this._value=t,this._state=ut,this._type=et,this._equals=null,this}function N(t){return new L(t)}function P(t){j.call(this,t.get),this._lensDescriptor=t,this._type=rt}function z(t){return new P(t)}function F(t){var e=o(arguments,1);return bt(function(){for(var n="",r=0;r<t.length;r++)n+=t[r],r<e.length&&(n+=J(e[r]));return n})}function J(t){return yt(t)?t.get():t}function U(t){return function(){var e=arguments,n=this;return bt(function(){return t.apply(n,Array.prototype.map.call(e,J))})}}function B(t){if(yt(t))return t.get();if(t instanceof Array)return t.map(B);if(t.constructor===Object){for(var e={},n=Y(t),r=n.length;r--;){var i=n[r];e[i]=B(t[i])}return e}return t}function G(t){if(t.constructor===Object||t instanceof Array)return bt(function(){return B(t)});throw new Error("`struct` expects plain Object or Array")}function H(t,e){var n=e;return function(e){var r=t.call(this,e,n);return n=e,r}}function K(t){var e=[];_(void 0,e);try{t()}finally{d()}return e}function Q(t){return function(){var e=arguments;return bt(function(){for(var n,r=0;r<e.length&&(n=J(e[r]),!t(n));r++);return n})}}function W(t){return t}function X(t){return function(e){return!t(e)}}Object.defineProperty(exports,"__esModule",{value:!0});var Y=Object.keys,Z=0,$=Object.freeze({equals:function(){return!1}}),tt=!1,et="ATOM",nt="DERIVATION",rt="LENS",it="REACTOR",st=0,ot=1,ut=2,at=3,ct=[],ft=null,ht={},lt=null,pt=0;t(j.prototype,{_clone:function(){return c(S(this._deriver),this._equals)},_forceEval:function(){var t,e=this,n=null;try{if(null===this._parents&&(this._parents=[]),_(this,this._parents),tt)try{n=e._deriver()}catch(r){throw console.error(e.stack),r}else n=e._deriver();t=v().offset}finally{d()}this._state=this.__equals(n,this._value)?ut:ot;for(var i=t,s=this._parents.length;i<s;i++){var o=this._parents[i];V(o,this),this._parents[i]=null}this._parents.length=t,this._value=n},_update:function(){ | ||
if(null===this._parents)this._forceEval();else if(this._state===st){for(var t=this._parents.length,e=0;e<t;e++){var n=this._parents[e];if(n._state===st&&n._update(),n._state===ot){this._forceEval();break}}this._state===st&&(this._state=ut)}},get:function(){if(g(this),this._activeChildren.length>0)this._update();else{_(void 0,[]);try{this._value=this._deriver()}finally{d()}}return this._value}}),t(M.prototype,{start:function(){return this._active=!0,r(this._parent._activeChildren,this),this._parent.get(),this},_force:function(t){try{this._reacting=!0,this.react(t)}catch(e){throw tt&&console.error(this.stack),e}finally{this._reacting=!1}},force:function(){return this._force(this._parent.get()),this},_maybeReact:function(){if(!this._reacting&&this._active&&(null!==this._governor&&this._governor._maybeReact(),this._active)){var t=this._parent.get();this._parent._state===ot&&this._force(t)}},stop:function(){return V(this._parent,this),this._active=!1,this}}),t(L.prototype,{_clone:function(){return c(N(this._value),this._equals)},set:function(t){b(this);var e=this._value;if(this._value=t,!E()&&!this.__equals(t,e))try{this._state=ot;var n=[];y(this,n),m(n)}finally{this._state=ut}},get:function(){return g(this),this._value}}),t(P.prototype,j.prototype,{_clone:function(){return c(new P(this._lensDescriptor),this._equals)},set:function(t){var e=this;return A(function(){e._lensDescriptor.set(t)}),this}});var _t=k,vt=a,dt=q,gt=T,yt=f,mt=h,wt=p,xt=l,bt=S,Et=N,kt=O,At=A,qt=z,Ot=Q(W),Dt=Q(u),Ct=Q(X(W)),Rt=Q(X(u)),Tt=Object.freeze({transact:_t,setDebugMode:vt,transaction:dt,ticker:gt,isDerivable:yt,isAtom:mt,isLensed:wt,isDerivation:xt,derivation:bt,atom:Et,atomic:kt,atomically:At,lens:qt,derive:F,unpack:J,lift:U,struct:G,wrapPreviousState:H,captureDereferences:K,or:Ot,mOr:Dt,and:Ct,mAnd:Rt}),jt={derive:function(t,e,n,r,i){var s=this;switch(arguments.length){case 0:throw new Error(".derive takes at least one argument");case 1:switch(typeof t){case"function":return bt(function(){return t(s.get())});case"string":case"number":return bt(function(){ | ||
return s.get()[J(t)]});default:if(t instanceof Array)return t.map(function(t){return s.derive(t)});if(t instanceof RegExp)return bt(function(){return s.get().match(t)});if(f(t))return bt(function(){var e=t.get(),n=s.get();switch(typeof e){case"function":return e(n);case"string":case"number":return n[e];default:if(e instanceof RegExp)return n.match(e);throw Error("type error")}});throw Error("type error")}case 2:return bt(function(){return t(s.get(),J(e))});case 3:return bt(function(){return t(s.get(),J(e),J(n))});case 4:return bt(function(){return t(s.get(),J(e),J(n),J(r))});case 5:return bt(function(){return t(s.get(),J(e),J(n),J(r),J(i))});default:var u=[s].concat(o(arguments,1));return bt(function(){return t.apply(null,u.map(J))})}},react:function(t,e){I(this,t,e)},mReact:function(e,n){var r=this.mThen(!0,!1);if(n&&"when"in n&&n.when!==!0){var i=n.when;if("function"==typeof i||i===!1)i=bt(i);else if(!f(i))throw new Error("when condition must be bool, function, or derivable");r=i.and(r)}return this.react(e,t({},n,{when:r}))},is:function(t){var e=this;return this.derive(function(n){return e.__equals(n,J(t))})},and:function(t){return this.derive(function(e){return e&&J(t)})},or:function(t){return this.derive(function(e){return e||J(t)})},then:function(t,e){return this.derive(function(n){return J(n?t:e)})},mThen:function(t,e){return this.derive(function(n){return J(u(n)?t:e)})},mOr:function(t){return this.mThen(this,t)},mDerive:function(t){if(1===arguments.length&&t instanceof Array){var e=this;return t.map(function(t){return e.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 c(this._clone(),t)},__equals:function(t,e){return(this._equals||n)(t,e)}};jt["switch"]=function(){var t=arguments,e=this;return this.derive(function(n){var r;for(r=0;r<t.length-1;r+=2)if(e.__equals(n,J(t[r])))return J(t[r+1]); | ||
if(r===t.length-1)return J(t[r])})};var Vt={swap:function(t){var e=o(arguments,0);return e[0]=this.get(),this.set(t.apply(null,e))},lens:function(t){var e=this;return new P({get:function(){return t.get(e.get())},set:function(n){e.set(t.set(e.get(),n))}})}};t(j.prototype,jt),t(P.prototype,jt,Vt),t(L.prototype,jt,Vt);var St=_t,Mt=vt,It=dt,Lt=gt,Nt=yt,Pt=mt,zt=wt,Ft=xt,Jt=bt,Ut=Et,Bt=kt,Gt=At,Ht=qt,Kt=F,Qt=J,Wt=U,Xt=G,Yt=H,Zt=K,$t=Ot,te=Dt,ee=Ct,ne=Rt;exports.transact=St,exports.setDebugMode=Mt,exports.transaction=It,exports.ticker=Lt,exports.isDerivable=Nt,exports.isAtom=Pt,exports.isLensed=zt,exports.isDerivation=Ft,exports.derivation=Jt,exports.atom=Ut,exports.atomic=Bt,exports.atomically=Gt,exports.lens=Ht,exports.derive=Kt,exports.unpack=Qt,exports.lift=Wt,exports.struct=Xt,exports.wrapPreviousState=Yt,exports.captureDereferences=Zt,exports.or=$t,exports.mOr=te,exports.and=ee,exports.mAnd=ne,exports["default"]=Tt; | ||
"use strict";function t(t){for(var e=1;e<arguments.length;e++)for(var n=arguments[e],r=Y(n||{}),i=r.length;i--;){var o=r[i];t[o]=n[o]}return t}function e(t,e){return t===e?0!==t||1/t===1/e:t!==t&&e!==e}function n(t,n){return e(t,n)||t&&"function"==typeof t.equals&&t.equals(n)}function r(t,e){var n=t.indexOf(e);n<0&&t.push(e)}function i(t,e){var n=t.indexOf(e);n>=0&&t.splice(n,1)}function o(){return Z++}function s(t,e){return Array.prototype.slice.call(t,e)}function u(t){return null!==t&&void 0!==t}function a(t){tt=!!t}function c(t,e){return t._equals=e,t}function f(t){return t&&(t._type===nt||t._type===et||t._type===rt)}function h(t){return t&&(t._type===et||t._type===rt)}function l(t){return t&&(t._type===nt||t._type===rt)}function p(t){return t&&t._type===rt}function _(t,e){ct.push({parents:e,offset:0,child:t}),ft=t}function v(){return ct[ct.length-1]}function d(){ct.pop(),ft=0===ct.length?null:ct[ct.length-1].child}function g(t){if(null!==ft){var e=ct[ct.length-1];if(e.parents[e.offset]===t)e.offset++;else{var n=e.parents.indexOf(t);if(n===-1)void 0!==ft&&r(t._activeChildren,ft),e.offset===e.parents.length?e.parents.push(t):(e.parents.push(e.parents[e.offset]),e.parents[e.offset]=t),e.offset++;else if(n>e.offset){var i=e.parents[n];e.parents[n]=e.parents[e.offset],e.parents[e.offset]=i,e.offset++}}}}function y(t,e){for(var n=0,r=t._activeChildren.length;n<r;n++){var i=t._activeChildren[n];switch(i._type){case nt:case rt:i._state!==ot&&(i._state=ot,y(i,e));break;case it:e.push(i)}}}function m(t){for(var e=0,n=t.length;e<n;e++){var r=t[e];if(r._reacting)throw new Error("Synchronous cyclical reactions disallowed. Use setImmediate.");r._maybeReact()}}function w(){throw ht}function x(t){this.parent=t,this.id2originalValue={},this.modifiedAtoms=[]}function b(t){null!==lt&&(t._id in lt.id2originalValue||(lt.modifiedAtoms.push(t),lt.id2originalValue[t._id]=t._value))}function E(){return null!==lt}function k(t){D();try{t.call(null,w)}catch(e){if(C(),e!==ht)throw e;return}R()}function A(t){E()?t():k(t)}function q(t){return function(){ | ||
var e,n=s(arguments,0),r=this;return k(function(){e=t.apply(r,n)}),e}}function O(t){return function(){var e,n=s(arguments,0),r=this;return A(function(){e=t.apply(r,n)}),e}}function D(){lt=new x(lt)}function R(){var t=lt;if(lt=t.parent,null===lt){var e=[];t.modifiedAtoms.forEach(function(n){n.__equals(n._value,t.id2originalValue[n._id])?n._state=ut:(n._state=st,y(n,e))}),m(e),t.modifiedAtoms.forEach(function(t){t._state=ut})}}function C(){var t=lt;lt=t.parent,t.modifiedAtoms.forEach(function(e){e._value=t.id2originalValue[e._id],e._state=ut,y(e,[])})}function T(){0===pt&&D(),pt++;var t=!1;return{tick:function(){if(t)throw new Error("trying to use ticker after release");R(),D()},reset:function(){if(t)throw new Error("trying to use ticker after release");C(),D()},release:function(){if(t)throw new Error("ticker already released");pt--,t=!0,0===pt&&R()}}}function j(t){this._deriver=t,this._parents=null,this._type=nt,this._value=$,this._equals=null,this._activeChildren=[],this._state=at,tt&&(this.stack=Error().stack)}function V(t,e){if(i(t._activeChildren,e),0===t._activeChildren.length&&null!=t._parents){for(var n=t._parents.length,r=0;r<n;r++)V(t._parents[r],t);t._parents=null,t._state=at}}function S(t){return new j(t)}function M(t,e,n){this._parent=t,this.react=e,this._governor=n||null,this._active=!1,this._reacting=!1,this._type=it,tt&&(this.stack=Error().stack)}function I(e,n,r){function i(t,e){if(!f(t)){if("function"==typeof t)return S(t);if("boolean"==typeof t)return S(function(){return t});throw Error("react "+e+" condition must be derivable, got: "+JSON.stringify(t))}return t}if("function"!=typeof n)throw Error("the first argument to .react must be a function");r=t({once:!1,from:!0,until:!1,when:!0,skipFirst:!1},r);var o=r.skipFirst,s=new M(e,function(t){o?o=!1:(n(t),r.once&&(this.stop(),h.stop()))}),u=i(r.until,"until"),a=i(r.when,"when"),c=S(function(){return{until:u.get(),when:a.get()}}),h=new M(c,function(t){t.until?(s.stop(),this.stop()):t.when?s._active||s.start().force():s._active&&s.stop()});s._governor=h; | ||
var l=i(r.from,"from"),p=new M(l,function(t){t&&(h.start().force(),this.stop())});p.start().force()}function L(t){return this._id=o(),this._activeChildren=[],this._value=t,this._state=ut,this._type=et,this._equals=null,this}function N(t){return new L(t)}function P(t){j.call(this,t.get),this._lensDescriptor=t,this._type=rt}function z(t){return new P(t)}function F(t){var e=s(arguments,1);return Et(function(){for(var n="",r=0;r<t.length;r++)n+=t[r],r<e.length&&(n+=J(e[r]));return n})}function J(t){return mt(t)?t.get():t}function U(t){return function(){var e=arguments,n=this;return Et(function(){return t.apply(n,Array.prototype.map.call(e,J))})}}function B(t){if(mt(t))return t.get();if(t instanceof Array)return t.map(B);if(t.constructor===Object){for(var e={},n=Y(t),r=n.length;r--;){var i=n[r];e[i]=B(t[i])}return e}return t}function G(t){if(t.constructor===Object||t instanceof Array)return Et(function(){return B(t)});throw new Error("`struct` expects plain Object or Array")}function H(t,e){var n=e;return function(e){var r=t.call(this,e,n);return n=e,r}}function K(t){var e=[];_(void 0,e);try{t()}finally{d()}return e}function Q(t){return function(){var e=arguments;return Et(function(){for(var n,r=0;r<e.length&&(n=J(e[r]),!t(n));r++);return n})}}function W(t){return t}function X(t){return function(e){return!t(e)}}Object.defineProperty(exports,"__esModule",{value:!0});var Y=Object.keys,Z=0,$=Object.freeze({equals:function(){return!1}}),tt=!1,et="ATOM",nt="DERIVATION",rt="LENS",it="REACTOR",ot=0,st=1,ut=2,at=3,ct=[],ft=null,ht={},lt=null,pt=0;t(j.prototype,{_clone:function(){return c(S(this._deriver),this._equals)},_forceEval:function(){var t,e=this,n=null;try{if(null===this._parents&&(this._parents=[]),_(this,this._parents),tt)try{n=e._deriver()}catch(r){throw console.error(e.stack),r}else n=e._deriver();t=v().offset}finally{d()}this._state=this.__equals(n,this._value)?ut:st;for(var i=t,o=this._parents.length;i<o;i++){var s=this._parents[i];V(s,this),this._parents[i]=null}this._parents.length=t,this._value=n},_update:function(){ | ||
if(null===this._parents)this._forceEval();else if(this._state===ot){for(var t=this._parents.length,e=0;e<t;e++){var n=this._parents[e];if(n._state===ot&&n._update(),n._state===st){this._forceEval();break}}this._state===ot&&(this._state=ut)}},get:function(){if(g(this),this._activeChildren.length>0)this._update();else{_(void 0,[]);try{this._value=this._deriver()}finally{d()}}return this._value}}),t(M.prototype,{start:function(){return this._active=!0,r(this._parent._activeChildren,this),this._parent.get(),this},_force:function(t){try{this._reacting=!0,this.react(t)}catch(e){throw tt&&console.error(this.stack),e}finally{this._reacting=!1}},force:function(){return this._force(this._parent.get()),this},_maybeReact:function(){if(!this._reacting&&this._active&&(null!==this._governor&&this._governor._maybeReact(),this._active)){var t=this._parent.get();this._parent._state===st&&this._force(t)}},stop:function(){return V(this._parent,this),this._active=!1,this}}),t(L.prototype,{_clone:function(){return c(N(this._value),this._equals)},set:function(t){b(this);var e=this._value;if(this._value=t,!E()&&!this.__equals(t,e))try{this._state=st;var n=[];y(this,n),m(n)}finally{this._state=ut}},get:function(){return g(this),this._value}}),t(P.prototype,j.prototype,{_clone:function(){return c(new P(this._lensDescriptor),this._equals)},set:function(t){var e=this;return A(function(){e._lensDescriptor.set(t)}),this}});var _t=M,vt=k,dt=a,gt=q,yt=T,mt=f,wt=h,xt=p,bt=l,Et=S,kt=N,At=O,qt=A,Ot=z,Dt=Q(W),Rt=Q(u),Ct=Q(X(W)),Tt=Q(X(u)),jt=Object.freeze({__Reactor:_t,transact:vt,setDebugMode:dt,transaction:gt,ticker:yt,isDerivable:mt,isAtom:wt,isLensed:xt,isDerivation:bt,derivation:Et,atom:kt,atomic:At,atomically:qt,lens:Ot,derive:F,unpack:J,lift:U,struct:G,wrapPreviousState:H,captureDereferences:K,or:Dt,mOr:Rt,and:Ct,mAnd:Tt}),Vt={derive:function(t,e,n,r,i){var o=this;switch(arguments.length){case 0:throw new Error(".derive takes at least one argument");case 1:switch(typeof t){case"function":return Et(function(){return t(o.get())});case"string":case"number": | ||
return Et(function(){return o.get()[J(t)]});default:if(t instanceof Array)return t.map(function(t){return o.derive(t)});if(t instanceof RegExp)return Et(function(){return o.get().match(t)});if(f(t))return Et(function(){var e=t.get(),n=o.get();switch(typeof e){case"function":return e(n);case"string":case"number":return n[e];default:if(e instanceof RegExp)return n.match(e);throw Error("type error")}});throw Error("type error")}case 2:return Et(function(){return t(o.get(),J(e))});case 3:return Et(function(){return t(o.get(),J(e),J(n))});case 4:return Et(function(){return t(o.get(),J(e),J(n),J(r))});case 5:return Et(function(){return t(o.get(),J(e),J(n),J(r),J(i))});default:var u=[o].concat(s(arguments,1));return Et(function(){return t.apply(null,u.map(J))})}},react:function(t,e){I(this,t,e)},mReact:function(e,n){var r=this.mThen(!0,!1);if(n&&"when"in n&&n.when!==!0){var i=n.when;if("function"==typeof i||i===!1)i=Et(i);else if(!f(i))throw new Error("when condition must be bool, function, or derivable");r=i.and(r)}return this.react(e,t({},n,{when:r}))},is:function(t){var e=this;return this.derive(function(n){return e.__equals(n,J(t))})},and:function(t){return this.derive(function(e){return e&&J(t)})},or:function(t){return this.derive(function(e){return e||J(t)})},then:function(t,e){return this.derive(function(n){return J(n?t:e)})},mThen:function(t,e){return this.derive(function(n){return J(u(n)?t:e)})},mOr:function(t){return this.mThen(this,t)},mDerive:function(t){if(1===arguments.length&&t instanceof Array){var e=this;return t.map(function(t){return e.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 c(this._clone(),t)},__equals:function(t,e){return(this._equals||n)(t,e)}};Vt["switch"]=function(){var t=arguments,e=this;return this.derive(function(n){var r;for(r=0;r<t.length-1;r+=2)if(e.__equals(n,J(t[r])))return J(t[r+1]); | ||
if(r===t.length-1)return J(t[r])})};var St={swap:function(t){var e=s(arguments,0);return e[0]=this.get(),this.set(t.apply(null,e))},lens:function(t){var e=this;return new P({get:function(){return t.get(e.get())},set:function(n){e.set(t.set(e.get(),n))}})}};t(j.prototype,Vt),t(P.prototype,Vt,St),t(L.prototype,Vt,St);var Mt=_t,It=vt,Lt=dt,Nt=gt,Pt=yt,zt=mt,Ft=wt,Jt=xt,Ut=bt,Bt=Et,Gt=kt,Ht=At,Kt=qt,Qt=Ot,Wt=F,Xt=J,Yt=U,Zt=G,$t=H,te=K,ee=Dt,ne=Rt,re=Ct,ie=Tt;exports.__Reactor=Mt,exports.transact=It,exports.setDebugMode=Lt,exports.transaction=Nt,exports.ticker=Pt,exports.isDerivable=zt,exports.isAtom=Ft,exports.isLensed=Jt,exports.isDerivation=Ut,exports.derivation=Bt,exports.atom=Gt,exports.atomic=Ht,exports.atomically=Kt,exports.lens=Qt,exports.derive=Wt,exports.unpack=Xt,exports.lift=Yt,exports.struct=Zt,exports.wrapPreviousState=$t,exports.captureDereferences=te,exports.or=ee,exports.mOr=ne,exports.and=re,exports.mAnd=ie,exports["default"]=jt; | ||
//# sourceMappingURL=dist/derivable.min.js.map | ||
//# sourceMappingURL=derivable.min.js.map |
@@ -672,2 +672,3 @@ // UMD loader | ||
var __Reactor$1 = Reactor; | ||
var transact$2 = transact$1; | ||
@@ -800,2 +801,3 @@ var setDebugMode$2 = setDebugMode$1; | ||
var derivable = Object.freeze({ | ||
__Reactor: __Reactor$1, | ||
transact: transact$2, | ||
@@ -1032,2 +1034,3 @@ setDebugMode: setDebugMode$2, | ||
var __Reactor = __Reactor$1; | ||
var transact = transact$2; | ||
@@ -1057,2 +1060,3 @@ var setDebugMode = setDebugMode$2; | ||
exports.__Reactor = __Reactor; | ||
exports.transact = transact; | ||
@@ -1059,0 +1063,0 @@ exports.setDebugMode = setDebugMode; |
!function(t,e){"use strict";t&&"function"==typeof t.define&&t.define.amd?t.define(["exports"],e):e("undefined"!=typeof exports?exports:t.Derivable={})}(this,function(t){"use strict";function e(t){for(var e=1;e<arguments.length;e++)for(var n=arguments[e],r=Z(n||{}),i=r.length;i--;){var u=r[i];t[u]=n[u]}return t}function n(t,e){return t===e?0!==t||1/t===1/e:t!==t&&e!==e}function r(t,e){return n(t,e)||t&&"function"==typeof t.equals&&t.equals(e)}function i(t,e){var n=t.indexOf(e);n<0&&t.push(e)}function u(t,e){var n=t.indexOf(e);n>=0&&t.splice(n,1)}function o(){return $++}function s(t,e){return Array.prototype.slice.call(t,e)}function a(t){return null!==t&&void 0!==t}function c(t){et=!!t}function f(t,e){return t._equals=e,t}function h(t){return t&&(t._type===rt||t._type===nt||t._type===it)}function l(t){return t&&(t._type===nt||t._type===it)}function _(t){return t&&(t._type===rt||t._type===it)}function p(t){return t&&t._type===it}function v(t,e){ft.push({parents:e,offset:0,child:t}),ht=t}function d(){return ft[ft.length-1]}function y(){ft.pop(),ht=0===ft.length?null:ft[ft.length-1].child}function g(t){if(null!==ht){var e=ft[ft.length-1];if(e.parents[e.offset]===t)e.offset++;else{var n=e.parents.indexOf(t);if(n===-1)void 0!==ht&&i(t._activeChildren,ht),e.offset===e.parents.length?e.parents.push(t):(e.parents.push(e.parents[e.offset]),e.parents[e.offset]=t),e.offset++;else if(n>e.offset){var r=e.parents[n];e.parents[n]=e.parents[e.offset],e.parents[e.offset]=r,e.offset++}}}}function m(t,e){for(var n=0,r=t._activeChildren.length;n<r;n++){var i=t._activeChildren[n];switch(i._type){case rt:case it:i._state!==ot&&(i._state=ot,m(i,e));break;case ut:e.push(i)}}}function w(t){for(var e=0,n=t.length;e<n;e++){var r=t[e];if(r._reacting)throw new Error("Synchronous cyclical reactions disallowed. Use setImmediate.");r._maybeReact()}}function b(){throw lt}function E(t){this.parent=t,this.id2originalValue={},this.modifiedAtoms=[]}function k(t){null!==_t&&(t._id in _t.id2originalValue||(_t.modifiedAtoms.push(t),_t.id2originalValue[t._id]=t._value)); | ||
}function A(){return null!==_t}function q(t){x();try{t.call(null,b)}catch(e){if(T(),e!==lt)throw e;return}R()}function O(t){A()?t():q(t)}function D(t){return function(){var e,n=s(arguments,0),r=this;return q(function(){e=t.apply(r,n)}),e}}function C(t){return function(){var e,n=s(arguments,0),r=this;return O(function(){e=t.apply(r,n)}),e}}function x(){_t=new E(_t)}function R(){var t=_t;if(_t=t.parent,null===_t){var e=[];t.modifiedAtoms.forEach(function(n){n.__equals(n._value,t.id2originalValue[n._id])?n._state=at:(n._state=st,m(n,e))}),w(e),t.modifiedAtoms.forEach(function(t){t._state=at})}}function T(){var t=_t;_t=t.parent,t.modifiedAtoms.forEach(function(e){e._value=t.id2originalValue[e._id],e._state=at,m(e,[])})}function j(){0===pt&&x(),pt++;var t=!1;return{tick:function(){if(t)throw new Error("trying to use ticker after release");R(),x()},reset:function(){if(t)throw new Error("trying to use ticker after release");T(),x()},release:function(){if(t)throw new Error("ticker already released");pt--,t=!0,0===pt&&R()}}}function V(t){this._deriver=t,this._parents=null,this._type=rt,this._value=tt,this._equals=null,this._activeChildren=[],this._state=ct,et&&(this.stack=Error().stack)}function S(t,e){if(u(t._activeChildren,e),0===t._activeChildren.length&&null!=t._parents){for(var n=t._parents.length,r=0;r<n;r++)S(t._parents[r],t);t._parents=null,t._state=ct}}function M(t){return new V(t)}function I(t,e,n){this._parent=t,this.react=e,this._governor=n||null,this._active=!1,this._reacting=!1,this._type=ut,et&&(this.stack=Error().stack)}function L(t,n,r){function i(t,e){if(!h(t)){if("function"==typeof t)return M(t);if("boolean"==typeof t)return M(function(){return t});throw Error("react "+e+" condition must be derivable, got: "+JSON.stringify(t))}return t}if("function"!=typeof n)throw Error("the first argument to .react must be a function");r=e({once:!1,from:!0,until:!1,when:!0,skipFirst:!1},r);var u=r.skipFirst,o=new I(t,function(t){u?u=!1:(n(t),r.once&&(this.stop(),f.stop()))}),s=i(r.until,"until"),a=i(r.when,"when"),c=M(function(){ | ||
return{until:s.get(),when:a.get()}}),f=new I(c,function(t){t.until?(o.stop(),this.stop()):t.when?o._active||o.start().force():o._active&&o.stop()});o._governor=f;var l=i(r.from,"from"),_=new I(l,function(t){t&&(f.start().force(),this.stop())});_.start().force()}function N(t){return this._id=o(),this._activeChildren=[],this._value=t,this._state=at,this._type=nt,this._equals=null,this}function P(t){return new N(t)}function z(t){V.call(this,t.get),this._lensDescriptor=t,this._type=it}function F(t){return new z(t)}function J(t){var e=s(arguments,1);return kt(function(){for(var n="",r=0;r<t.length;r++)n+=t[r],r<e.length&&(n+=U(e[r]));return n})}function U(t){return mt(t)?t.get():t}function B(t){return function(){var e=arguments,n=this;return kt(function(){return t.apply(n,Array.prototype.map.call(e,U))})}}function G(t){if(mt(t))return t.get();if(t instanceof Array)return t.map(G);if(t.constructor===Object){for(var e={},n=Z(t),r=n.length;r--;){var i=n[r];e[i]=G(t[i])}return e}return t}function H(t){if(t.constructor===Object||t instanceof Array)return kt(function(){return G(t)});throw new Error("`struct` expects plain Object or Array")}function K(t,e){var n=e;return function(e){var r=t.call(this,e,n);return n=e,r}}function Q(t){var e=[];v(void 0,e);try{t()}finally{y()}return e}function W(t){return function(){var e=arguments;return kt(function(){for(var n,r=0;r<e.length&&(n=U(e[r]),!t(n));r++);return n})}}function X(t){return t}function Y(t){return function(e){return!t(e)}}Object.defineProperty(t,"__esModule",{value:!0});var Z=Object.keys,$=0,tt=Object.freeze({equals:function(){return!1}}),et=!1,nt="ATOM",rt="DERIVATION",it="LENS",ut="REACTOR",ot=0,st=1,at=2,ct=3,ft=[],ht=null,lt={},_t=null,pt=0;e(V.prototype,{_clone:function(){return f(M(this._deriver),this._equals)},_forceEval:function(){var t,e=this,n=null;try{if(null===this._parents&&(this._parents=[]),v(this,this._parents),et)try{n=e._deriver()}catch(r){throw console.error(e.stack),r}else n=e._deriver();t=d().offset}finally{y()}this._state=this.__equals(n,this._value)?at:st; | ||
for(var i=t,u=this._parents.length;i<u;i++){var o=this._parents[i];S(o,this),this._parents[i]=null}this._parents.length=t,this._value=n},_update:function(){if(null===this._parents)this._forceEval();else if(this._state===ot){for(var t=this._parents.length,e=0;e<t;e++){var n=this._parents[e];if(n._state===ot&&n._update(),n._state===st){this._forceEval();break}}this._state===ot&&(this._state=at)}},get:function(){if(g(this),this._activeChildren.length>0)this._update();else{v(void 0,[]);try{this._value=this._deriver()}finally{y()}}return this._value}}),e(I.prototype,{start:function(){return this._active=!0,i(this._parent._activeChildren,this),this._parent.get(),this},_force:function(t){try{this._reacting=!0,this.react(t)}catch(e){throw et&&console.error(this.stack),e}finally{this._reacting=!1}},force:function(){return this._force(this._parent.get()),this},_maybeReact:function(){if(!this._reacting&&this._active&&(null!==this._governor&&this._governor._maybeReact(),this._active)){var t=this._parent.get();this._parent._state===st&&this._force(t)}},stop:function(){return S(this._parent,this),this._active=!1,this}}),e(N.prototype,{_clone:function(){return f(P(this._value),this._equals)},set:function(t){k(this);var e=this._value;if(this._value=t,!A()&&!this.__equals(t,e))try{this._state=st;var n=[];m(this,n),w(n)}finally{this._state=at}},get:function(){return g(this),this._value}}),e(z.prototype,V.prototype,{_clone:function(){return f(new z(this._lensDescriptor),this._equals)},set:function(t){var e=this;return O(function(){e._lensDescriptor.set(t)}),this}});var vt=q,dt=c,yt=D,gt=j,mt=h,wt=l,bt=p,Et=_,kt=M,At=P,qt=C,Ot=O,Dt=F,Ct=W(X),xt=W(a),Rt=W(Y(X)),Tt=W(Y(a)),jt=Object.freeze({transact:vt,setDebugMode:dt,transaction:yt,ticker:gt,isDerivable:mt,isAtom:wt,isLensed:bt,isDerivation:Et,derivation:kt,atom:At,atomic:qt,atomically:Ot,lens:Dt,derive:J,unpack:U,lift:B,struct:H,wrapPreviousState:K,captureDereferences:Q,or:Ct,mOr:xt,and:Rt,mAnd:Tt}),Vt={derive:function(t,e,n,r,i){var u=this;switch(arguments.length){case 0:throw new Error(".derive takes at least one argument"); | ||
case 1:switch(typeof t){case"function":return kt(function(){return t(u.get())});case"string":case"number":return kt(function(){return u.get()[U(t)]});default:if(t instanceof Array)return t.map(function(t){return u.derive(t)});if(t instanceof RegExp)return kt(function(){return u.get().match(t)});if(h(t))return kt(function(){var e=t.get(),n=u.get();switch(typeof e){case"function":return e(n);case"string":case"number":return n[e];default:if(e instanceof RegExp)return n.match(e);throw Error("type error")}});throw Error("type error")}case 2:return kt(function(){return t(u.get(),U(e))});case 3:return kt(function(){return t(u.get(),U(e),U(n))});case 4:return kt(function(){return t(u.get(),U(e),U(n),U(r))});case 5:return kt(function(){return t(u.get(),U(e),U(n),U(r),U(i))});default:var o=[u].concat(s(arguments,1));return kt(function(){return t.apply(null,o.map(U))})}},react:function(t,e){L(this,t,e)},mReact:function(t,n){var r=this.mThen(!0,!1);if(n&&"when"in n&&n.when!==!0){var i=n.when;if("function"==typeof i||i===!1)i=kt(i);else if(!h(i))throw new Error("when condition must be bool, function, or derivable");r=i.and(r)}return this.react(t,e({},n,{when:r}))},is:function(t){var e=this;return this.derive(function(n){return e.__equals(n,U(t))})},and:function(t){return this.derive(function(e){return e&&U(t)})},or:function(t){return this.derive(function(e){return e||U(t)})},then:function(t,e){return this.derive(function(n){return U(n?t:e)})},mThen:function(t,e){return this.derive(function(n){return U(a(n)?t:e)})},mOr:function(t){return this.mThen(this,t)},mDerive:function(t){if(1===arguments.length&&t instanceof Array){var e=this;return t.map(function(t){return e.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||r)(t,e)}};Vt["switch"]=function(){ | ||
var t=arguments,e=this;return this.derive(function(n){var r;for(r=0;r<t.length-1;r+=2)if(e.__equals(n,U(t[r])))return U(t[r+1]);if(r===t.length-1)return U(t[r])})};var St={swap:function(t){var e=s(arguments,0);return e[0]=this.get(),this.set(t.apply(null,e))},lens:function(t){var e=this;return new z({get:function(){return t.get(e.get())},set:function(n){e.set(t.set(e.get(),n))}})}};e(V.prototype,Vt),e(z.prototype,Vt,St),e(N.prototype,Vt,St);var Mt=vt,It=dt,Lt=yt,Nt=gt,Pt=mt,zt=wt,Ft=bt,Jt=Et,Ut=kt,Bt=At,Gt=qt,Ht=Ot,Kt=Dt,Qt=J,Wt=U,Xt=B,Yt=H,Zt=K,$t=Q,te=Ct,ee=xt,ne=Rt,re=Tt;t.transact=Mt,t.setDebugMode=It,t.transaction=Lt,t.ticker=Nt,t.isDerivable=Pt,t.isAtom=zt,t.isLensed=Ft,t.isDerivation=Jt,t.derivation=Ut,t.atom=Bt,t.atomic=Gt,t.atomically=Ht,t.lens=Kt,t.derive=Qt,t.unpack=Wt,t.lift=Xt,t.struct=Yt,t.wrapPreviousState=Zt,t.captureDereferences=$t,t.or=te,t.mOr=ee,t.and=ne,t.mAnd=re,t["default"]=jt}); | ||
}function A(){return null!==_t}function q(t){C();try{t.call(null,b)}catch(e){if(T(),e!==lt)throw e;return}x()}function O(t){A()?t():q(t)}function D(t){return function(){var e,n=s(arguments,0),r=this;return q(function(){e=t.apply(r,n)}),e}}function R(t){return function(){var e,n=s(arguments,0),r=this;return O(function(){e=t.apply(r,n)}),e}}function C(){_t=new E(_t)}function x(){var t=_t;if(_t=t.parent,null===_t){var e=[];t.modifiedAtoms.forEach(function(n){n.__equals(n._value,t.id2originalValue[n._id])?n._state=at:(n._state=st,m(n,e))}),w(e),t.modifiedAtoms.forEach(function(t){t._state=at})}}function T(){var t=_t;_t=t.parent,t.modifiedAtoms.forEach(function(e){e._value=t.id2originalValue[e._id],e._state=at,m(e,[])})}function j(){0===pt&&C(),pt++;var t=!1;return{tick:function(){if(t)throw new Error("trying to use ticker after release");x(),C()},reset:function(){if(t)throw new Error("trying to use ticker after release");T(),C()},release:function(){if(t)throw new Error("ticker already released");pt--,t=!0,0===pt&&x()}}}function V(t){this._deriver=t,this._parents=null,this._type=rt,this._value=tt,this._equals=null,this._activeChildren=[],this._state=ct,et&&(this.stack=Error().stack)}function S(t,e){if(u(t._activeChildren,e),0===t._activeChildren.length&&null!=t._parents){for(var n=t._parents.length,r=0;r<n;r++)S(t._parents[r],t);t._parents=null,t._state=ct}}function M(t){return new V(t)}function I(t,e,n){this._parent=t,this.react=e,this._governor=n||null,this._active=!1,this._reacting=!1,this._type=ut,et&&(this.stack=Error().stack)}function L(t,n,r){function i(t,e){if(!h(t)){if("function"==typeof t)return M(t);if("boolean"==typeof t)return M(function(){return t});throw Error("react "+e+" condition must be derivable, got: "+JSON.stringify(t))}return t}if("function"!=typeof n)throw Error("the first argument to .react must be a function");r=e({once:!1,from:!0,until:!1,when:!0,skipFirst:!1},r);var u=r.skipFirst,o=new I(t,function(t){u?u=!1:(n(t),r.once&&(this.stop(),f.stop()))}),s=i(r.until,"until"),a=i(r.when,"when"),c=M(function(){ | ||
return{until:s.get(),when:a.get()}}),f=new I(c,function(t){t.until?(o.stop(),this.stop()):t.when?o._active||o.start().force():o._active&&o.stop()});o._governor=f;var l=i(r.from,"from"),_=new I(l,function(t){t&&(f.start().force(),this.stop())});_.start().force()}function N(t){return this._id=o(),this._activeChildren=[],this._value=t,this._state=at,this._type=nt,this._equals=null,this}function P(t){return new N(t)}function z(t){V.call(this,t.get),this._lensDescriptor=t,this._type=it}function F(t){return new z(t)}function J(t){var e=s(arguments,1);return At(function(){for(var n="",r=0;r<t.length;r++)n+=t[r],r<e.length&&(n+=U(e[r]));return n})}function U(t){return wt(t)?t.get():t}function B(t){return function(){var e=arguments,n=this;return At(function(){return t.apply(n,Array.prototype.map.call(e,U))})}}function G(t){if(wt(t))return t.get();if(t instanceof Array)return t.map(G);if(t.constructor===Object){for(var e={},n=Z(t),r=n.length;r--;){var i=n[r];e[i]=G(t[i])}return e}return t}function H(t){if(t.constructor===Object||t instanceof Array)return At(function(){return G(t)});throw new Error("`struct` expects plain Object or Array")}function K(t,e){var n=e;return function(e){var r=t.call(this,e,n);return n=e,r}}function Q(t){var e=[];v(void 0,e);try{t()}finally{y()}return e}function W(t){return function(){var e=arguments;return At(function(){for(var n,r=0;r<e.length&&(n=U(e[r]),!t(n));r++);return n})}}function X(t){return t}function Y(t){return function(e){return!t(e)}}Object.defineProperty(t,"__esModule",{value:!0});var Z=Object.keys,$=0,tt=Object.freeze({equals:function(){return!1}}),et=!1,nt="ATOM",rt="DERIVATION",it="LENS",ut="REACTOR",ot=0,st=1,at=2,ct=3,ft=[],ht=null,lt={},_t=null,pt=0;e(V.prototype,{_clone:function(){return f(M(this._deriver),this._equals)},_forceEval:function(){var t,e=this,n=null;try{if(null===this._parents&&(this._parents=[]),v(this,this._parents),et)try{n=e._deriver()}catch(r){throw console.error(e.stack),r}else n=e._deriver();t=d().offset}finally{y()}this._state=this.__equals(n,this._value)?at:st; | ||
for(var i=t,u=this._parents.length;i<u;i++){var o=this._parents[i];S(o,this),this._parents[i]=null}this._parents.length=t,this._value=n},_update:function(){if(null===this._parents)this._forceEval();else if(this._state===ot){for(var t=this._parents.length,e=0;e<t;e++){var n=this._parents[e];if(n._state===ot&&n._update(),n._state===st){this._forceEval();break}}this._state===ot&&(this._state=at)}},get:function(){if(g(this),this._activeChildren.length>0)this._update();else{v(void 0,[]);try{this._value=this._deriver()}finally{y()}}return this._value}}),e(I.prototype,{start:function(){return this._active=!0,i(this._parent._activeChildren,this),this._parent.get(),this},_force:function(t){try{this._reacting=!0,this.react(t)}catch(e){throw et&&console.error(this.stack),e}finally{this._reacting=!1}},force:function(){return this._force(this._parent.get()),this},_maybeReact:function(){if(!this._reacting&&this._active&&(null!==this._governor&&this._governor._maybeReact(),this._active)){var t=this._parent.get();this._parent._state===st&&this._force(t)}},stop:function(){return S(this._parent,this),this._active=!1,this}}),e(N.prototype,{_clone:function(){return f(P(this._value),this._equals)},set:function(t){k(this);var e=this._value;if(this._value=t,!A()&&!this.__equals(t,e))try{this._state=st;var n=[];m(this,n),w(n)}finally{this._state=at}},get:function(){return g(this),this._value}}),e(z.prototype,V.prototype,{_clone:function(){return f(new z(this._lensDescriptor),this._equals)},set:function(t){var e=this;return O(function(){e._lensDescriptor.set(t)}),this}});var vt=I,dt=q,yt=c,gt=D,mt=j,wt=h,bt=l,Et=p,kt=_,At=M,qt=P,Ot=R,Dt=O,Rt=F,Ct=W(X),xt=W(a),Tt=W(Y(X)),jt=W(Y(a)),Vt=Object.freeze({__Reactor:vt,transact:dt,setDebugMode:yt,transaction:gt,ticker:mt,isDerivable:wt,isAtom:bt,isLensed:Et,isDerivation:kt,derivation:At,atom:qt,atomic:Ot,atomically:Dt,lens:Rt,derive:J,unpack:U,lift:B,struct:H,wrapPreviousState:K,captureDereferences:Q,or:Ct,mOr:xt,and:Tt,mAnd:jt}),St={derive:function(t,e,n,r,i){var u=this;switch(arguments.length){ | ||
case 0:throw new Error(".derive takes at least one argument");case 1:switch(typeof t){case"function":return At(function(){return t(u.get())});case"string":case"number":return At(function(){return u.get()[U(t)]});default:if(t instanceof Array)return t.map(function(t){return u.derive(t)});if(t instanceof RegExp)return At(function(){return u.get().match(t)});if(h(t))return At(function(){var e=t.get(),n=u.get();switch(typeof e){case"function":return e(n);case"string":case"number":return n[e];default:if(e instanceof RegExp)return n.match(e);throw Error("type error")}});throw Error("type error")}case 2:return At(function(){return t(u.get(),U(e))});case 3:return At(function(){return t(u.get(),U(e),U(n))});case 4:return At(function(){return t(u.get(),U(e),U(n),U(r))});case 5:return At(function(){return t(u.get(),U(e),U(n),U(r),U(i))});default:var o=[u].concat(s(arguments,1));return At(function(){return t.apply(null,o.map(U))})}},react:function(t,e){L(this,t,e)},mReact:function(t,n){var r=this.mThen(!0,!1);if(n&&"when"in n&&n.when!==!0){var i=n.when;if("function"==typeof i||i===!1)i=At(i);else if(!h(i))throw new Error("when condition must be bool, function, or derivable");r=i.and(r)}return this.react(t,e({},n,{when:r}))},is:function(t){var e=this;return this.derive(function(n){return e.__equals(n,U(t))})},and:function(t){return this.derive(function(e){return e&&U(t)})},or:function(t){return this.derive(function(e){return e||U(t)})},then:function(t,e){return this.derive(function(n){return U(n?t:e)})},mThen:function(t,e){return this.derive(function(n){return U(a(n)?t:e)})},mOr:function(t){return this.mThen(this,t)},mDerive:function(t){if(1===arguments.length&&t instanceof Array){var e=this;return t.map(function(t){return e.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||r)(t,e)}};St["switch"]=function(){var t=arguments,e=this;return this.derive(function(n){var r;for(r=0;r<t.length-1;r+=2)if(e.__equals(n,U(t[r])))return U(t[r+1]);if(r===t.length-1)return U(t[r])})};var Mt={swap:function(t){var e=s(arguments,0);return e[0]=this.get(),this.set(t.apply(null,e))},lens:function(t){var e=this;return new z({get:function(){return t.get(e.get())},set:function(n){e.set(t.set(e.get(),n))}})}};e(V.prototype,St),e(z.prototype,St,Mt),e(N.prototype,St,Mt);var It=vt,Lt=dt,Nt=yt,Pt=gt,zt=mt,Ft=wt,Jt=bt,Ut=Et,Bt=kt,Gt=At,Ht=qt,Kt=Ot,Qt=Dt,Wt=Rt,Xt=J,Yt=U,Zt=B,$t=H,te=K,ee=Q,ne=Ct,re=xt,ie=Tt,ue=jt;t.__Reactor=It,t.transact=Lt,t.setDebugMode=Nt,t.transaction=Pt,t.ticker=zt,t.isDerivable=Ft,t.isAtom=Jt,t.isLensed=Ut,t.isDerivation=Bt,t.derivation=Gt,t.atom=Ht,t.atomic=Kt,t.atomically=Qt,t.lens=Wt,t.derive=Xt,t.unpack=Yt,t.lift=Zt,t.struct=$t,t.wrapPreviousState=te,t.captureDereferences=ee,t.or=ne,t.mOr=re,t.and=ie,t.mAnd=ue,t["default"]=Vt}); | ||
//# sourceMappingURL=dist/derivable.umd.min.js.map | ||
//# sourceMappingURL=derivable.umd.min.js.map |
{ | ||
"name": "derivable", | ||
"version": "1.0.0-beta", | ||
"version": "1.0.0-beta10", | ||
"description": "Functional Reactive State for JavaScript & TypeScript", | ||
@@ -10,4 +10,6 @@ "author": "David Sheldrick", | ||
"scripts": { | ||
"build": "node scripts/build.js", | ||
"prepublish": "npm run build", | ||
"build": "node scripts/build.js && cp derivable.d.ts derivable.js.flow dist/", | ||
"test": "mocha --recursive", | ||
"ci:test": "mocha --recursive && (cd test_flow && npm install && npm test)", | ||
"bench": "node scripts/bench.js", | ||
@@ -53,3 +55,5 @@ "coverage": "./scripts/coverage.sh && istanbul report --include=coverage-final.json text", | ||
"mocha-istanbul": "^0.2.0", | ||
"promise": "^7.1.1", | ||
"rollup": "^0.26.1", | ||
"source-map": "^0.5.6", | ||
"source-map-support": "^0.3.2", | ||
@@ -56,0 +60,0 @@ "uglify-js": "^2.4.24" |
@@ -9,2 +9,4 @@ <h1 align="center">DerivableJS</h1> | ||
**This README is work in progress. Please refer to the master branch's README for rationale etc.** | ||
<!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
@@ -163,16 +165,5 @@ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
[react-derivable](https://github.com/jevakallio/react-derivable) is where it's at. | ||
The fantastic project [react-derivable](https://github.com/andreypopp/react-derivable) lets you use | ||
derivables in your render method, providing seamless interop with component-local state and props. | ||
### With Redux | ||
DerivableJS can be used as a kind-of replacement for reselect, by just doing something like this: | ||
```javascript | ||
const $Store = atom(null); | ||
myReduxStore.subscribe(() => $Store.set(myReduxStore.getState())); | ||
``` | ||
and then you derive all your derived state from $Store, rather than | ||
### Debugging | ||
@@ -182,22 +173,9 @@ | ||
### Examples (very wip) | ||
### Examples | ||
The best example of writing good code with Derivables right now is the [talk demo](https://github.com/ds300/derivables-talk-demo), which is presented as a 'diff tutorial' and should be read from the initial commit. | ||
Coming soon. | ||
The next best is the [routing walkthrough](https://github.com/ds300/derivablejs/tree/master/examples/routing/README.md) | ||
I've also implemented a solution to @staltz's [flux challenge](https://github.com/staltz/flux-challenge/tree/master/submissions/ds300). | ||
There is a proper gitbook tutorial on the way! | ||
### Browser | ||
Either with browserify/webpack/common-js-bundler-du-jour or build as umd bundle with `npm run build -- --umd` | ||
Either with browserify/webpack/common-js-bundler-du-jour, or clone the repo, run `npm install && npm run build`, then grab the UMD bundle from `dist/derivable.umd[.min].js` (source maps are also available). | ||
### Equality Woes | ||
JavaScript is entirely whack when it comes to equality. People do [crazy jazz](https://github.com/ramda/ramda/blob/v0.16.0/src/internal/_equals.js) trying to figure out if some stuff is the same as some other stuff. | ||
If the data you're threading through DerivableJS needs its own notion of equality, make sure it has a sensible `.equals` method and everything will be fine. | ||
If you're using a data library with some custom non-standard mechanism for doing equality checks (e.g. mori), then you'll need to re-initialize DerivableJS with a custom equality function. | ||
```javascript | ||
@@ -204,0 +182,0 @@ import { withEquality } from 'derivable' |
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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
254993
14
2089
0
18
213