Comparing version 0.13.0-beta3 to 0.13.0-beta4
@@ -269,24 +269,3 @@ // UMD loader | ||
this.react(nextValue); | ||
var oldAtoms = this._atoms; | ||
var newAtoms = []; | ||
this._atoms = newAtoms; | ||
captureAtoms(this._derivable, newAtoms); | ||
var that = this; | ||
newAtoms.forEach(function (atom) { | ||
var idx = oldAtoms.indexOf(atom); | ||
if (idx === -1) { | ||
util_addToArray(atom._reactors, that); | ||
} else { | ||
oldAtoms[idx] = null; | ||
} | ||
}); | ||
oldAtoms.forEach(function (atom) { | ||
if (atom !== null) { | ||
util_removeFromArray(atom._reactors, that); | ||
} | ||
}); | ||
} catch (e) { | ||
@@ -323,7 +302,31 @@ if (util_DEBUG_MODE) { | ||
if (this._derivable._epoch !== this._lastEpoch && | ||
!this._derivable.__equals(nextValue, this._lastValue)) { | ||
this._force(nextValue); | ||
!this._derivable.__equals(nextValue, this._lastValue)) { | ||
this._force(nextValue); | ||
} | ||
// need to check atoms regardless of whether reactions happens | ||
// TODO: incorporate atom capturing into .get somehow | ||
this._lastEpoch = this._derivable._epoch; | ||
this._lastValue = nextValue; | ||
var oldAtoms = this._atoms; | ||
var newAtoms = []; | ||
this._atoms = newAtoms; | ||
captureAtoms(this._derivable, newAtoms); | ||
var that = this; | ||
newAtoms.forEach(function (atom) { | ||
var idx = oldAtoms.indexOf(atom); | ||
if (idx === -1) { | ||
util_addToArray(atom._reactors, that); | ||
} else { | ||
oldAtoms[idx] = null; | ||
} | ||
this._lastEpoch = this._derivable._epoch; | ||
this._lastValue = nextValue; | ||
}); | ||
oldAtoms.forEach(function (atom) { | ||
if (atom !== null) { | ||
util_removeFromArray(atom._reactors, that); | ||
} | ||
}); | ||
} | ||
@@ -330,0 +333,0 @@ } |
@@ -6,3 +6,3 @@ !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); | ||
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}); | ||
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)}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,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;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)})}}},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-beta3", | ||
"version": "0.13.0-beta4", | ||
"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
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
171060
1088