Comparing version 2.0.0-beta.2 to 2.0.0-beta.3
@@ -1,5 +0,1 @@ | ||
/** | ||
* This TypeScript file was generated from derivable.api.edn. | ||
* Please change that file and re-run `grunt docs` to modify this file. | ||
*/ | ||
declare module derivable { | ||
@@ -13,3 +9,3 @@ | ||
orDefault<E>(E): Derivable<T | E> | ||
orDefault<E>(value: E): Derivable<T | E> | ||
@@ -24,3 +20,3 @@ react(f: (value: T) => void, options?: Lifecycle<T>): void; | ||
withEquality(equals: (a: any, b: any) => boolean): this; | ||
withEquality(equals: (a: T, b: T) => boolean): this; | ||
} | ||
@@ -30,18 +26,15 @@ | ||
set<E>(value: E): Atom<E>; | ||
set(value: T): void; | ||
update<E>(f: (value: T, ...args: any[]) => E, ...args: any[]): Atom<E>; | ||
proxy<E>(proxy: Proxy<T, E>): Atom<E>; | ||
update(f: (value: T) => T): void; | ||
update<A>(f: (value: T, a: A) => T, a: A): void; | ||
update<A, B>(f: (value: T, a: A, b: B) => T, a: A, b: B): void; | ||
update<A, B, C>(f: (value: T, a: A, b: B, c: C) => T, a: A, b: B, c: C): void; | ||
update<A, B, C, D>(f: (value: T, a: A, b: B, c: C, d: D) => T, a: A, b: B, c: C, d: D): void; | ||
} | ||
export interface Proxy<ParentType, ChildType> { | ||
export interface Lens<T> extends Atom<T> {} | ||
get(source: ParentType): ChildType; | ||
export interface LensDescriptor<T> { | ||
set(source: ParentType, value: ChildType): ParentType; | ||
} | ||
export interface CompositeProxy<T> { | ||
get(): T; | ||
@@ -69,11 +62,11 @@ | ||
function proxy<T>(proxy: CompositeProxy<T>): Atom<T>; | ||
function lens<T>(descriptor: LensDescriptor<T>): Lens<T>; | ||
function transact(f: () => void): void; | ||
function transaction(f: (...args: any[]) => any): (...args: any[]) => any; | ||
function transaction<F extends Function>(f: F): F; | ||
function atomically(f: () => void): void; | ||
function atomic(f: (...args: any[]) => any): (...args: any[]) => any; | ||
function atomic<F extends Function>(f: F): F; | ||
@@ -90,6 +83,4 @@ function struct(obj: any): Derivable<any>; | ||
function isProxy(obj: any): boolean; | ||
function isLens(obj: any): boolean; | ||
function captureDereferences(fn: () => void): Derivable<any>[]; | ||
function setDebugMode(debugMode: boolean): void; | ||
@@ -96,0 +87,0 @@ |
@@ -55,19 +55,19 @@ var assign = Object.assign; | ||
var DERIVATION = "DERIVATION"; | ||
var PROXY = "PROXY"; | ||
var LENS = "LENS"; | ||
var REACTOR = "REACTOR"; | ||
function isDerivable(x) { | ||
return x && (x._type === DERIVATION || x._type === ATOM || x._type === PROXY); | ||
return x && (x._type === DERIVATION || x._type === ATOM || x._type === LENS); | ||
} | ||
function isAtom(x) { | ||
return x && (x._type === ATOM || x._type === PROXY); | ||
return x && (x._type === ATOM || x._type === LENS); | ||
} | ||
function isDerivation(x) { | ||
return x && (x._type === DERIVATION || x._type === PROXY); | ||
return x && (x._type === DERIVATION || x._type === LENS); | ||
} | ||
function isProxy(x) { | ||
return x && x._type === PROXY; | ||
function isLens(x) { | ||
return x && x._type === LENS; | ||
} | ||
@@ -148,3 +148,5 @@ | ||
function Derivation(deriver) { | ||
function Derivation(deriver, meta) { | ||
if ( meta === void 0 ) meta = null; | ||
this._deriver = deriver; | ||
@@ -157,2 +159,3 @@ this._parents = null; | ||
this._state = DISCONNECTED; | ||
this._meta = meta; | ||
@@ -267,7 +270,7 @@ if (isDebug()) { | ||
function derive(f) { | ||
function derive(f, meta) { | ||
if (typeof f !== "function") { | ||
throw Error("derive requires function"); | ||
} | ||
return new Derivation(f); | ||
return new Derivation(f, meta); | ||
} | ||
@@ -558,3 +561,3 @@ | ||
case DERIVATION: | ||
case PROXY: | ||
case LENS: | ||
if (child._state !== UNKNOWN) { | ||
@@ -730,3 +733,5 @@ child._state = UNKNOWN; | ||
function Atom(value) { | ||
function Atom(value, meta) { | ||
if ( meta === void 0 ) meta = null; | ||
this._id = nextId(); | ||
@@ -738,2 +743,3 @@ this._activeChildren = []; | ||
this._equals = null; | ||
this._meta = meta; | ||
} | ||
@@ -775,15 +781,15 @@ | ||
function atom(value) { | ||
return new Atom(value); | ||
function atom(value, meta) { | ||
return new Atom(value, meta); | ||
} | ||
function Proxy(descriptor) { | ||
Derivation.call(this, descriptor.get); | ||
this._proxyMapping = descriptor; | ||
this._type = PROXY; | ||
function Lens(descriptor, meta) { | ||
Derivation.call(this, descriptor.get, meta); | ||
this._descriptor = descriptor; | ||
this._type = LENS; | ||
} | ||
assign(Proxy.prototype, Derivation.prototype, { | ||
assign(Lens.prototype, Derivation.prototype, { | ||
_clone: function _clone() { | ||
return setEquals(new Proxy(this._proxyMapping), this._equals); | ||
return setEquals(new Lens(this._descriptor), this._equals); | ||
}, | ||
@@ -795,3 +801,3 @@ | ||
atomically(function () { | ||
this$1._proxyMapping.set(value); | ||
this$1._descriptor.set(value); | ||
}); | ||
@@ -801,8 +807,8 @@ } | ||
function proxy(descriptor) { | ||
return new Proxy(descriptor); | ||
function lens(descriptor, meta) { | ||
return new Lens(descriptor, meta); | ||
} | ||
assign(Derivation.prototype, derivablePrototype); | ||
assign(Proxy.prototype, derivablePrototype, mutablePrototype); | ||
assign(Lens.prototype, derivablePrototype, mutablePrototype); | ||
assign(Atom.prototype, derivablePrototype, mutablePrototype); | ||
@@ -817,3 +823,3 @@ | ||
export { atom, proxy, derive, setDebugMode, isDerivable, isAtom, isProxy, isDerivation, unpack, struct, transact, transaction, ticker, atomic, atomically, Reactor as __Reactor, captureDereferences as __captureDereferences }; | ||
export { atom, lens, derive, setDebugMode, isDerivable, isAtom, isLens, isDerivation, unpack, struct, transact, transaction, ticker, atomic, atomically, Reactor as __Reactor, captureDereferences as __captureDereferences }; | ||
//# sourceMappingURL=derivable.es.js.map |
@@ -59,19 +59,19 @@ 'use strict'; | ||
var DERIVATION = "DERIVATION"; | ||
var PROXY = "PROXY"; | ||
var LENS = "LENS"; | ||
var REACTOR = "REACTOR"; | ||
function isDerivable(x) { | ||
return x && (x._type === DERIVATION || x._type === ATOM || x._type === PROXY); | ||
return x && (x._type === DERIVATION || x._type === ATOM || x._type === LENS); | ||
} | ||
function isAtom(x) { | ||
return x && (x._type === ATOM || x._type === PROXY); | ||
return x && (x._type === ATOM || x._type === LENS); | ||
} | ||
function isDerivation(x) { | ||
return x && (x._type === DERIVATION || x._type === PROXY); | ||
return x && (x._type === DERIVATION || x._type === LENS); | ||
} | ||
function isProxy(x) { | ||
return x && x._type === PROXY; | ||
function isLens(x) { | ||
return x && x._type === LENS; | ||
} | ||
@@ -152,3 +152,5 @@ | ||
function Derivation(deriver) { | ||
function Derivation(deriver, meta) { | ||
if ( meta === void 0 ) meta = null; | ||
this._deriver = deriver; | ||
@@ -161,2 +163,3 @@ this._parents = null; | ||
this._state = DISCONNECTED; | ||
this._meta = meta; | ||
@@ -271,7 +274,7 @@ if (isDebug()) { | ||
function derive(f) { | ||
function derive(f, meta) { | ||
if (typeof f !== "function") { | ||
throw Error("derive requires function"); | ||
} | ||
return new Derivation(f); | ||
return new Derivation(f, meta); | ||
} | ||
@@ -562,3 +565,3 @@ | ||
case DERIVATION: | ||
case PROXY: | ||
case LENS: | ||
if (child._state !== UNKNOWN) { | ||
@@ -734,3 +737,5 @@ child._state = UNKNOWN; | ||
function Atom(value) { | ||
function Atom(value, meta) { | ||
if ( meta === void 0 ) meta = null; | ||
this._id = nextId(); | ||
@@ -742,2 +747,3 @@ this._activeChildren = []; | ||
this._equals = null; | ||
this._meta = meta; | ||
} | ||
@@ -779,15 +785,15 @@ | ||
function atom(value) { | ||
return new Atom(value); | ||
function atom(value, meta) { | ||
return new Atom(value, meta); | ||
} | ||
function Proxy(descriptor) { | ||
Derivation.call(this, descriptor.get); | ||
this._proxyMapping = descriptor; | ||
this._type = PROXY; | ||
function Lens(descriptor, meta) { | ||
Derivation.call(this, descriptor.get, meta); | ||
this._descriptor = descriptor; | ||
this._type = LENS; | ||
} | ||
assign(Proxy.prototype, Derivation.prototype, { | ||
assign(Lens.prototype, Derivation.prototype, { | ||
_clone: function _clone() { | ||
return setEquals(new Proxy(this._proxyMapping), this._equals); | ||
return setEquals(new Lens(this._descriptor), this._equals); | ||
}, | ||
@@ -799,3 +805,3 @@ | ||
atomically(function () { | ||
this$1._proxyMapping.set(value); | ||
this$1._descriptor.set(value); | ||
}); | ||
@@ -805,8 +811,8 @@ } | ||
function proxy(descriptor) { | ||
return new Proxy(descriptor); | ||
function lens(descriptor, meta) { | ||
return new Lens(descriptor, meta); | ||
} | ||
assign(Derivation.prototype, derivablePrototype); | ||
assign(Proxy.prototype, derivablePrototype, mutablePrototype); | ||
assign(Lens.prototype, derivablePrototype, mutablePrototype); | ||
assign(Atom.prototype, derivablePrototype, mutablePrototype); | ||
@@ -822,3 +828,3 @@ | ||
exports.atom = atom; | ||
exports.proxy = proxy; | ||
exports.lens = lens; | ||
exports.derive = derive; | ||
@@ -828,3 +834,3 @@ exports.setDebugMode = setDebugMode; | ||
exports.isAtom = isAtom; | ||
exports.isProxy = isProxy; | ||
exports.isLens = isLens; | ||
exports.isDerivation = isDerivation; | ||
@@ -831,0 +837,0 @@ exports.unpack = unpack; |
@@ -61,19 +61,19 @@ (function (global, factory) { | ||
var DERIVATION = "DERIVATION"; | ||
var PROXY = "PROXY"; | ||
var LENS = "LENS"; | ||
var REACTOR = "REACTOR"; | ||
function isDerivable(x) { | ||
return x && (x._type === DERIVATION || x._type === ATOM || x._type === PROXY); | ||
return x && (x._type === DERIVATION || x._type === ATOM || x._type === LENS); | ||
} | ||
function isAtom(x) { | ||
return x && (x._type === ATOM || x._type === PROXY); | ||
return x && (x._type === ATOM || x._type === LENS); | ||
} | ||
function isDerivation(x) { | ||
return x && (x._type === DERIVATION || x._type === PROXY); | ||
return x && (x._type === DERIVATION || x._type === LENS); | ||
} | ||
function isProxy(x) { | ||
return x && x._type === PROXY; | ||
function isLens(x) { | ||
return x && x._type === LENS; | ||
} | ||
@@ -154,3 +154,5 @@ | ||
function Derivation(deriver) { | ||
function Derivation(deriver, meta) { | ||
if ( meta === void 0 ) meta = null; | ||
this._deriver = deriver; | ||
@@ -163,2 +165,3 @@ this._parents = null; | ||
this._state = DISCONNECTED; | ||
this._meta = meta; | ||
@@ -273,7 +276,7 @@ if (isDebug()) { | ||
function derive(f) { | ||
function derive(f, meta) { | ||
if (typeof f !== "function") { | ||
throw Error("derive requires function"); | ||
} | ||
return new Derivation(f); | ||
return new Derivation(f, meta); | ||
} | ||
@@ -564,3 +567,3 @@ | ||
case DERIVATION: | ||
case PROXY: | ||
case LENS: | ||
if (child._state !== UNKNOWN) { | ||
@@ -736,3 +739,5 @@ child._state = UNKNOWN; | ||
function Atom(value) { | ||
function Atom(value, meta) { | ||
if ( meta === void 0 ) meta = null; | ||
this._id = nextId(); | ||
@@ -744,2 +749,3 @@ this._activeChildren = []; | ||
this._equals = null; | ||
this._meta = meta; | ||
} | ||
@@ -781,15 +787,15 @@ | ||
function atom(value) { | ||
return new Atom(value); | ||
function atom(value, meta) { | ||
return new Atom(value, meta); | ||
} | ||
function Proxy(descriptor) { | ||
Derivation.call(this, descriptor.get); | ||
this._proxyMapping = descriptor; | ||
this._type = PROXY; | ||
function Lens(descriptor, meta) { | ||
Derivation.call(this, descriptor.get, meta); | ||
this._descriptor = descriptor; | ||
this._type = LENS; | ||
} | ||
assign(Proxy.prototype, Derivation.prototype, { | ||
assign(Lens.prototype, Derivation.prototype, { | ||
_clone: function _clone() { | ||
return setEquals(new Proxy(this._proxyMapping), this._equals); | ||
return setEquals(new Lens(this._descriptor), this._equals); | ||
}, | ||
@@ -801,3 +807,3 @@ | ||
atomically(function () { | ||
this$1._proxyMapping.set(value); | ||
this$1._descriptor.set(value); | ||
}); | ||
@@ -807,8 +813,8 @@ } | ||
function proxy(descriptor) { | ||
return new Proxy(descriptor); | ||
function lens(descriptor, meta) { | ||
return new Lens(descriptor, meta); | ||
} | ||
assign(Derivation.prototype, derivablePrototype); | ||
assign(Proxy.prototype, derivablePrototype, mutablePrototype); | ||
assign(Lens.prototype, derivablePrototype, mutablePrototype); | ||
assign(Atom.prototype, derivablePrototype, mutablePrototype); | ||
@@ -824,3 +830,3 @@ | ||
exports.atom = atom; | ||
exports.proxy = proxy; | ||
exports.lens = lens; | ||
exports.derive = derive; | ||
@@ -830,3 +836,3 @@ exports.setDebugMode = setDebugMode; | ||
exports.isAtom = isAtom; | ||
exports.isProxy = isProxy; | ||
exports.isLens = isLens; | ||
exports.isDerivation = isDerivation; | ||
@@ -833,0 +839,0 @@ exports.unpack = unpack; |
@@ -1,6 +0,6 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.Derivable={})}(this,function(t){"use strict";function e(t,e){-1===t.indexOf(e)&&t.push(e)}function n(t){return null!==t&&void 0!==t}function r(){return C}function i(t,e){return t._equals=e,t}function o(t,e,n){return(t._equals||function(t,e){return Object.is(t,e)||t&&"function"==typeof t.equals&&t.equals(e)})(e,n)}function s(t){return t&&(t._type===V||t._type===I||t._type===M)}function a(t,e){P.push({parents:e,offset:0,child:t}),S=t}function u(){P.pop(),S=0===P.length?null:P[P.length-1].child}function f(t){if(null!==S){var n=P[P.length-1];if(n.parents[n.offset]===t)n.offset++;else{var r=n.parents.indexOf(t);if(-1===r)void 0!==S&&e(t._activeChildren,S),n.offset===n.parents.length?n.parents.push(t):(n.parents.push(n.parents[n.offset]),n.parents[n.offset]=t),n.offset++;else if(r>n.offset){var i=n.parents[r];n.parents[r]=n.parents[n.offset],n.parents[n.offset]=i,n.offset++}}}}function c(t){this._deriver=t,this._parents=null,this._type=V,this._value=j,this._equals=null,this._activeChildren=[],this._state=N,r()&&(this.stack=Error().stack)}function h(t,e){if(function(t,e){var n=t.indexOf(e);-1!==n&&t.splice(n,1)}(t._activeChildren,e),0===t._activeChildren.length&&null!=t._parents){for(var n=t._parents.length,r=0;r<n;r++)h(t._parents[r],t);t._parents=null,t._state=N}}function l(t){if("function"!=typeof t)throw Error("derive requires function");return new c(t)}function _(t,e){this._parent=t,this.react=e,this._governor=null,this._active=!1,this._reacting=!1,this._type=L,r()&&(this.stack=Error().stack)}function p(t,e,n){if("function"!=typeof e)throw Error("the first argument to .react must be a function");var r=(n=x({once:!1,skipFirst:!1},n)).skipFirst,i=new _(t,function(t){r?r=!1:(e(t),n.once&&(i.stop(),p.stop()))}),o=function(t,e){if(s(t))return t;if("function"==typeof t)return t;if(void 0===t)return t | ||
;throw Error("react "+e+" condition must be derivable or function, got: "+JSON.stringify(t))},a=function(e,n){return e?"function"==typeof e?e(t):e.get():n},u=o(n.from,"from"),f=o(n.until,"until"),c=o(n.when,"when"),h=!1,p=new _(l(function(){return{from:a(u,!0),until:a(f,!1),when:a(c,!0)}}),function(t){t.from&&(h=!0),h&&(t.until?(i.stop(),p.stop()):t.when?i._active||(i.start(),i.force()):i._active&&i.stop())});p.start(),p.force(),i._governor=p}function v(t){return s(t)?t.get():t}function d(t){if(s(t))return t.get();if(Array.isArray(t))return t.map(d);if(t.constructor===Object){for(var e={},n=Object.keys(t),r=n.length;r--;){var i=n[r];e[i]=d(t[i])}return e}return t}function y(t,e){for(var n=0,r=t._activeChildren.length;n<r;n++){var i=t._activeChildren[n];switch(i._type){case V:case M:i._state!==T&&(i._state=T,y(i,e));break;case L:e.push(i)}}}function g(t){for(var e=0,n=t.length;e<n;e++){var r=t[e];if(r._reacting)throw Error("Synchronous cyclical reactions disallowed. Use setImmediate.");r._maybeReact()}}function w(){return null!==J}function m(t){E();try{t(function(){throw H})}catch(t){if(O(),t!==H)throw t;return}A()}function b(t){w()?t():m(t)}function E(){J=new function(t){this.parent=t,this.id2originalValue={},this.modifiedAtoms=[]}(J)}function A(){var t=J;if(null===(J=t.parent)){var e=[];t.modifiedAtoms.forEach(function(n){o(n,n._value,t.id2originalValue[n._id])?n._state=F:(n._state=B,y(n,e))}),g(e),t.modifiedAtoms.forEach(function(t){t._state=F})}}function O(){var t=J;J=t.parent,t.modifiedAtoms.forEach(function(e){e._value=t.id2originalValue[e._id],e._state=F,y(e,[])})}function k(t){this._id=R++,this._activeChildren=[],this._value=t,this._state=F,this._type=I,this._equals=null}function q(t){return new k(t)}function D(t){c.call(this,t.get),this._proxyMapping=t,this._type=M}var x=Object.assign,R=0,j=Object.freeze({equals:function(){return!1}}),C=!1,I="ATOM",V="DERIVATION",M="PROXY",L="REACTOR",T=0,B=1,F=2,N=3,P=[],S=null;x(c.prototype,{_clone:function(){return i(l(this._deriver),this._equals)}, | ||
_forceEval:function(){var t,e=null;try{if(null===this._parents&&(this._parents=[]),a(this,this._parents),r())try{e=this._deriver()}catch(t){throw console.error(this.stack),t}else e=this._deriver();t=P[P.length-1].offset}finally{u()}this._state=o(this,e,this._value)?F:B;for(var n=t,i=this._parents.length;n<i;n++){h(this._parents[n],this),this._parents[n]=null}this._parents.length=t,this._value=e},_update:function(){if(null===this._parents)this._forceEval();else if(this._state===T){for(var t=this._parents.length,e=0;e<t;e++){var n=this._parents[e];if(n._state===T&&n._update(),n._state===B){this._forceEval();break}}this._state===T&&(this._state=F)}},get:function(){if(f(this),this._activeChildren.length>0)this._update();else{a(void 0,[]);try{this._value=this._deriver()}finally{u()}}return this._value}}),x(_.prototype,{start:function(){this._active=!0,e(this._parent._activeChildren,this),this._parent.get()},_force:function(t){try{this._reacting=!0,this.react(t)}catch(t){throw r()&&console.error(this.stack),t}finally{this._reacting=!1}},force:function(){this._force(this._parent.get())},stop:function(){h(this._parent,this),this._active=!1},_maybeReact:function(){if(!this._reacting&&this._active&&(null!==this._governor&&this._governor._maybeReact(),this._active)){var t=this._parent.get();this._parent._state===B&&this._force(t)}}});var z={derive:function(t){var e=this;if("function"!=typeof t)throw Error("derive requires function");return l(function(){return t(e.get())})},maybeDerive:function(t){var e=this;if("function"!=typeof t)throw Error("maybeDerive requires function");return l(function(){var r=e.get();return n(r)?t(r):null})},orDefault:function(t){if(!n(t))throw Error("orDefault requires non-null value");return this.derive(function(e){return n(e)?e:t})},react:function(t,e){p(this,t,e)},maybeReact:function(t,e){var n=this.derive(Boolean);if(e&&"when"in e&&!0!==e.when){var r=e.when;if("function"==typeof r||!1===r)r=l(r);else if(!s(r))throw new Error("when condition must be bool, function, or derivable") | ||
;n=n.derive(function(t){return t&&r.get()})}p(this,t,x({},e,{when:n}))},is:function(t){var e=this;return l(function(){return o(e,e.get(),v(t))})},withEquality:function(t){if(t){if("function"!=typeof t)throw new Error("equals must be function")}else t=null;return i(this._clone(),t)}},G={update:function(t,e,n,r,i){switch(arguments.length){case 0:throw Error("update method accepts at least 1 argument");case 1:return this.set(t(this.get()));case 2:return this.set(t(this.get(),e));case 3:return this.set(t(this.get(),e,n));case 4:return this.set(t(this.get(),e,n,r));case 5:return this.set(t(this.get(),e,n,r,i));default:throw Error("update method accepts only 5 arguments")}}},H={},J=null,K=0,U="object"==typeof window?window:"object"==typeof global?global:{},X=U.__DERIVABLE_DEVTOOLS_HOOK__;x(k.prototype,{_clone:function(){return i(q(this._value),this._equals)},set:function(t){!function(t){null!==J&&(t._id in J.id2originalValue||(J.modifiedAtoms.push(t),J.id2originalValue[t._id]=t._value))}(this);var e=this._value;if(this._value=t,!w()&&!o(this,t,e))try{this._state=B;var n=[];y(this,n),g(n)}finally{this._state=F}},get:function(){return"function"==typeof X&&X("captureAtom",this),f(this),this._value}}),x(D.prototype,c.prototype,{_clone:function(){return i(new D(this._proxyMapping),this._equals)},set:function(t){var e=this;b(function(){e._proxyMapping.set(t)})}}),x(c.prototype,z),x(D.prototype,z,G),x(k.prototype,z,G),U.__DERIVABLE_INIT_FLAG__&&console.warn("Multiple instances of derivable have been initialized on the same page"),U.__DERIVABLE_INIT_FLAG__=!0,t.atom=q,t.proxy=function(t){return new D(t)},t.derive=l,t.setDebugMode=function(t){C=!!t},t.isDerivable=s,t.isAtom=function(t){return t&&(t._type===I||t._type===M)},t.isProxy=function(t){return t&&t._type===M},t.isDerivation=function(t){return t&&(t._type===V||t._type===M)},t.unpack=v,t.struct=function(t){if(t.constructor===Object||Array.isArray(t))return l(function(){return d(t)});throw new Error("`struct` expects plain Object or Array")},t.transact=m, | ||
t.transaction=function(t){return function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var r;return m(function(){r=t.apply(void 0,e)}),r}},t.ticker=function(){0===K&&E(),K++;var t=!1;return{tick:function(){if(t)throw new Error("trying to use ticker after release");A(),E()},reset:function(){if(t)throw new Error("trying to use ticker after release");O(),E()},release:function(){if(t)throw new Error("ticker already released");t=!0,0==--K&&A()}}},t.atomic=function(t){return function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var r;return b(function(){r=t.apply(void 0,e)}),r}},t.atomically=b,t.__Reactor=_,t.__captureDereferences=function(t){var e=[];a(void 0,e);try{t()}finally{u()}return e},Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.Derivable={})}(this,function(t){"use strict";function e(t,e){-1===t.indexOf(e)&&t.push(e)}function n(t){return null!==t&&void 0!==t}function r(){return I}function i(t,e){return t._equals=e,t}function o(t,e,n){return(t._equals||function(t,e){return Object.is(t,e)||t&&"function"==typeof t.equals&&t.equals(e)})(e,n)}function s(t){return t&&(t._type===L||t._type===V||t._type===x)}function a(t,e){S.push({parents:e,offset:0,child:t}),z=t}function u(){S.pop(),z=0===S.length?null:S[S.length-1].child}function c(t){if(null!==z){var n=S[S.length-1];if(n.parents[n.offset]===t)n.offset++;else{var r=n.parents.indexOf(t);if(-1===r)void 0!==z&&e(t._activeChildren,z),n.offset===n.parents.length?n.parents.push(t):(n.parents.push(n.parents[n.offset]),n.parents[n.offset]=t),n.offset++;else if(r>n.offset){var i=n.parents[r];n.parents[r]=n.parents[n.offset],n.parents[n.offset]=i,n.offset++}}}}function f(t,e){void 0===e&&(e=null),this._deriver=t,this._parents=null,this._type=L,this._value=C,this._equals=null,this._activeChildren=[],this._state=M,this._meta=e,r()&&(this.stack=Error().stack)}function h(t,e){if(function(t,e){var n=t.indexOf(e);-1!==n&&t.splice(n,1)}(t._activeChildren,e),0===t._activeChildren.length&&null!=t._parents){for(var n=t._parents.length,r=0;r<n;r++)h(t._parents[r],t);t._parents=null,t._state=M}}function l(t,e){if("function"!=typeof t)throw Error("derive requires function");return new f(t,e)}function _(t,e){this._parent=t,this.react=e,this._governor=null,this._active=!1,this._reacting=!1,this._type=T,r()&&(this.stack=Error().stack)}function p(t,e,n){if("function"!=typeof e)throw Error("the first argument to .react must be a function");var r=(n=j({once:!1,skipFirst:!1},n)).skipFirst,i=new _(t,function(t){r?r=!1:(e(t),n.once&&(i.stop(),p.stop()))}),o=function(t,e){if(s(t))return t;if("function"==typeof t)return t;if(void 0===t)return t | ||
;throw Error("react "+e+" condition must be derivable or function, got: "+JSON.stringify(t))},a=function(e,n){return e?"function"==typeof e?e(t):e.get():n},u=o(n.from,"from"),c=o(n.until,"until"),f=o(n.when,"when"),h=!1,p=new _(l(function(){return{from:a(u,!0),until:a(c,!1),when:a(f,!0)}}),function(t){t.from&&(h=!0),h&&(t.until?(i.stop(),p.stop()):t.when?i._active||(i.start(),i.force()):i._active&&i.stop())});p.start(),p.force(),i._governor=p}function v(t){return s(t)?t.get():t}function d(t){if(s(t))return t.get();if(Array.isArray(t))return t.map(d);if(t.constructor===Object){for(var e={},n=Object.keys(t),r=n.length;r--;){var i=n[r];e[i]=d(t[i])}return e}return t}function y(t,e){for(var n=0,r=t._activeChildren.length;n<r;n++){var i=t._activeChildren[n];switch(i._type){case L:case x:i._state!==N&&(i._state=N,y(i,e));break;case T:e.push(i)}}}function g(t){for(var e=0,n=t.length;e<n;e++){var r=t[e];if(r._reacting)throw Error("Synchronous cyclical reactions disallowed. Use setImmediate.");r._maybeReact()}}function w(){return null!==K}function m(t){b();try{t(function(){throw J})}catch(t){if(O(),t!==J)throw t;return}A()}function E(t){w()?t():m(t)}function b(){K=new function(t){this.parent=t,this.id2originalValue={},this.modifiedAtoms=[]}(K)}function A(){var t=K;if(null===(K=t.parent)){var e=[];t.modifiedAtoms.forEach(function(n){o(n,n._value,t.id2originalValue[n._id])?n._state=F:(n._state=B,y(n,e))}),g(e),t.modifiedAtoms.forEach(function(t){t._state=F})}}function O(){var t=K;K=t.parent,t.modifiedAtoms.forEach(function(e){e._value=t.id2originalValue[e._id],e._state=F,y(e,[])})}function k(t,e){void 0===e&&(e=null),this._id=R++,this._activeChildren=[],this._value=t,this._state=F,this._type=V,this._equals=null,this._meta=e}function q(t,e){return new k(t,e)}function D(t,e){f.call(this,t.get,e),this._descriptor=t,this._type=x}var j=Object.assign,R=0,C=Object.freeze({equals:function(){return!1}}),I=!1,V="ATOM",L="DERIVATION",x="LENS",T="REACTOR",N=0,B=1,F=2,M=3,S=[],z=null;j(f.prototype,{_clone:function(){ | ||
return i(l(this._deriver),this._equals)},_forceEval:function(){var t,e=null;try{if(null===this._parents&&(this._parents=[]),a(this,this._parents),r())try{e=this._deriver()}catch(t){throw console.error(this.stack),t}else e=this._deriver();t=S[S.length-1].offset}finally{u()}this._state=o(this,e,this._value)?F:B;for(var n=t,i=this._parents.length;n<i;n++){h(this._parents[n],this),this._parents[n]=null}this._parents.length=t,this._value=e},_update:function(){if(null===this._parents)this._forceEval();else if(this._state===N){for(var t=this._parents.length,e=0;e<t;e++){var n=this._parents[e];if(n._state===N&&n._update(),n._state===B){this._forceEval();break}}this._state===N&&(this._state=F)}},get:function(){if(c(this),this._activeChildren.length>0)this._update();else{a(void 0,[]);try{this._value=this._deriver()}finally{u()}}return this._value}}),j(_.prototype,{start:function(){this._active=!0,e(this._parent._activeChildren,this),this._parent.get()},_force:function(t){try{this._reacting=!0,this.react(t)}catch(t){throw r()&&console.error(this.stack),t}finally{this._reacting=!1}},force:function(){this._force(this._parent.get())},stop:function(){h(this._parent,this),this._active=!1},_maybeReact:function(){if(!this._reacting&&this._active&&(null!==this._governor&&this._governor._maybeReact(),this._active)){var t=this._parent.get();this._parent._state===B&&this._force(t)}}});var G={derive:function(t){var e=this;if("function"!=typeof t)throw Error("derive requires function");return l(function(){return t(e.get())})},maybeDerive:function(t){var e=this;if("function"!=typeof t)throw Error("maybeDerive requires function");return l(function(){var r=e.get();return n(r)?t(r):null})},orDefault:function(t){if(!n(t))throw Error("orDefault requires non-null value");return this.derive(function(e){return n(e)?e:t})},react:function(t,e){p(this,t,e)},maybeReact:function(t,e){var n=this.derive(Boolean);if(e&&"when"in e&&!0!==e.when){var r=e.when | ||
;if("function"==typeof r||!1===r)r=l(r);else if(!s(r))throw new Error("when condition must be bool, function, or derivable");n=n.derive(function(t){return t&&r.get()})}p(this,t,j({},e,{when:n}))},is:function(t){var e=this;return l(function(){return o(e,e.get(),v(t))})},withEquality:function(t){if(t){if("function"!=typeof t)throw new Error("equals must be function")}else t=null;return i(this._clone(),t)}},H={update:function(t,e,n,r,i){switch(arguments.length){case 0:throw Error("update method accepts at least 1 argument");case 1:return this.set(t(this.get()));case 2:return this.set(t(this.get(),e));case 3:return this.set(t(this.get(),e,n));case 4:return this.set(t(this.get(),e,n,r));case 5:return this.set(t(this.get(),e,n,r,i));default:throw Error("update method accepts only 5 arguments")}}},J={},K=null,P=0,U="object"==typeof window?window:"object"==typeof global?global:{},Q=U.__DERIVABLE_DEVTOOLS_HOOK__;j(k.prototype,{_clone:function(){return i(q(this._value),this._equals)},set:function(t){!function(t){null!==K&&(t._id in K.id2originalValue||(K.modifiedAtoms.push(t),K.id2originalValue[t._id]=t._value))}(this);var e=this._value;if(this._value=t,!w()&&!o(this,t,e))try{this._state=B;var n=[];y(this,n),g(n)}finally{this._state=F}},get:function(){return"function"==typeof Q&&Q("captureAtom",this),c(this),this._value}}),j(D.prototype,f.prototype,{_clone:function(){return i(new D(this._descriptor),this._equals)},set:function(t){var e=this;E(function(){e._descriptor.set(t)})}}),j(f.prototype,G),j(D.prototype,G,H),j(k.prototype,G,H),U.__DERIVABLE_INIT_FLAG__&&console.warn("Multiple instances of derivable have been initialized on the same page"),U.__DERIVABLE_INIT_FLAG__=!0,t.atom=q,t.lens=function(t,e){return new D(t,e)},t.derive=l,t.setDebugMode=function(t){I=!!t},t.isDerivable=s,t.isAtom=function(t){return t&&(t._type===V||t._type===x)},t.isLens=function(t){return t&&t._type===x},t.isDerivation=function(t){return t&&(t._type===L||t._type===x)},t.unpack=v,t.struct=function(t){ | ||
if(t.constructor===Object||Array.isArray(t))return l(function(){return d(t)});throw new Error("`struct` expects plain Object or Array")},t.transact=m,t.transaction=function(t){return function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var r;return m(function(){r=t.apply(void 0,e)}),r}},t.ticker=function(){0===P&&b(),P++;var t=!1;return{tick:function(){if(t)throw new Error("trying to use ticker after release");A(),b()},reset:function(){if(t)throw new Error("trying to use ticker after release");O(),b()},release:function(){if(t)throw new Error("ticker already released");t=!0,0==--P&&A()}}},t.atomic=function(t){return function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var r;return E(function(){r=t.apply(void 0,e)}),r}},t.atomically=E,t.__Reactor=_,t.__captureDereferences=function(t){var e=[];a(void 0,e);try{t()}finally{u()}return e},Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=derivable.umd.min.js.map |
{ | ||
"name": "derivable", | ||
"version": "2.0.0-beta.2", | ||
"version": "2.0.0-beta.3", | ||
"description": "Functional Reactive State for JavaScript & TypeScript", | ||
@@ -59,3 +59,3 @@ "author": "David Sheldrick", | ||
"mobx": "^2.3.3", | ||
"np": "^2.16.0", | ||
"np": "^2.20.1", | ||
"prettier": "^1.8.2", | ||
@@ -73,3 +73,3 @@ "rollup": "^0.51.6", | ||
}, | ||
"license": "Apache 2.0" | ||
"license": "Apache-2.0" | ||
} |
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
Sorry, the diff of this file is not supported yet
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
318288
2279
0