Comparing version 3.0.12 to 3.0.13
@@ -5,2 +5,7 @@ # Change Log | ||
<a name="3.0.13"></a> | ||
## [3.0.13](https://github.com/zerkalica/lom_atom/compare/v3.0.12...v3.0.13) (2017-12-07) | ||
<a name="3.0.12"></a> | ||
@@ -7,0 +12,0 @@ ## [3.0.12](https://github.com/zerkalica/lom_atom/compare/v3.0.11...v3.0.12) (2017-12-07) |
@@ -141,3 +141,3 @@ function _defineProperties(target, props) { | ||
function disleadThis(master) { | ||
function disleadSlaves(master) { | ||
master.dislead(this); | ||
@@ -152,2 +152,6 @@ } | ||
function deleteMasters(slave) { | ||
slave.removeMaster(this); | ||
} | ||
var Atom = (_temp = _class = | ||
@@ -190,3 +194,3 @@ /*#__PURE__*/ | ||
if (this._masters) { | ||
this._masters.forEach(disleadThis, this); | ||
this._masters.forEach(disleadSlaves, this); | ||
@@ -196,4 +200,9 @@ this._masters = null; | ||
this._checkSlaves(); | ||
if (this._slaves) { | ||
this._slaves.forEach(deleteMasters, this); | ||
this._slaves = null; | ||
} // this._checkSlaves() | ||
this._hostAtoms.delete(this._keyHash || this.owner); | ||
@@ -212,8 +221,2 @@ | ||
_proto.reset = function reset() { | ||
this._suggested = this._next; | ||
this._next = undefined; | ||
this.status = ATOM_STATUS_DEEP_RESET; | ||
}; | ||
_proto.value = function value(next, forceCache) { | ||
@@ -224,3 +227,5 @@ var context = this._context; | ||
if (next === undefined) { | ||
this.reset(); | ||
this._suggested = this._next; | ||
this._next = undefined; | ||
this.status = ATOM_STATUS_DEEP_RESET; | ||
if (this._slaves) this._slaves.forEach(obsoleteSlave); | ||
@@ -285,3 +290,3 @@ } else { | ||
this._push(this._pull()); | ||
this._pullPush(); | ||
@@ -292,5 +297,5 @@ Atom.deepReset = deepReset; | ||
this._push(this._pull()); | ||
this._pullPush(); | ||
} else if (this.status !== ATOM_STATUS_ACTUAL) { | ||
this._push(this._pull()); | ||
this._pullPush(); | ||
} | ||
@@ -300,4 +305,2 @@ }; | ||
_proto._push = function _push(nextRaw) { | ||
if (nextRaw === undefined) return; | ||
if (!(nextRaw instanceof AtomWait)) { | ||
@@ -321,5 +324,5 @@ this._suggested = this._next; | ||
_proto._pull = function _pull() { | ||
_proto._pullPush = function _pullPush() { | ||
if (this._masters) { | ||
this._masters.forEach(disleadThis, this); | ||
this._masters.forEach(disleadSlaves, this); | ||
} | ||
@@ -347,4 +350,3 @@ | ||
context.current = slave; | ||
if (this.status === ATOM_STATUS_DEEP_RESET) return; | ||
return newValue; | ||
if (this.status !== ATOM_STATUS_DEEP_RESET) this._push(newValue); | ||
}; | ||
@@ -357,2 +359,3 @@ | ||
slaves.delete(slave); | ||
slave.removeMaster(this); | ||
@@ -391,2 +394,8 @@ if (slaves.size === 0) { | ||
_proto.removeMaster = function removeMaster(master) { | ||
if (!this._masters) return; | ||
this._masters.delete(master); | ||
}; | ||
_proto.addMaster = function addMaster(master) { | ||
@@ -409,2 +418,82 @@ if (!this._masters) { | ||
function fastCallMethod(host, methodName, args) { | ||
try { | ||
switch (args.length) { | ||
case 0: | ||
return host[methodName](); | ||
case 1: | ||
return host[methodName](args[0]); | ||
case 2: | ||
return host[methodName](args[0], args[1]); | ||
case 3: | ||
return host[methodName](args[0], args[1], args[2]); | ||
case 4: | ||
return host[methodName](args[0], args[1], args[2], args[3]); | ||
case 5: | ||
return host[methodName](args[0], args[1], args[2], args[3], args[4]); | ||
default: | ||
return host[methodName].apply(host, args); | ||
} | ||
} catch (e) { | ||
if (!(e instanceof AtomWait)) throw e; | ||
} | ||
} | ||
function action(host, name, descr, defer) { | ||
var hk = name + "$"; | ||
if (descr.value === undefined) { | ||
throw new TypeError(getId(host, name) + " is not an function (next?: V)"); | ||
} | ||
host[hk] = descr.value; | ||
var definingProperty = false; | ||
var actionId = getId(host, name); | ||
return { | ||
enumerable: descr.enumerable, | ||
configurable: descr.configurable, | ||
get: function get() { | ||
var _this = this; | ||
if (definingProperty) return this[hk].bind(this); | ||
var actionFn = defer ? function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return scheduleNative(function () { | ||
return fastCallMethod(_this, hk, args); | ||
}); | ||
} : function () { | ||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
return fastCallMethod(_this, hk, args); | ||
}; | ||
setFunctionName(actionFn, actionId); | ||
definingProperty = true; | ||
Object.defineProperty(this, name, { | ||
configurable: true, | ||
enumerable: false, | ||
value: actionFn | ||
}); | ||
definingProperty = false; | ||
return actionFn; | ||
} | ||
}; | ||
} | ||
function actionDefer(host, name, descr) { | ||
return action(host, name, descr, true); | ||
} | ||
action.defer = actionDefer; | ||
function reap(atom, key, reaping) { | ||
@@ -575,141 +664,2 @@ reaping.delete(atom); | ||
function createActionMethod(t, name, context) { | ||
var longName = getId(t, name); | ||
function action() { | ||
var result; | ||
var oldNamespace = context.beginTransaction(longName); | ||
var args = arguments; | ||
try { | ||
switch (args.length) { | ||
case 0: | ||
result = t[name](); | ||
break; | ||
case 1: | ||
result = t[name](args[0]); | ||
break; | ||
case 2: | ||
result = t[name](args[0], args[1]); | ||
break; | ||
case 3: | ||
result = t[name](args[0], args[1], args[2]); | ||
break; | ||
case 4: | ||
result = t[name](args[0], args[1], args[2], args[3]); | ||
break; | ||
case 5: | ||
result = t[name](args[0], args[1], args[2], args[3], args[4]); | ||
break; | ||
default: | ||
result = t[name].apply(t, args); | ||
} | ||
} catch (e) { | ||
if (!(e instanceof AtomWait)) throw e; | ||
} finally { | ||
context.endTransaction(oldNamespace); | ||
} | ||
return result; | ||
} | ||
setFunctionName(action, longName); | ||
return action; | ||
} | ||
function createActionFn(fn, rawName, context) { | ||
var name = rawName || fn.displayName || fn.name; | ||
function action() { | ||
var result; | ||
var oldNamespace = context.beginTransaction(name); | ||
var args = arguments; | ||
try { | ||
switch (args.length) { | ||
case 0: | ||
result = fn(); | ||
break; | ||
case 1: | ||
result = fn(args[0]); | ||
break; | ||
case 2: | ||
result = fn(args[0], args[1]); | ||
break; | ||
case 3: | ||
result = fn(args[0], args[1], args[2]); | ||
break; | ||
case 4: | ||
result = fn(args[0], args[1], args[2], args[3]); | ||
break; | ||
case 5: | ||
result = fn(args[0], args[1], args[2], args[3], args[4]); | ||
break; | ||
default: | ||
result = fn.apply(null, args); | ||
} | ||
} catch (e) { | ||
if (!(e instanceof AtomWait)) throw e; | ||
} finally { | ||
context.endTransaction(oldNamespace); | ||
} | ||
return result; | ||
} | ||
setFunctionName(action, name); | ||
return action; | ||
} | ||
function actionMethod(proto, name, descr, context) { | ||
var hk = name + "$"; | ||
if (descr.value === undefined) { | ||
throw new TypeError(getId(proto, name) + " is not an function (next?: V)"); | ||
} | ||
proto[hk] = descr.value; | ||
var definingProperty = false; | ||
return { | ||
enumerable: descr.enumerable, | ||
configurable: descr.configurable, | ||
get: function get() { | ||
if (definingProperty) { | ||
return this[hk].bind(this); | ||
} | ||
var actionFn = createActionMethod(this, hk, context); | ||
definingProperty = true; | ||
Object.defineProperty(this, name, { | ||
configurable: true, | ||
value: actionFn | ||
}); | ||
definingProperty = false; | ||
return actionFn; | ||
} | ||
}; | ||
} | ||
function action() { | ||
var args = arguments; | ||
if (args.length === 3) { | ||
return actionMethod(args[0], args[1], args[2], defaultContext); | ||
} | ||
return createActionFn(args[0], args[1], defaultContext); | ||
} | ||
function detached(proto, name, descr) { | ||
@@ -735,3 +685,3 @@ proto[name + "$"] = descr.value; | ||
if (force) { | ||
atom.status = ATOM_STATUS_OBSOLETE; // atom.reset() | ||
atom.status = ATOM_STATUS_OBSOLETE; | ||
} | ||
@@ -899,41 +849,2 @@ | ||
function defer(proto, name, descr) { | ||
var origFn = descr.value; | ||
if (!origFn) throw new Error('Not a method'); | ||
var definingProperty = false; | ||
function value() { | ||
var _this = this; | ||
if (definingProperty) { | ||
return origFn.bind(this); | ||
} | ||
var fn = function fn() { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
scheduleNative(function () { | ||
return origFn.apply(_this, args); | ||
}); | ||
}; | ||
fn.displayName = name + "#defer"; | ||
definingProperty = true; | ||
Object.defineProperty(this, name, { | ||
configurable: true, | ||
value: fn | ||
}); | ||
definingProperty = false; | ||
return fn; | ||
} | ||
return { | ||
enumerable: descr.enumerable, | ||
configurable: descr.configurable, | ||
get: value | ||
}; | ||
} | ||
function stringToColor(str) { | ||
@@ -990,3 +901,3 @@ var hash = 0; | ||
export { Atom, action, detached, mem, defer, ConsoleLogger, defaultContext, AtomWait }; | ||
export { Atom, action, detached, mem, ConsoleLogger, defaultContext, AtomWait }; | ||
//# sourceMappingURL=lom_atom.es.js.map |
@@ -145,3 +145,3 @@ 'use strict'; | ||
function disleadThis(master) { | ||
function disleadSlaves(master) { | ||
master.dislead(this); | ||
@@ -156,2 +156,6 @@ } | ||
function deleteMasters(slave) { | ||
slave.removeMaster(this); | ||
} | ||
var Atom = (_temp = _class = | ||
@@ -194,3 +198,3 @@ /*#__PURE__*/ | ||
if (this._masters) { | ||
this._masters.forEach(disleadThis, this); | ||
this._masters.forEach(disleadSlaves, this); | ||
@@ -200,4 +204,9 @@ this._masters = null; | ||
this._checkSlaves(); | ||
if (this._slaves) { | ||
this._slaves.forEach(deleteMasters, this); | ||
this._slaves = null; | ||
} // this._checkSlaves() | ||
this._hostAtoms.delete(this._keyHash || this.owner); | ||
@@ -216,8 +225,2 @@ | ||
_proto.reset = function reset() { | ||
this._suggested = this._next; | ||
this._next = undefined; | ||
this.status = ATOM_STATUS_DEEP_RESET; | ||
}; | ||
_proto.value = function value(next, forceCache) { | ||
@@ -228,3 +231,5 @@ var context = this._context; | ||
if (next === undefined) { | ||
this.reset(); | ||
this._suggested = this._next; | ||
this._next = undefined; | ||
this.status = ATOM_STATUS_DEEP_RESET; | ||
if (this._slaves) this._slaves.forEach(obsoleteSlave); | ||
@@ -289,3 +294,3 @@ } else { | ||
this._push(this._pull()); | ||
this._pullPush(); | ||
@@ -296,5 +301,5 @@ Atom.deepReset = deepReset; | ||
this._push(this._pull()); | ||
this._pullPush(); | ||
} else if (this.status !== ATOM_STATUS_ACTUAL) { | ||
this._push(this._pull()); | ||
this._pullPush(); | ||
} | ||
@@ -304,4 +309,2 @@ }; | ||
_proto._push = function _push(nextRaw) { | ||
if (nextRaw === undefined) return; | ||
if (!(nextRaw instanceof AtomWait)) { | ||
@@ -325,5 +328,5 @@ this._suggested = this._next; | ||
_proto._pull = function _pull() { | ||
_proto._pullPush = function _pullPush() { | ||
if (this._masters) { | ||
this._masters.forEach(disleadThis, this); | ||
this._masters.forEach(disleadSlaves, this); | ||
} | ||
@@ -351,4 +354,3 @@ | ||
context.current = slave; | ||
if (this.status === ATOM_STATUS_DEEP_RESET) return; | ||
return newValue; | ||
if (this.status !== ATOM_STATUS_DEEP_RESET) this._push(newValue); | ||
}; | ||
@@ -361,2 +363,3 @@ | ||
slaves.delete(slave); | ||
slave.removeMaster(this); | ||
@@ -395,2 +398,8 @@ if (slaves.size === 0) { | ||
_proto.removeMaster = function removeMaster(master) { | ||
if (!this._masters) return; | ||
this._masters.delete(master); | ||
}; | ||
_proto.addMaster = function addMaster(master) { | ||
@@ -413,2 +422,82 @@ if (!this._masters) { | ||
function fastCallMethod(host, methodName, args) { | ||
try { | ||
switch (args.length) { | ||
case 0: | ||
return host[methodName](); | ||
case 1: | ||
return host[methodName](args[0]); | ||
case 2: | ||
return host[methodName](args[0], args[1]); | ||
case 3: | ||
return host[methodName](args[0], args[1], args[2]); | ||
case 4: | ||
return host[methodName](args[0], args[1], args[2], args[3]); | ||
case 5: | ||
return host[methodName](args[0], args[1], args[2], args[3], args[4]); | ||
default: | ||
return host[methodName].apply(host, args); | ||
} | ||
} catch (e) { | ||
if (!(e instanceof AtomWait)) throw e; | ||
} | ||
} | ||
function action(host, name, descr, defer) { | ||
var hk = name + "$"; | ||
if (descr.value === undefined) { | ||
throw new TypeError(getId(host, name) + " is not an function (next?: V)"); | ||
} | ||
host[hk] = descr.value; | ||
var definingProperty = false; | ||
var actionId = getId(host, name); | ||
return { | ||
enumerable: descr.enumerable, | ||
configurable: descr.configurable, | ||
get: function get() { | ||
var _this = this; | ||
if (definingProperty) return this[hk].bind(this); | ||
var actionFn = defer ? function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return scheduleNative(function () { | ||
return fastCallMethod(_this, hk, args); | ||
}); | ||
} : function () { | ||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
return fastCallMethod(_this, hk, args); | ||
}; | ||
setFunctionName(actionFn, actionId); | ||
definingProperty = true; | ||
Object.defineProperty(this, name, { | ||
configurable: true, | ||
enumerable: false, | ||
value: actionFn | ||
}); | ||
definingProperty = false; | ||
return actionFn; | ||
} | ||
}; | ||
} | ||
function actionDefer(host, name, descr) { | ||
return action(host, name, descr, true); | ||
} | ||
action.defer = actionDefer; | ||
function reap(atom, key, reaping) { | ||
@@ -579,141 +668,2 @@ reaping.delete(atom); | ||
function createActionMethod(t, name, context) { | ||
var longName = getId(t, name); | ||
function action() { | ||
var result; | ||
var oldNamespace = context.beginTransaction(longName); | ||
var args = arguments; | ||
try { | ||
switch (args.length) { | ||
case 0: | ||
result = t[name](); | ||
break; | ||
case 1: | ||
result = t[name](args[0]); | ||
break; | ||
case 2: | ||
result = t[name](args[0], args[1]); | ||
break; | ||
case 3: | ||
result = t[name](args[0], args[1], args[2]); | ||
break; | ||
case 4: | ||
result = t[name](args[0], args[1], args[2], args[3]); | ||
break; | ||
case 5: | ||
result = t[name](args[0], args[1], args[2], args[3], args[4]); | ||
break; | ||
default: | ||
result = t[name].apply(t, args); | ||
} | ||
} catch (e) { | ||
if (!(e instanceof AtomWait)) throw e; | ||
} finally { | ||
context.endTransaction(oldNamespace); | ||
} | ||
return result; | ||
} | ||
setFunctionName(action, longName); | ||
return action; | ||
} | ||
function createActionFn(fn, rawName, context) { | ||
var name = rawName || fn.displayName || fn.name; | ||
function action() { | ||
var result; | ||
var oldNamespace = context.beginTransaction(name); | ||
var args = arguments; | ||
try { | ||
switch (args.length) { | ||
case 0: | ||
result = fn(); | ||
break; | ||
case 1: | ||
result = fn(args[0]); | ||
break; | ||
case 2: | ||
result = fn(args[0], args[1]); | ||
break; | ||
case 3: | ||
result = fn(args[0], args[1], args[2]); | ||
break; | ||
case 4: | ||
result = fn(args[0], args[1], args[2], args[3]); | ||
break; | ||
case 5: | ||
result = fn(args[0], args[1], args[2], args[3], args[4]); | ||
break; | ||
default: | ||
result = fn.apply(null, args); | ||
} | ||
} catch (e) { | ||
if (!(e instanceof AtomWait)) throw e; | ||
} finally { | ||
context.endTransaction(oldNamespace); | ||
} | ||
return result; | ||
} | ||
setFunctionName(action, name); | ||
return action; | ||
} | ||
function actionMethod(proto, name, descr, context) { | ||
var hk = name + "$"; | ||
if (descr.value === undefined) { | ||
throw new TypeError(getId(proto, name) + " is not an function (next?: V)"); | ||
} | ||
proto[hk] = descr.value; | ||
var definingProperty = false; | ||
return { | ||
enumerable: descr.enumerable, | ||
configurable: descr.configurable, | ||
get: function get() { | ||
if (definingProperty) { | ||
return this[hk].bind(this); | ||
} | ||
var actionFn = createActionMethod(this, hk, context); | ||
definingProperty = true; | ||
Object.defineProperty(this, name, { | ||
configurable: true, | ||
value: actionFn | ||
}); | ||
definingProperty = false; | ||
return actionFn; | ||
} | ||
}; | ||
} | ||
function action() { | ||
var args = arguments; | ||
if (args.length === 3) { | ||
return actionMethod(args[0], args[1], args[2], defaultContext); | ||
} | ||
return createActionFn(args[0], args[1], defaultContext); | ||
} | ||
function detached(proto, name, descr) { | ||
@@ -739,3 +689,3 @@ proto[name + "$"] = descr.value; | ||
if (force) { | ||
atom.status = ATOM_STATUS_OBSOLETE; // atom.reset() | ||
atom.status = ATOM_STATUS_OBSOLETE; | ||
} | ||
@@ -903,41 +853,2 @@ | ||
function defer(proto, name, descr) { | ||
var origFn = descr.value; | ||
if (!origFn) throw new Error('Not a method'); | ||
var definingProperty = false; | ||
function value() { | ||
var _this = this; | ||
if (definingProperty) { | ||
return origFn.bind(this); | ||
} | ||
var fn = function fn() { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
scheduleNative(function () { | ||
return origFn.apply(_this, args); | ||
}); | ||
}; | ||
fn.displayName = name + "#defer"; | ||
definingProperty = true; | ||
Object.defineProperty(this, name, { | ||
configurable: true, | ||
value: fn | ||
}); | ||
definingProperty = false; | ||
return fn; | ||
} | ||
return { | ||
enumerable: descr.enumerable, | ||
configurable: descr.configurable, | ||
get: value | ||
}; | ||
} | ||
function stringToColor(str) { | ||
@@ -998,3 +909,2 @@ var hash = 0; | ||
exports.mem = mem; | ||
exports.defer = defer; | ||
exports.ConsoleLogger = ConsoleLogger; | ||
@@ -1001,0 +911,0 @@ exports.defaultContext = defaultContext; |
@@ -147,3 +147,3 @@ (function (global, factory) { | ||
function disleadThis(master) { | ||
function disleadSlaves(master) { | ||
master.dislead(this); | ||
@@ -158,2 +158,6 @@ } | ||
function deleteMasters(slave) { | ||
slave.removeMaster(this); | ||
} | ||
var Atom = (_temp = _class = | ||
@@ -196,3 +200,3 @@ /*#__PURE__*/ | ||
if (this._masters) { | ||
this._masters.forEach(disleadThis, this); | ||
this._masters.forEach(disleadSlaves, this); | ||
@@ -202,4 +206,9 @@ this._masters = null; | ||
this._checkSlaves(); | ||
if (this._slaves) { | ||
this._slaves.forEach(deleteMasters, this); | ||
this._slaves = null; | ||
} // this._checkSlaves() | ||
this._hostAtoms.delete(this._keyHash || this.owner); | ||
@@ -218,8 +227,2 @@ | ||
_proto.reset = function reset() { | ||
this._suggested = this._next; | ||
this._next = undefined; | ||
this.status = ATOM_STATUS_DEEP_RESET; | ||
}; | ||
_proto.value = function value(next, forceCache) { | ||
@@ -230,3 +233,5 @@ var context = this._context; | ||
if (next === undefined) { | ||
this.reset(); | ||
this._suggested = this._next; | ||
this._next = undefined; | ||
this.status = ATOM_STATUS_DEEP_RESET; | ||
if (this._slaves) this._slaves.forEach(obsoleteSlave); | ||
@@ -291,3 +296,3 @@ } else { | ||
this._push(this._pull()); | ||
this._pullPush(); | ||
@@ -298,5 +303,5 @@ Atom.deepReset = deepReset; | ||
this._push(this._pull()); | ||
this._pullPush(); | ||
} else if (this.status !== ATOM_STATUS_ACTUAL) { | ||
this._push(this._pull()); | ||
this._pullPush(); | ||
} | ||
@@ -306,4 +311,2 @@ }; | ||
_proto._push = function _push(nextRaw) { | ||
if (nextRaw === undefined) return; | ||
if (!(nextRaw instanceof AtomWait)) { | ||
@@ -327,5 +330,5 @@ this._suggested = this._next; | ||
_proto._pull = function _pull() { | ||
_proto._pullPush = function _pullPush() { | ||
if (this._masters) { | ||
this._masters.forEach(disleadThis, this); | ||
this._masters.forEach(disleadSlaves, this); | ||
} | ||
@@ -353,4 +356,3 @@ | ||
context.current = slave; | ||
if (this.status === ATOM_STATUS_DEEP_RESET) return; | ||
return newValue; | ||
if (this.status !== ATOM_STATUS_DEEP_RESET) this._push(newValue); | ||
}; | ||
@@ -363,2 +365,3 @@ | ||
slaves.delete(slave); | ||
slave.removeMaster(this); | ||
@@ -397,2 +400,8 @@ if (slaves.size === 0) { | ||
_proto.removeMaster = function removeMaster(master) { | ||
if (!this._masters) return; | ||
this._masters.delete(master); | ||
}; | ||
_proto.addMaster = function addMaster(master) { | ||
@@ -415,2 +424,82 @@ if (!this._masters) { | ||
function fastCallMethod(host, methodName, args) { | ||
try { | ||
switch (args.length) { | ||
case 0: | ||
return host[methodName](); | ||
case 1: | ||
return host[methodName](args[0]); | ||
case 2: | ||
return host[methodName](args[0], args[1]); | ||
case 3: | ||
return host[methodName](args[0], args[1], args[2]); | ||
case 4: | ||
return host[methodName](args[0], args[1], args[2], args[3]); | ||
case 5: | ||
return host[methodName](args[0], args[1], args[2], args[3], args[4]); | ||
default: | ||
return host[methodName].apply(host, args); | ||
} | ||
} catch (e) { | ||
if (!(e instanceof AtomWait)) throw e; | ||
} | ||
} | ||
function action(host, name, descr, defer) { | ||
var hk = name + "$"; | ||
if (descr.value === undefined) { | ||
throw new TypeError(getId(host, name) + " is not an function (next?: V)"); | ||
} | ||
host[hk] = descr.value; | ||
var definingProperty = false; | ||
var actionId = getId(host, name); | ||
return { | ||
enumerable: descr.enumerable, | ||
configurable: descr.configurable, | ||
get: function get() { | ||
var _this = this; | ||
if (definingProperty) return this[hk].bind(this); | ||
var actionFn = defer ? function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return scheduleNative(function () { | ||
return fastCallMethod(_this, hk, args); | ||
}); | ||
} : function () { | ||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
return fastCallMethod(_this, hk, args); | ||
}; | ||
setFunctionName(actionFn, actionId); | ||
definingProperty = true; | ||
Object.defineProperty(this, name, { | ||
configurable: true, | ||
enumerable: false, | ||
value: actionFn | ||
}); | ||
definingProperty = false; | ||
return actionFn; | ||
} | ||
}; | ||
} | ||
function actionDefer(host, name, descr) { | ||
return action(host, name, descr, true); | ||
} | ||
action.defer = actionDefer; | ||
function reap(atom, key, reaping) { | ||
@@ -581,141 +670,2 @@ reaping.delete(atom); | ||
function createActionMethod(t, name, context) { | ||
var longName = getId(t, name); | ||
function action() { | ||
var result; | ||
var oldNamespace = context.beginTransaction(longName); | ||
var args = arguments; | ||
try { | ||
switch (args.length) { | ||
case 0: | ||
result = t[name](); | ||
break; | ||
case 1: | ||
result = t[name](args[0]); | ||
break; | ||
case 2: | ||
result = t[name](args[0], args[1]); | ||
break; | ||
case 3: | ||
result = t[name](args[0], args[1], args[2]); | ||
break; | ||
case 4: | ||
result = t[name](args[0], args[1], args[2], args[3]); | ||
break; | ||
case 5: | ||
result = t[name](args[0], args[1], args[2], args[3], args[4]); | ||
break; | ||
default: | ||
result = t[name].apply(t, args); | ||
} | ||
} catch (e) { | ||
if (!(e instanceof AtomWait)) throw e; | ||
} finally { | ||
context.endTransaction(oldNamespace); | ||
} | ||
return result; | ||
} | ||
setFunctionName(action, longName); | ||
return action; | ||
} | ||
function createActionFn(fn, rawName, context) { | ||
var name = rawName || fn.displayName || fn.name; | ||
function action() { | ||
var result; | ||
var oldNamespace = context.beginTransaction(name); | ||
var args = arguments; | ||
try { | ||
switch (args.length) { | ||
case 0: | ||
result = fn(); | ||
break; | ||
case 1: | ||
result = fn(args[0]); | ||
break; | ||
case 2: | ||
result = fn(args[0], args[1]); | ||
break; | ||
case 3: | ||
result = fn(args[0], args[1], args[2]); | ||
break; | ||
case 4: | ||
result = fn(args[0], args[1], args[2], args[3]); | ||
break; | ||
case 5: | ||
result = fn(args[0], args[1], args[2], args[3], args[4]); | ||
break; | ||
default: | ||
result = fn.apply(null, args); | ||
} | ||
} catch (e) { | ||
if (!(e instanceof AtomWait)) throw e; | ||
} finally { | ||
context.endTransaction(oldNamespace); | ||
} | ||
return result; | ||
} | ||
setFunctionName(action, name); | ||
return action; | ||
} | ||
function actionMethod(proto, name, descr, context) { | ||
var hk = name + "$"; | ||
if (descr.value === undefined) { | ||
throw new TypeError(getId(proto, name) + " is not an function (next?: V)"); | ||
} | ||
proto[hk] = descr.value; | ||
var definingProperty = false; | ||
return { | ||
enumerable: descr.enumerable, | ||
configurable: descr.configurable, | ||
get: function get() { | ||
if (definingProperty) { | ||
return this[hk].bind(this); | ||
} | ||
var actionFn = createActionMethod(this, hk, context); | ||
definingProperty = true; | ||
Object.defineProperty(this, name, { | ||
configurable: true, | ||
value: actionFn | ||
}); | ||
definingProperty = false; | ||
return actionFn; | ||
} | ||
}; | ||
} | ||
function action() { | ||
var args = arguments; | ||
if (args.length === 3) { | ||
return actionMethod(args[0], args[1], args[2], defaultContext); | ||
} | ||
return createActionFn(args[0], args[1], defaultContext); | ||
} | ||
function detached(proto, name, descr) { | ||
@@ -741,3 +691,3 @@ proto[name + "$"] = descr.value; | ||
if (force) { | ||
atom.status = ATOM_STATUS_OBSOLETE; // atom.reset() | ||
atom.status = ATOM_STATUS_OBSOLETE; | ||
} | ||
@@ -905,41 +855,2 @@ | ||
function defer(proto, name, descr) { | ||
var origFn = descr.value; | ||
if (!origFn) throw new Error('Not a method'); | ||
var definingProperty = false; | ||
function value() { | ||
var _this = this; | ||
if (definingProperty) { | ||
return origFn.bind(this); | ||
} | ||
var fn = function fn() { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
scheduleNative(function () { | ||
return origFn.apply(_this, args); | ||
}); | ||
}; | ||
fn.displayName = name + "#defer"; | ||
definingProperty = true; | ||
Object.defineProperty(this, name, { | ||
configurable: true, | ||
value: fn | ||
}); | ||
definingProperty = false; | ||
return fn; | ||
} | ||
return { | ||
enumerable: descr.enumerable, | ||
configurable: descr.configurable, | ||
get: value | ||
}; | ||
} | ||
function stringToColor(str) { | ||
@@ -1000,3 +911,2 @@ var hash = 0; | ||
exports.mem = mem; | ||
exports.defer = defer; | ||
exports.ConsoleLogger = ConsoleLogger; | ||
@@ -1003,0 +913,0 @@ exports.defaultContext = defaultContext; |
{ | ||
"name": "lom_atom", | ||
"version": "3.0.12", | ||
"version": "3.0.13", | ||
"description": "Alternative implementation of eigenmethod mol_atom state management library", | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
@@ -32,3 +32,3 @@ // @flow | ||
function disleadThis(master: IAtomInt) { | ||
function disleadSlaves(master: IAtomInt) { | ||
master.dislead((this: IAtomInt)) | ||
@@ -42,2 +42,7 @@ } | ||
} | ||
function deleteMasters(slave: IAtomInt) { | ||
slave.removeMaster((this: IAtomInt)) | ||
} | ||
export default class Atom<V> implements IAtom<V>, IAtomInt { | ||
@@ -110,6 +115,10 @@ status: IAtomStatus | ||
if (this._masters) { | ||
this._masters.forEach(disleadThis, this) | ||
this._masters.forEach(disleadSlaves, this) | ||
this._masters = null | ||
} | ||
this._checkSlaves() | ||
if (this._slaves) { | ||
this._slaves.forEach(deleteMasters, this) | ||
this._slaves = null | ||
} | ||
// this._checkSlaves() | ||
this._hostAtoms.delete(((this._keyHash || this.owner): any)) | ||
@@ -126,8 +135,2 @@ this._context.destroyHost(this) | ||
reset() { | ||
this._suggested = this._next | ||
this._next = undefined | ||
this.status = ATOM_STATUS_DEEP_RESET | ||
} | ||
value(next?: V | Error, forceCache?: IAtomForce): V { | ||
@@ -137,3 +140,5 @@ const context = this._context | ||
if (next === undefined) { | ||
this.reset() | ||
this._suggested = this._next | ||
this._next = undefined | ||
this.status = ATOM_STATUS_DEEP_RESET | ||
if (this._slaves) this._slaves.forEach(obsoleteSlave) | ||
@@ -198,14 +203,13 @@ } else { | ||
Atom.deepReset = deepReset || new Set() | ||
this._push(this._pull()) | ||
this._pullPush() | ||
Atom.deepReset = deepReset | ||
} else if (deepReset !== undefined && !this.manualReset && !deepReset.has(this)) { | ||
deepReset.add(this) | ||
this._push(this._pull()) | ||
this._pullPush() | ||
} else if (this.status !== ATOM_STATUS_ACTUAL) { | ||
this._push(this._pull()) | ||
this._pullPush() | ||
} | ||
} | ||
_push(nextRaw: V | Error | void): void { | ||
if (nextRaw === undefined) return | ||
_push(nextRaw: V | Error): void { | ||
if (!(nextRaw instanceof AtomWait)) { | ||
@@ -228,5 +232,5 @@ this._suggested = this._next | ||
_pull(): V | Error | void { | ||
_pullPush(): void { | ||
if (this._masters) { | ||
this._masters.forEach(disleadThis, this) | ||
this._masters.forEach(disleadSlaves, this) | ||
} | ||
@@ -255,5 +259,4 @@ let newValue: V | Error | ||
context.current = slave | ||
if (this.status === ATOM_STATUS_DEEP_RESET) return | ||
return newValue | ||
if (this.status !== ATOM_STATUS_DEEP_RESET) this._push(newValue) | ||
} | ||
@@ -265,2 +268,3 @@ | ||
slaves.delete(slave) | ||
slave.removeMaster(this) | ||
if (slaves.size === 0) { | ||
@@ -295,2 +299,7 @@ this._slaves = null | ||
removeMaster(master: IAtomInt) { | ||
if (!this._masters) return | ||
this._masters.delete(master) | ||
} | ||
addMaster(master: IAtomInt) { | ||
@@ -297,0 +306,0 @@ if (!this._masters) { |
// @flow | ||
import type {TypedPropertyDescriptor, IContext} from '../interfaces' | ||
import {getId, setFunctionName, AtomWait} from '../utils' | ||
import {defaultContext} from '../Context' | ||
import {scheduleNative, getId, setFunctionName, AtomWait} from '../utils' | ||
function createActionMethod(t: Object, name: string, context: IContext): (...args: any[]) => any { | ||
const longName = getId(t, name) | ||
function action() { | ||
let result: mixed | void | ||
const oldNamespace = context.beginTransaction(longName) | ||
const args = arguments | ||
try { | ||
switch (args.length) { | ||
case 0: result = t[name](); break | ||
case 1: result = t[name](args[0]); break | ||
case 2: result = t[name](args[0], args[1]); break | ||
case 3: result = t[name](args[0], args[1], args[2]); break | ||
case 4: result = t[name](args[0], args[1], args[2], args[3]); break | ||
case 5: result = t[name](args[0], args[1], args[2], args[3], args[4]); break | ||
default: result = t[name].apply(t, args) | ||
} | ||
} catch(e) { | ||
if (!(e instanceof AtomWait)) throw e | ||
} finally { | ||
context.endTransaction(oldNamespace) | ||
} | ||
type Handler = (...args: any[]) => void | ||
return result | ||
} | ||
setFunctionName(action, longName) | ||
return action | ||
} | ||
function createActionFn<F: Function>(fn: F, rawName?: string, context: IContext): F { | ||
const name = rawName || fn.displayName || fn.name | ||
function action(): any { | ||
let result: mixed | void | ||
const oldNamespace = context.beginTransaction(name) | ||
const args = arguments | ||
try { | ||
switch (args.length) { | ||
case 0: result = fn(); break | ||
case 1: result = fn(args[0]); break | ||
case 2: result = fn(args[0], args[1]); break | ||
case 3: result = fn(args[0], args[1], args[2]); break | ||
case 4: result = fn(args[0], args[1], args[2], args[3]); break | ||
case 5: result = fn(args[0], args[1], args[2], args[3], args[4]); break | ||
default: result = fn.apply(null, args) | ||
} | ||
} catch(e) { | ||
if (!(e instanceof AtomWait)) throw e | ||
} finally { | ||
context.endTransaction(oldNamespace) | ||
function fastCallMethod<Host: Object>(host: Host, methodName: string, args: any[]): void { | ||
try { | ||
switch (args.length) { | ||
case 0: return host[methodName]() | ||
case 1: return host[methodName](args[0]) | ||
case 2: return host[methodName](args[0], args[1]) | ||
case 3: return host[methodName](args[0], args[1], args[2]) | ||
case 4: return host[methodName](args[0], args[1], args[2], args[3]) | ||
case 5: return host[methodName](args[0], args[1], args[2], args[3], args[4]) | ||
default: return host[methodName].apply(host, args) | ||
} | ||
return result | ||
} catch(e) { | ||
if (!(e instanceof AtomWait)) throw e | ||
} | ||
setFunctionName(action, name) | ||
return (action: any) | ||
} | ||
function actionMethod<V: Function>( | ||
proto: Object, | ||
function action<Host: Object, H: Handler>( | ||
host: Host, | ||
name: string, | ||
descr: TypedPropertyDescriptor<V>, | ||
context: IContext | ||
): TypedPropertyDescriptor<V> { | ||
descr: TypedPropertyDescriptor<H>, | ||
defer?: boolean | ||
): TypedPropertyDescriptor<H> { | ||
const hk = `${name}$` | ||
if (descr.value === undefined) { | ||
throw new TypeError(`${getId(proto, name)} is not an function (next?: V)`) | ||
throw new TypeError(`${getId(host, name)} is not an function (next?: V)`) | ||
} | ||
proto[hk] = descr.value | ||
host[hk] = descr.value | ||
let definingProperty = false | ||
const actionId = getId(host, name) | ||
return { | ||
enumerable: descr.enumerable, | ||
configurable: descr.configurable, | ||
get(): V { | ||
if (definingProperty) { | ||
return this[hk].bind(this) | ||
} | ||
const actionFn: Function = createActionMethod(this, hk, context) | ||
get(): H { | ||
if (definingProperty) return this[hk].bind(this) | ||
const actionFn = defer | ||
? (...args: any[]) => scheduleNative(() => fastCallMethod(this, hk, args)) | ||
: (...args: any[]) => fastCallMethod(this, hk, args) | ||
setFunctionName(actionFn, actionId) | ||
definingProperty = true | ||
Object.defineProperty(this, name, { | ||
configurable: true, | ||
enumerable: false, | ||
value: actionFn | ||
@@ -93,3 +58,3 @@ }) | ||
return (actionFn: any) | ||
return ((actionFn: any): H) | ||
} | ||
@@ -99,16 +64,25 @@ } | ||
declare function action<F: Function>(fn: F, name?: string): F | ||
declare function action<V>( | ||
proto: Object, | ||
function actionDefer<Host: Object, H: Handler>( | ||
host: Host, | ||
name: string, | ||
descr: TypedPropertyDescriptor<V> | ||
): TypedPropertyDescriptor<V> | ||
descr: TypedPropertyDescriptor<H> | ||
): TypedPropertyDescriptor<H> { | ||
return action(host, name, descr, true) | ||
} | ||
export default function action() { | ||
const args = arguments | ||
if (args.length === 3) { | ||
return actionMethod(args[0], args[1], args[2], defaultContext) | ||
} | ||
action.defer = actionDefer | ||
return createActionFn(args[0], args[1], defaultContext) | ||
interface IAction { | ||
<Host: Object, H: Handler>( | ||
host: Host, | ||
name: string, | ||
descr: TypedPropertyDescriptor<H> | ||
): TypedPropertyDescriptor<H>; | ||
defer: <Host: Object, H: Handler>( | ||
host: Host, | ||
name: string, | ||
descr: TypedPropertyDescriptor<H> | ||
) => TypedPropertyDescriptor<H>; | ||
} | ||
export default (action: IAction) |
@@ -32,3 +32,2 @@ // @flow | ||
atom.status = ATOM_STATUS_OBSOLETE | ||
// atom.reset() | ||
} | ||
@@ -35,0 +34,0 @@ |
@@ -7,3 +7,2 @@ // @flow | ||
export {default as mem} from './decorators/mem' | ||
export {default as defer} from './decorators/defer' | ||
export {default as ConsoleLogger} from './ConsoleLogger' | ||
@@ -10,0 +9,0 @@ export {defaultContext} from './Context' |
@@ -61,3 +61,2 @@ // @flow | ||
value(v?: V | Error, forceCache?: IAtomForce): V; | ||
reset(): void; | ||
destructor(): void; | ||
@@ -76,2 +75,3 @@ } | ||
dislead(slave: IAtomInt): void; | ||
removeMaster(master: IAtomInt): void; | ||
addMaster(master: IAtomInt): void; | ||
@@ -78,0 +78,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
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
324709
24
3302