Comparing version 3.0.3 to 3.0.4
@@ -5,2 +5,7 @@ # Change Log | ||
<a name="3.0.4"></a> | ||
## [3.0.4](https://github.com/zerkalica/lom_atom/compare/v3.0.3...v3.0.4) (2017-11-29) | ||
<a name="3.0.3"></a> | ||
@@ -7,0 +12,0 @@ ## [3.0.3](https://github.com/zerkalica/lom_atom/compare/v3.0.2...v3.0.3) (2017-11-26) |
@@ -23,5 +23,2 @@ function _defineProperties(target, props) { | ||
var ATOM_FORCE_NONE = 0; | ||
var ATOM_FORCE_CACHE = 1; | ||
var ATOM_FORCE_UPDATE = 2; | ||
var ATOM_STATUS_DESTROYED = 0; | ||
@@ -32,2 +29,3 @@ var ATOM_STATUS_OBSOLETE = 1; | ||
var ATOM_STATUS_ACTUAL = 4; | ||
var ATOM_STATUS_DEEP_RESET = 5; | ||
var catchedId = Symbol('lom_atom_catched'); | ||
@@ -115,2 +113,5 @@ var origId = Symbol('orig_error'); | ||
var _class; | ||
var _temp; | ||
var throwOnAccess = { | ||
@@ -144,6 +145,6 @@ get: function get(target, key) { | ||
var Atom = | ||
var Atom = (_temp = _class = | ||
/*#__PURE__*/ | ||
function () { | ||
function Atom(field, owner, context, hostAtoms, key, keyHash, isComponent) { | ||
function Atom(field, owner, context, hostAtoms, manualReset, key, keyHash, isComponent) { | ||
this._masters = null; | ||
@@ -156,2 +157,3 @@ this._slaves = null; | ||
this.isComponent = isComponent || false; | ||
this.manualReset = manualReset || false; | ||
this._context = context; | ||
@@ -162,3 +164,3 @@ this.current = undefined; | ||
this._hostAtoms = hostAtoms; | ||
this.status = this.current === undefined ? ATOM_STATUS_OBSOLETE : ATOM_STATUS_ACTUAL; | ||
this.status = ATOM_STATUS_OBSOLETE; | ||
} | ||
@@ -203,16 +205,22 @@ | ||
_proto.value = function value(next) { | ||
_proto.reset = function reset() { | ||
this._suggested = this._next; | ||
this._next = undefined; | ||
this.status = ATOM_STATUS_DEEP_RESET; | ||
}; | ||
_proto.value = function value(next, forceCache) { | ||
var context = this._context; | ||
var force = context.force; | ||
if (force === ATOM_FORCE_CACHE) { | ||
this._push(next); | ||
} else { | ||
var normalized; | ||
if (forceCache === true) { | ||
if (next === undefined) { | ||
this.reset(); | ||
if (next !== undefined && (normalized = conform(next, this._suggested, this.isComponent)) !== this._suggested && (this.current instanceof Error || (normalized = conform(next, this.current, this.isComponent)) !== this.current)) { | ||
this._suggested = this._next = normalized; | ||
context.force = force = ATOM_FORCE_UPDATE; | ||
if (this._slaves) { | ||
this._slaves.forEach(obsoleteSlave); | ||
} | ||
} else { | ||
this._push(next); | ||
} | ||
} else { | ||
var slave = context.current; | ||
@@ -230,15 +238,14 @@ | ||
slave.addMaster(this); | ||
} // if (this.isComponent) | ||
} | ||
var normalized; | ||
context.force = context.prevForce; | ||
if (next !== undefined && (normalized = conform(next, this._suggested, this.isComponent)) !== this._suggested && (this.current instanceof Error || (normalized = conform(next, this.current, this.isComponent)) !== this.current)) { | ||
this._suggested = this._next = normalized; | ||
this.status = ATOM_STATUS_DEEP_RESET; | ||
} | ||
if (force === ATOM_FORCE_UPDATE) { | ||
this._push(this._pull()); | ||
} else { | ||
this.actualize(); | ||
} | ||
this.actualize(); | ||
} | ||
context.force = context.prevForce; | ||
return this.current; | ||
@@ -252,4 +259,2 @@ }; | ||
if (this.status === ATOM_STATUS_ACTUAL) return; | ||
if (this.status === ATOM_STATUS_CHECKING) { | ||
@@ -265,4 +270,11 @@ if (this._masters) { | ||
if (this.status !== ATOM_STATUS_ACTUAL) { | ||
if (this.status === ATOM_STATUS_DEEP_RESET) { | ||
var isDeepReset = Atom.isDeepReset; | ||
Atom.isDeepReset = true; | ||
this._push(this._pull()); | ||
Atom.isDeepReset = isDeepReset; | ||
} else if (this.status !== ATOM_STATUS_ACTUAL || Atom.isDeepReset && !this.manualReset) { | ||
this._push(this._pull()); | ||
} | ||
@@ -277,10 +289,4 @@ }; | ||
this.status = ATOM_STATUS_ACTUAL; | ||
var prev = this.current; | ||
if (nextRaw === undefined) { | ||
this.status = ATOM_STATUS_OBSOLETE; | ||
return; | ||
} | ||
this.status = ATOM_STATUS_ACTUAL; | ||
var next = nextRaw instanceof Error ? new Proxy(nextRaw, throwOnAccess) : conform(nextRaw, prev, this.isComponent); | ||
@@ -368,2 +374,4 @@ | ||
if (master.manualReset) this.manualReset = true; | ||
this._masters.add(master); | ||
@@ -379,3 +387,3 @@ }; | ||
return Atom; | ||
}(); | ||
}(), _class.isDeepReset = false, _temp); | ||
@@ -403,4 +411,4 @@ var scheduleNative = typeof requestAnimationFrame === 'function' ? function (handler) { | ||
this.current = null; | ||
this.force = ATOM_FORCE_NONE; | ||
this.prevForce = ATOM_FORCE_NONE; | ||
this.isCacheForce = false; | ||
this.isDeepReset = false; | ||
this._logger = undefined; | ||
@@ -706,3 +714,3 @@ this._updating = []; | ||
if (atom === undefined) { | ||
atom = new Atom(name, this, defaultContext, hostAtoms, undefined, undefined, true); | ||
atom = new Atom(name, this, defaultContext, hostAtoms, false, undefined, undefined, true); | ||
hostAtoms.set(this, atom); | ||
@@ -712,4 +720,3 @@ } | ||
if (force) { | ||
defaultContext.prevForce = defaultContext.force; | ||
defaultContext.force = ATOM_FORCE_UPDATE; | ||
atom.reset(); | ||
} | ||
@@ -739,3 +746,5 @@ | ||
function mem(proto, name, descr) { | ||
var isForceCache = false; | ||
function mem(proto, name, descr, deepReset) { | ||
var handlerKey = name + "$"; | ||
@@ -754,7 +763,9 @@ if (proto[handlerKey] !== undefined) return descr; | ||
if (atom === undefined) { | ||
atom = new Atom(name, this, defaultContext, hostAtoms); | ||
atom = new Atom(name, this, defaultContext, hostAtoms, deepReset); | ||
hostAtoms.set(this, atom); | ||
} | ||
return atom.value(next); | ||
var force = isForceCache; | ||
isForceCache = false; | ||
return atom.value(next, force); | ||
} | ||
@@ -781,2 +792,6 @@ | ||
function memManual(proto, name, descr) { | ||
return mem(proto, name, descr, true); | ||
} | ||
function getKeyFromObj(params) { | ||
@@ -802,3 +817,3 @@ var keys = Object.keys(params).sort(); | ||
function memkey(proto, name, descr) { | ||
function memkey(proto, name, descr, deepReset) { | ||
var longName = getId(proto, name); | ||
@@ -831,7 +846,9 @@ var handler = descr.value; | ||
if (atom === undefined) { | ||
atom = new Atom(name, this, defaultContext, atomMap, rawKey, key); | ||
atom = new Atom(name, this, defaultContext, atomMap, deepReset, rawKey, key); | ||
atomMap.set(key, atom); | ||
} | ||
return atom.value(next); | ||
var force = isForceCache; | ||
isForceCache = false; | ||
return atom.value(next, force); | ||
} | ||
@@ -843,30 +860,36 @@ | ||
var proxyHandler = { | ||
get: function get(obj, key) { | ||
return obj[key + '()']; | ||
} | ||
}; | ||
function toAtom(obj) { | ||
return new Proxy(obj, proxyHandler); | ||
function memkeyManual(proto, name, descr) { | ||
return memkey(proto, name, descr, true); | ||
} | ||
memkey.manual = memkeyManual; | ||
function cache(data) { | ||
defaultContext.prevForce = defaultContext.force; | ||
defaultContext.force = ATOM_FORCE_CACHE; | ||
isForceCache = true; | ||
return data; | ||
} | ||
function force(data) { | ||
defaultContext.prevForce = defaultContext.force; | ||
defaultContext.force = ATOM_FORCE_UPDATE; | ||
return data; | ||
} | ||
function reset(data) {} | ||
mem.cache = cache; | ||
mem.force = force; | ||
mem.key = memkey; | ||
mem.Wait = AtomWait; | ||
mem.toAtom = toAtom; | ||
Object.defineProperties(mem, { | ||
reset: { | ||
get: function get() { | ||
isForceCache = true; | ||
return reset; | ||
} | ||
}, | ||
manual: { | ||
value: memManual | ||
}, | ||
cache: { | ||
value: cache | ||
}, | ||
key: { | ||
value: memkey | ||
}, | ||
Wait: { | ||
value: AtomWait // toAtom: {value: toAtom } | ||
} | ||
}); | ||
function stringToColor(str) { | ||
@@ -873,0 +896,0 @@ var hash = 0; |
@@ -27,5 +27,2 @@ 'use strict'; | ||
var ATOM_FORCE_NONE = 0; | ||
var ATOM_FORCE_CACHE = 1; | ||
var ATOM_FORCE_UPDATE = 2; | ||
var ATOM_STATUS_DESTROYED = 0; | ||
@@ -36,2 +33,3 @@ var ATOM_STATUS_OBSOLETE = 1; | ||
var ATOM_STATUS_ACTUAL = 4; | ||
var ATOM_STATUS_DEEP_RESET = 5; | ||
var catchedId = Symbol('lom_atom_catched'); | ||
@@ -119,2 +117,5 @@ var origId = Symbol('orig_error'); | ||
var _class; | ||
var _temp; | ||
var throwOnAccess = { | ||
@@ -148,6 +149,6 @@ get: function get(target, key) { | ||
var Atom = | ||
var Atom = (_temp = _class = | ||
/*#__PURE__*/ | ||
function () { | ||
function Atom(field, owner, context, hostAtoms, key, keyHash, isComponent) { | ||
function Atom(field, owner, context, hostAtoms, manualReset, key, keyHash, isComponent) { | ||
this._masters = null; | ||
@@ -160,2 +161,3 @@ this._slaves = null; | ||
this.isComponent = isComponent || false; | ||
this.manualReset = manualReset || false; | ||
this._context = context; | ||
@@ -166,3 +168,3 @@ this.current = undefined; | ||
this._hostAtoms = hostAtoms; | ||
this.status = this.current === undefined ? ATOM_STATUS_OBSOLETE : ATOM_STATUS_ACTUAL; | ||
this.status = ATOM_STATUS_OBSOLETE; | ||
} | ||
@@ -207,16 +209,22 @@ | ||
_proto.value = function value(next) { | ||
_proto.reset = function reset() { | ||
this._suggested = this._next; | ||
this._next = undefined; | ||
this.status = ATOM_STATUS_DEEP_RESET; | ||
}; | ||
_proto.value = function value(next, forceCache) { | ||
var context = this._context; | ||
var force = context.force; | ||
if (force === ATOM_FORCE_CACHE) { | ||
this._push(next); | ||
} else { | ||
var normalized; | ||
if (forceCache === true) { | ||
if (next === undefined) { | ||
this.reset(); | ||
if (next !== undefined && (normalized = conform(next, this._suggested, this.isComponent)) !== this._suggested && (this.current instanceof Error || (normalized = conform(next, this.current, this.isComponent)) !== this.current)) { | ||
this._suggested = this._next = normalized; | ||
context.force = force = ATOM_FORCE_UPDATE; | ||
if (this._slaves) { | ||
this._slaves.forEach(obsoleteSlave); | ||
} | ||
} else { | ||
this._push(next); | ||
} | ||
} else { | ||
var slave = context.current; | ||
@@ -234,15 +242,14 @@ | ||
slave.addMaster(this); | ||
} // if (this.isComponent) | ||
} | ||
var normalized; | ||
context.force = context.prevForce; | ||
if (next !== undefined && (normalized = conform(next, this._suggested, this.isComponent)) !== this._suggested && (this.current instanceof Error || (normalized = conform(next, this.current, this.isComponent)) !== this.current)) { | ||
this._suggested = this._next = normalized; | ||
this.status = ATOM_STATUS_DEEP_RESET; | ||
} | ||
if (force === ATOM_FORCE_UPDATE) { | ||
this._push(this._pull()); | ||
} else { | ||
this.actualize(); | ||
} | ||
this.actualize(); | ||
} | ||
context.force = context.prevForce; | ||
return this.current; | ||
@@ -256,4 +263,2 @@ }; | ||
if (this.status === ATOM_STATUS_ACTUAL) return; | ||
if (this.status === ATOM_STATUS_CHECKING) { | ||
@@ -269,4 +274,11 @@ if (this._masters) { | ||
if (this.status !== ATOM_STATUS_ACTUAL) { | ||
if (this.status === ATOM_STATUS_DEEP_RESET) { | ||
var isDeepReset = Atom.isDeepReset; | ||
Atom.isDeepReset = true; | ||
this._push(this._pull()); | ||
Atom.isDeepReset = isDeepReset; | ||
} else if (this.status !== ATOM_STATUS_ACTUAL || Atom.isDeepReset && !this.manualReset) { | ||
this._push(this._pull()); | ||
} | ||
@@ -281,10 +293,4 @@ }; | ||
this.status = ATOM_STATUS_ACTUAL; | ||
var prev = this.current; | ||
if (nextRaw === undefined) { | ||
this.status = ATOM_STATUS_OBSOLETE; | ||
return; | ||
} | ||
this.status = ATOM_STATUS_ACTUAL; | ||
var next = nextRaw instanceof Error ? new Proxy(nextRaw, throwOnAccess) : conform(nextRaw, prev, this.isComponent); | ||
@@ -372,2 +378,4 @@ | ||
if (master.manualReset) this.manualReset = true; | ||
this._masters.add(master); | ||
@@ -383,3 +391,3 @@ }; | ||
return Atom; | ||
}(); | ||
}(), _class.isDeepReset = false, _temp); | ||
@@ -407,4 +415,4 @@ var scheduleNative = typeof requestAnimationFrame === 'function' ? function (handler) { | ||
this.current = null; | ||
this.force = ATOM_FORCE_NONE; | ||
this.prevForce = ATOM_FORCE_NONE; | ||
this.isCacheForce = false; | ||
this.isDeepReset = false; | ||
this._logger = undefined; | ||
@@ -710,3 +718,3 @@ this._updating = []; | ||
if (atom === undefined) { | ||
atom = new Atom(name, this, defaultContext, hostAtoms, undefined, undefined, true); | ||
atom = new Atom(name, this, defaultContext, hostAtoms, false, undefined, undefined, true); | ||
hostAtoms.set(this, atom); | ||
@@ -716,4 +724,3 @@ } | ||
if (force) { | ||
defaultContext.prevForce = defaultContext.force; | ||
defaultContext.force = ATOM_FORCE_UPDATE; | ||
atom.reset(); | ||
} | ||
@@ -743,3 +750,5 @@ | ||
function mem(proto, name, descr) { | ||
var isForceCache = false; | ||
function mem(proto, name, descr, deepReset) { | ||
var handlerKey = name + "$"; | ||
@@ -758,7 +767,9 @@ if (proto[handlerKey] !== undefined) return descr; | ||
if (atom === undefined) { | ||
atom = new Atom(name, this, defaultContext, hostAtoms); | ||
atom = new Atom(name, this, defaultContext, hostAtoms, deepReset); | ||
hostAtoms.set(this, atom); | ||
} | ||
return atom.value(next); | ||
var force = isForceCache; | ||
isForceCache = false; | ||
return atom.value(next, force); | ||
} | ||
@@ -785,2 +796,6 @@ | ||
function memManual(proto, name, descr) { | ||
return mem(proto, name, descr, true); | ||
} | ||
function getKeyFromObj(params) { | ||
@@ -806,3 +821,3 @@ var keys = Object.keys(params).sort(); | ||
function memkey(proto, name, descr) { | ||
function memkey(proto, name, descr, deepReset) { | ||
var longName = getId(proto, name); | ||
@@ -835,7 +850,9 @@ var handler = descr.value; | ||
if (atom === undefined) { | ||
atom = new Atom(name, this, defaultContext, atomMap, rawKey, key); | ||
atom = new Atom(name, this, defaultContext, atomMap, deepReset, rawKey, key); | ||
atomMap.set(key, atom); | ||
} | ||
return atom.value(next); | ||
var force = isForceCache; | ||
isForceCache = false; | ||
return atom.value(next, force); | ||
} | ||
@@ -847,30 +864,36 @@ | ||
var proxyHandler = { | ||
get: function get(obj, key) { | ||
return obj[key + '()']; | ||
} | ||
}; | ||
function toAtom(obj) { | ||
return new Proxy(obj, proxyHandler); | ||
function memkeyManual(proto, name, descr) { | ||
return memkey(proto, name, descr, true); | ||
} | ||
memkey.manual = memkeyManual; | ||
function cache(data) { | ||
defaultContext.prevForce = defaultContext.force; | ||
defaultContext.force = ATOM_FORCE_CACHE; | ||
isForceCache = true; | ||
return data; | ||
} | ||
function force(data) { | ||
defaultContext.prevForce = defaultContext.force; | ||
defaultContext.force = ATOM_FORCE_UPDATE; | ||
return data; | ||
} | ||
function reset(data) {} | ||
mem.cache = cache; | ||
mem.force = force; | ||
mem.key = memkey; | ||
mem.Wait = AtomWait; | ||
mem.toAtom = toAtom; | ||
Object.defineProperties(mem, { | ||
reset: { | ||
get: function get() { | ||
isForceCache = true; | ||
return reset; | ||
} | ||
}, | ||
manual: { | ||
value: memManual | ||
}, | ||
cache: { | ||
value: cache | ||
}, | ||
key: { | ||
value: memkey | ||
}, | ||
Wait: { | ||
value: AtomWait // toAtom: {value: toAtom } | ||
} | ||
}); | ||
function stringToColor(str) { | ||
@@ -877,0 +900,0 @@ var hash = 0; |
@@ -29,5 +29,2 @@ (function (global, factory) { | ||
var ATOM_FORCE_NONE = 0; | ||
var ATOM_FORCE_CACHE = 1; | ||
var ATOM_FORCE_UPDATE = 2; | ||
var ATOM_STATUS_DESTROYED = 0; | ||
@@ -38,2 +35,3 @@ var ATOM_STATUS_OBSOLETE = 1; | ||
var ATOM_STATUS_ACTUAL = 4; | ||
var ATOM_STATUS_DEEP_RESET = 5; | ||
var catchedId = Symbol('lom_atom_catched'); | ||
@@ -121,2 +119,5 @@ var origId = Symbol('orig_error'); | ||
var _class; | ||
var _temp; | ||
var throwOnAccess = { | ||
@@ -150,6 +151,6 @@ get: function get(target, key) { | ||
var Atom = | ||
var Atom = (_temp = _class = | ||
/*#__PURE__*/ | ||
function () { | ||
function Atom(field, owner, context, hostAtoms, key, keyHash, isComponent) { | ||
function Atom(field, owner, context, hostAtoms, manualReset, key, keyHash, isComponent) { | ||
this._masters = null; | ||
@@ -162,2 +163,3 @@ this._slaves = null; | ||
this.isComponent = isComponent || false; | ||
this.manualReset = manualReset || false; | ||
this._context = context; | ||
@@ -168,3 +170,3 @@ this.current = undefined; | ||
this._hostAtoms = hostAtoms; | ||
this.status = this.current === undefined ? ATOM_STATUS_OBSOLETE : ATOM_STATUS_ACTUAL; | ||
this.status = ATOM_STATUS_OBSOLETE; | ||
} | ||
@@ -209,16 +211,22 @@ | ||
_proto.value = function value(next) { | ||
_proto.reset = function reset() { | ||
this._suggested = this._next; | ||
this._next = undefined; | ||
this.status = ATOM_STATUS_DEEP_RESET; | ||
}; | ||
_proto.value = function value(next, forceCache) { | ||
var context = this._context; | ||
var force = context.force; | ||
if (force === ATOM_FORCE_CACHE) { | ||
this._push(next); | ||
} else { | ||
var normalized; | ||
if (forceCache === true) { | ||
if (next === undefined) { | ||
this.reset(); | ||
if (next !== undefined && (normalized = conform(next, this._suggested, this.isComponent)) !== this._suggested && (this.current instanceof Error || (normalized = conform(next, this.current, this.isComponent)) !== this.current)) { | ||
this._suggested = this._next = normalized; | ||
context.force = force = ATOM_FORCE_UPDATE; | ||
if (this._slaves) { | ||
this._slaves.forEach(obsoleteSlave); | ||
} | ||
} else { | ||
this._push(next); | ||
} | ||
} else { | ||
var slave = context.current; | ||
@@ -236,15 +244,14 @@ | ||
slave.addMaster(this); | ||
} // if (this.isComponent) | ||
} | ||
var normalized; | ||
context.force = context.prevForce; | ||
if (next !== undefined && (normalized = conform(next, this._suggested, this.isComponent)) !== this._suggested && (this.current instanceof Error || (normalized = conform(next, this.current, this.isComponent)) !== this.current)) { | ||
this._suggested = this._next = normalized; | ||
this.status = ATOM_STATUS_DEEP_RESET; | ||
} | ||
if (force === ATOM_FORCE_UPDATE) { | ||
this._push(this._pull()); | ||
} else { | ||
this.actualize(); | ||
} | ||
this.actualize(); | ||
} | ||
context.force = context.prevForce; | ||
return this.current; | ||
@@ -258,4 +265,2 @@ }; | ||
if (this.status === ATOM_STATUS_ACTUAL) return; | ||
if (this.status === ATOM_STATUS_CHECKING) { | ||
@@ -271,4 +276,11 @@ if (this._masters) { | ||
if (this.status !== ATOM_STATUS_ACTUAL) { | ||
if (this.status === ATOM_STATUS_DEEP_RESET) { | ||
var isDeepReset = Atom.isDeepReset; | ||
Atom.isDeepReset = true; | ||
this._push(this._pull()); | ||
Atom.isDeepReset = isDeepReset; | ||
} else if (this.status !== ATOM_STATUS_ACTUAL || Atom.isDeepReset && !this.manualReset) { | ||
this._push(this._pull()); | ||
} | ||
@@ -283,10 +295,4 @@ }; | ||
this.status = ATOM_STATUS_ACTUAL; | ||
var prev = this.current; | ||
if (nextRaw === undefined) { | ||
this.status = ATOM_STATUS_OBSOLETE; | ||
return; | ||
} | ||
this.status = ATOM_STATUS_ACTUAL; | ||
var next = nextRaw instanceof Error ? new Proxy(nextRaw, throwOnAccess) : conform(nextRaw, prev, this.isComponent); | ||
@@ -374,2 +380,4 @@ | ||
if (master.manualReset) this.manualReset = true; | ||
this._masters.add(master); | ||
@@ -385,3 +393,3 @@ }; | ||
return Atom; | ||
}(); | ||
}(), _class.isDeepReset = false, _temp); | ||
@@ -409,4 +417,4 @@ var scheduleNative = typeof requestAnimationFrame === 'function' ? function (handler) { | ||
this.current = null; | ||
this.force = ATOM_FORCE_NONE; | ||
this.prevForce = ATOM_FORCE_NONE; | ||
this.isCacheForce = false; | ||
this.isDeepReset = false; | ||
this._logger = undefined; | ||
@@ -712,3 +720,3 @@ this._updating = []; | ||
if (atom === undefined) { | ||
atom = new Atom(name, this, defaultContext, hostAtoms, undefined, undefined, true); | ||
atom = new Atom(name, this, defaultContext, hostAtoms, false, undefined, undefined, true); | ||
hostAtoms.set(this, atom); | ||
@@ -718,4 +726,3 @@ } | ||
if (force) { | ||
defaultContext.prevForce = defaultContext.force; | ||
defaultContext.force = ATOM_FORCE_UPDATE; | ||
atom.reset(); | ||
} | ||
@@ -745,3 +752,5 @@ | ||
function mem(proto, name, descr) { | ||
var isForceCache = false; | ||
function mem(proto, name, descr, deepReset) { | ||
var handlerKey = name + "$"; | ||
@@ -760,7 +769,9 @@ if (proto[handlerKey] !== undefined) return descr; | ||
if (atom === undefined) { | ||
atom = new Atom(name, this, defaultContext, hostAtoms); | ||
atom = new Atom(name, this, defaultContext, hostAtoms, deepReset); | ||
hostAtoms.set(this, atom); | ||
} | ||
return atom.value(next); | ||
var force = isForceCache; | ||
isForceCache = false; | ||
return atom.value(next, force); | ||
} | ||
@@ -787,2 +798,6 @@ | ||
function memManual(proto, name, descr) { | ||
return mem(proto, name, descr, true); | ||
} | ||
function getKeyFromObj(params) { | ||
@@ -808,3 +823,3 @@ var keys = Object.keys(params).sort(); | ||
function memkey(proto, name, descr) { | ||
function memkey(proto, name, descr, deepReset) { | ||
var longName = getId(proto, name); | ||
@@ -837,7 +852,9 @@ var handler = descr.value; | ||
if (atom === undefined) { | ||
atom = new Atom(name, this, defaultContext, atomMap, rawKey, key); | ||
atom = new Atom(name, this, defaultContext, atomMap, deepReset, rawKey, key); | ||
atomMap.set(key, atom); | ||
} | ||
return atom.value(next); | ||
var force = isForceCache; | ||
isForceCache = false; | ||
return atom.value(next, force); | ||
} | ||
@@ -849,30 +866,36 @@ | ||
var proxyHandler = { | ||
get: function get(obj, key) { | ||
return obj[key + '()']; | ||
} | ||
}; | ||
function toAtom(obj) { | ||
return new Proxy(obj, proxyHandler); | ||
function memkeyManual(proto, name, descr) { | ||
return memkey(proto, name, descr, true); | ||
} | ||
memkey.manual = memkeyManual; | ||
function cache(data) { | ||
defaultContext.prevForce = defaultContext.force; | ||
defaultContext.force = ATOM_FORCE_CACHE; | ||
isForceCache = true; | ||
return data; | ||
} | ||
function force(data) { | ||
defaultContext.prevForce = defaultContext.force; | ||
defaultContext.force = ATOM_FORCE_UPDATE; | ||
return data; | ||
} | ||
function reset(data) {} | ||
mem.cache = cache; | ||
mem.force = force; | ||
mem.key = memkey; | ||
mem.Wait = AtomWait; | ||
mem.toAtom = toAtom; | ||
Object.defineProperties(mem, { | ||
reset: { | ||
get: function get() { | ||
isForceCache = true; | ||
return reset; | ||
} | ||
}, | ||
manual: { | ||
value: memManual | ||
}, | ||
cache: { | ||
value: cache | ||
}, | ||
key: { | ||
value: memkey | ||
}, | ||
Wait: { | ||
value: AtomWait // toAtom: {value: toAtom } | ||
} | ||
}); | ||
function stringToColor(str) { | ||
@@ -879,0 +902,0 @@ var hash = 0; |
{ | ||
"name": "lom_atom", | ||
"version": "3.0.3", | ||
"version": "3.0.4", | ||
"description": "Alternative implementation of eigenmethod mol_atom state management library", | ||
@@ -65,8 +65,8 @@ "publishConfig": { | ||
"rimraf": "^2.6.2", | ||
"rollup": "^0.51.5", | ||
"rollup": "^0.52.0", | ||
"rollup-plugin-babel": "^4.0.0-beta.0", | ||
"rollup-plugin-uglify": "^2.0.1", | ||
"standard-version": "^4.2.0", | ||
"uglify-es": "^3.1.9" | ||
"uglify-es": "^3.2.0" | ||
} | ||
} |
@@ -6,7 +6,4 @@ // @flow | ||
origId, | ||
ATOM_FORCE_NONE, | ||
ATOM_FORCE_CACHE, | ||
ATOM_FORCE_UPDATE, | ||
ATOM_STATUS_DESTROYED, | ||
ATOM_STATUS_DEEP_RESET, | ||
ATOM_STATUS_OBSOLETE, ATOM_STATUS_CHECKING, ATOM_STATUS_PULLING, ATOM_STATUS_ACTUAL | ||
@@ -17,3 +14,2 @@ } from './interfaces' | ||
IAtom, | ||
IAtomForce, | ||
IAtomInt, | ||
@@ -49,7 +45,7 @@ IAtomStatus, | ||
function disleadThis(master: IAtomInt) { | ||
master.dislead((this: Atom<*>)) | ||
master.dislead((this: IAtomInt)) | ||
} | ||
function actualizeMaster(master: IAtomInt) { | ||
if ((this: Atom<*>).status === ATOM_STATUS_CHECKING) { | ||
if ((this: IAtom<*>).status === ATOM_STATUS_CHECKING) { | ||
master.actualize() | ||
@@ -76,2 +72,4 @@ } | ||
manualReset: boolean | ||
constructor( | ||
@@ -82,5 +80,6 @@ field: string, | ||
hostAtoms: WeakMap<Object, IAtom<*>> | Map<string, IAtom<*>>, | ||
manualReset?: boolean, | ||
key?: mixed, | ||
keyHash?: string, | ||
isComponent?: boolean, | ||
isComponent?: boolean | ||
) { | ||
@@ -92,2 +91,3 @@ this._keyHash = keyHash | ||
this.isComponent = isComponent || false | ||
this.manualReset = manualReset || false | ||
this._context = context | ||
@@ -98,3 +98,3 @@ this.current = undefined | ||
this._hostAtoms = hostAtoms | ||
this.status = this.current === undefined ? ATOM_STATUS_OBSOLETE : ATOM_STATUS_ACTUAL | ||
this.status = ATOM_STATUS_OBSOLETE | ||
} | ||
@@ -140,8 +140,33 @@ | ||
value(next?: V | Error): V { | ||
reset() { | ||
this._suggested = this._next | ||
this._next = undefined | ||
this.status = ATOM_STATUS_DEEP_RESET | ||
} | ||
static isDeepReset = false | ||
value(next?: V | Error, forceCache?: boolean): V { | ||
const context = this._context | ||
let force = context.force | ||
if (force === ATOM_FORCE_CACHE) { | ||
this._push(next) | ||
if (forceCache === true) { | ||
if (next === undefined) { | ||
this.reset() | ||
if (this._slaves) { | ||
this._slaves.forEach(obsoleteSlave) | ||
} | ||
} else { | ||
this._push(next) | ||
} | ||
} else { | ||
const slave = context.current | ||
if (slave && (!slave.isComponent || !this.isComponent)) { | ||
let slaves = this._slaves | ||
if (!slaves) { | ||
context.unreap(this) | ||
slaves = this._slaves = new Set() | ||
} | ||
slaves.add(slave) | ||
slave.addMaster(this) | ||
} | ||
let normalized: V | Error | ||
@@ -157,24 +182,6 @@ if ( | ||
this._suggested = this._next = normalized | ||
context.force = force = ATOM_FORCE_UPDATE | ||
this.status = ATOM_STATUS_DEEP_RESET | ||
} | ||
const slave = context.current | ||
if (slave && (!slave.isComponent || !this.isComponent)) { | ||
let slaves = this._slaves | ||
if (!slaves) { | ||
context.unreap(this) | ||
slaves = this._slaves = new Set() | ||
} | ||
slaves.add(slave) | ||
slave.addMaster(this) | ||
} | ||
// if (this.isComponent) | ||
context.force = context.prevForce | ||
if (force === ATOM_FORCE_UPDATE) { | ||
this._push(this._pull()) | ||
} else { | ||
this.actualize() | ||
} | ||
this.actualize() | ||
} | ||
context.force = context.prevForce | ||
@@ -188,3 +195,2 @@ return (this.current: any) | ||
} | ||
if (this.status === ATOM_STATUS_ACTUAL) return | ||
@@ -201,8 +207,16 @@ if (this.status === ATOM_STATUS_CHECKING) { | ||
if (this.status !== ATOM_STATUS_ACTUAL) { | ||
if (this.status === ATOM_STATUS_DEEP_RESET) { | ||
const isDeepReset = Atom.isDeepReset | ||
Atom.isDeepReset = true | ||
this._push(this._pull()) | ||
Atom.isDeepReset = isDeepReset | ||
} else if ( | ||
this.status !== ATOM_STATUS_ACTUAL | ||
|| (Atom.isDeepReset && !this.manualReset) | ||
) { | ||
this._push(this._pull()) | ||
} | ||
} | ||
_push(nextRaw?: V | Error): void { | ||
_push(nextRaw: V | Error): void { | ||
if (!(nextRaw instanceof AtomWait)) { | ||
@@ -212,8 +226,4 @@ this._suggested = this._next | ||
} | ||
this.status = ATOM_STATUS_ACTUAL | ||
const prev = this.current | ||
if (nextRaw === undefined) { | ||
this.status = ATOM_STATUS_OBSOLETE | ||
return | ||
} | ||
this.status = ATOM_STATUS_ACTUAL | ||
const next: V | Error = nextRaw instanceof Error | ||
@@ -299,4 +309,5 @@ ? new Proxy(nextRaw, throwOnAccess) | ||
} | ||
if (master.manualReset) this.manualReset = true | ||
this._masters.add(master) | ||
} | ||
} |
// @flow | ||
import type { | ||
IAtomForce, | ||
IAtomInt, | ||
@@ -10,3 +9,3 @@ IAtom, | ||
} from './interfaces' | ||
import {origId, ATOM_FORCE_NONE, ATOM_STATUS_DESTROYED} from './interfaces' | ||
import {origId, ATOM_STATUS_DESTROYED} from './interfaces' | ||
@@ -26,4 +25,4 @@ const scheduleNative: (handler: () => void) => number = typeof requestAnimationFrame === 'function' | ||
current: ?IAtomInt = null | ||
force: IAtomForce = ATOM_FORCE_NONE | ||
prevForce: IAtomForce = ATOM_FORCE_NONE | ||
isCacheForce: boolean = false | ||
isDeepReset: boolean = false | ||
@@ -30,0 +29,0 @@ _logger: ILogger | void = undefined |
// @flow | ||
import type {IAtom, TypedPropertyDescriptor} from './interfaces' | ||
import {ATOM_FORCE_NONE, ATOM_FORCE_CACHE, ATOM_FORCE_UPDATE} from './interfaces' | ||
import Atom from './Atom' | ||
@@ -27,8 +26,7 @@ import {defaultContext} from './Context' | ||
if (atom === undefined) { | ||
atom = new Atom(name, this, defaultContext, hostAtoms, undefined, undefined, true) | ||
atom = new Atom(name, this, defaultContext, hostAtoms, false, undefined, undefined, true) | ||
hostAtoms.set(this, atom) | ||
} | ||
if (force) { | ||
defaultContext.prevForce = defaultContext.force | ||
defaultContext.force = ATOM_FORCE_UPDATE | ||
atom.reset() | ||
} | ||
@@ -35,0 +33,0 @@ |
@@ -27,4 +27,2 @@ // @flow | ||
current: ?IAtomInt; | ||
force: IAtomForce; | ||
prevForce: IAtomForce; | ||
destroyHost(atom: IAtomInt): void; | ||
@@ -40,8 +38,2 @@ newValue<V>(t: IAtom<V>, from?: V | Error, to: V | Error): void; | ||
export const ATOM_FORCE_NONE = 0 | ||
export const ATOM_FORCE_CACHE = 1 | ||
export const ATOM_FORCE_UPDATE = 2 | ||
export type IAtomForce = typeof ATOM_FORCE_CACHE | typeof ATOM_FORCE_UPDATE | typeof ATOM_FORCE_NONE | ||
export const ATOM_STATUS_DESTROYED = 0 | ||
@@ -52,2 +44,3 @@ export const ATOM_STATUS_OBSOLETE = 1 | ||
export const ATOM_STATUS_ACTUAL = 4 | ||
export const ATOM_STATUS_DEEP_RESET = 5 | ||
@@ -64,3 +57,4 @@ export const catchedId = Symbol('lom_atom_catched') | ||
+displayName: string; | ||
value(v?: V | Error): V; | ||
value(v?: V | Error, forceCache?: boolean): V; | ||
reset(): void; | ||
destructor(): void; | ||
@@ -71,5 +65,6 @@ } | ||
isComponent: boolean; | ||
manualReset: boolean; | ||
key: mixed | void; | ||
owner: IAtomOwner; | ||
actualize(): void; | ||
@@ -76,0 +71,0 @@ check(): void; |
101
src/mem.js
// @flow | ||
import type {IAtomForce, TypedPropertyDescriptor, IAtom} from './interfaces' | ||
import {ATOM_FORCE_CACHE, ATOM_FORCE_UPDATE} from './interfaces' | ||
import type {TypedPropertyDescriptor, IAtom} from './interfaces' | ||
import {defaultContext} from './Context' | ||
@@ -29,6 +28,9 @@ import {AtomWait, getId, setFunctionName} from './utils' | ||
function mem<V, P: Object>( | ||
proto: P, | ||
let isForceCache = false | ||
function mem<V>( | ||
proto: Object, | ||
name: string, | ||
descr: TypedPropertyDescriptor<V> | ||
descr: TypedPropertyDescriptor<V>, | ||
deepReset?: boolean | ||
): TypedPropertyDescriptor<V> { | ||
@@ -49,6 +51,9 @@ const handlerKey = `${name}$` | ||
if (atom === undefined) { | ||
atom = new Atom(name, this, defaultContext, hostAtoms) | ||
atom = new Atom(name, this, defaultContext, hostAtoms, deepReset) | ||
hostAtoms.set(this, atom) | ||
} | ||
return atom.value(next) | ||
const force = isForceCache | ||
isForceCache = false | ||
return atom.value(next, force) | ||
} | ||
@@ -78,2 +83,10 @@ if (descr.value !== undefined) { | ||
function memManual<V>( | ||
proto: Object, | ||
name: string, | ||
descr: TypedPropertyDescriptor<V> | ||
) { | ||
return mem(proto, name, descr, true) | ||
} | ||
function getKeyFromObj(params: Object): string { | ||
@@ -101,6 +114,7 @@ const keys = Object.keys(params) | ||
function memkey<V, K, P: Object>( | ||
proto: P, | ||
function memkey<V, K>( | ||
proto: Object, | ||
name: string, | ||
descr: TypedPropertyDescriptor<(k: K, next?: V) => V> | ||
descr: TypedPropertyDescriptor<(k: K, next?: V) => V>, | ||
deepReset?: boolean | ||
): TypedPropertyDescriptor<(k: K, next?: V) => V> { | ||
@@ -129,7 +143,10 @@ const longName = getId(proto, name) | ||
if (atom === undefined) { | ||
atom = new Atom(name, this, defaultContext, atomMap, rawKey, key) | ||
atom = new Atom(name, this, defaultContext, atomMap, deepReset, rawKey, key) | ||
atomMap.set(key, atom) | ||
} | ||
return (atom: IAtom<V>).value(next) | ||
const force = isForceCache | ||
isForceCache = false | ||
return (atom: IAtom<V>).value(next, force) | ||
} | ||
@@ -142,2 +159,11 @@ | ||
function memkeyManual<V, K>( | ||
proto: Object, | ||
name: string, | ||
descr: TypedPropertyDescriptor<(k: K, next?: V) => V> | ||
) { | ||
return memkey(proto, name, descr, true) | ||
} | ||
memkey.manual = memkeyManual | ||
const proxyHandler = { | ||
@@ -155,28 +181,39 @@ get<V: Object, T: $Keys<V>>(obj: V, key: T): IAtom<$ElementType<V, T>> { | ||
function cache<V>(data: V): V { | ||
defaultContext.prevForce = defaultContext.force | ||
defaultContext.force = ATOM_FORCE_CACHE | ||
isForceCache = true | ||
return data | ||
} | ||
function force<V>(data: V): V { | ||
defaultContext.prevForce = defaultContext.force | ||
defaultContext.force = ATOM_FORCE_UPDATE | ||
return data | ||
function reset<V>(data: V): void {} | ||
(Object: any).defineProperties(mem, { | ||
reset: { | ||
get<V>(): (v: V) => void { | ||
isForceCache = true | ||
return reset | ||
} | ||
}, | ||
manual: { value: memManual }, | ||
cache: { value: cache }, | ||
key: { value: memkey }, | ||
Wait: { value: AtomWait } | ||
// toAtom: {value: toAtom } | ||
}) | ||
type IDecorator<V> = (proto: Object, name: string, descr: TypedPropertyDescriptor<V>) => TypedPropertyDescriptor<V>; | ||
type IMemKey = { | ||
<V, K>(proto: Object, name: string, descr: TypedPropertyDescriptor<(k: K, next?: V) => V>): TypedPropertyDescriptor<(k: K, next?: V) => V>; | ||
manual: IDecorator<<V, K>(k: K, next?: V) => V>; | ||
} | ||
mem.cache = cache | ||
mem.force = force | ||
mem.key = memkey | ||
mem.Wait = AtomWait | ||
mem.toAtom = toAtom | ||
type IMem = { | ||
<V>(proto: Object, name: string, descr: TypedPropertyDescriptor<V>): TypedPropertyDescriptor<V>; | ||
manual: IDecorator<*>; | ||
cache<V>(v: V): V; | ||
reset<V>(v: V): void; | ||
type IMem = { | ||
<V, P: Object>(proto: P, name: string, descr: TypedPropertyDescriptor<V>): TypedPropertyDescriptor<V>; | ||
cache: typeof cache; | ||
force: typeof force; | ||
key: typeof memkey; | ||
toAtom: typeof toAtom; | ||
Wait: Class<AtomWait>; | ||
key: IMemKey; | ||
Wait: Class<Error>; | ||
} | ||
export default (mem: IMem) | ||
export default ((mem: any): IMem) |
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
326071
3409