Comparing version 2.0.9 to 2.0.10
@@ -5,2 +5,7 @@ # Change Log | ||
<a name="2.0.10"></a> | ||
## [2.0.10](https://github.com/zerkalica/lom_atom/compare/v2.0.9...v2.0.10) (2017-11-15) | ||
<a name="2.0.9"></a> | ||
@@ -7,0 +12,0 @@ ## [2.0.9](https://github.com/zerkalica/lom_atom/compare/v2.0.8...v2.0.9) (2017-11-06) |
@@ -33,5 +33,7 @@ function _defineProperties(target, props) { | ||
var catchedId = Symbol('lom_atom_catched'); | ||
var origId = Symbol('orig_error'); | ||
var throwOnAccess = { | ||
get: function get(target) { | ||
get: function get(target, key) { | ||
if (key === origId) return target.valueOf(); | ||
throw target.valueOf(); | ||
@@ -97,3 +99,3 @@ }, | ||
}]]); | ||
var done = Symbol('lom_conform_done'); | ||
var processed = new WeakMap(); | ||
function conform(target, source, isComponent, stack) { | ||
@@ -105,4 +107,4 @@ if (stack === void 0) { | ||
if (target === source) return source; | ||
if (isComponent || !target || typeof target !== 'object' || !source || typeof source !== 'object' || target instanceof Error || source instanceof Error || target.constructor !== source.constructor || target[done] !== undefined) return target; | ||
target[done] = true; | ||
if (isComponent || !target || typeof target !== 'object' || !source || typeof source !== 'object' || target instanceof Error || source instanceof Error || target.constructor !== source.constructor || processed.has(target)) return target; | ||
processed.set(target, true); | ||
var conformHandler = handlers.get(target.constructor); | ||
@@ -126,3 +128,2 @@ if (!conformHandler) return target; | ||
function disleadThis(master) { | ||
this; | ||
master.dislead(this); | ||
@@ -132,4 +133,2 @@ } | ||
function actualizeMaster(master) { | ||
this; | ||
if (this.status === ATOM_STATUS_CHECKING) { | ||
@@ -162,5 +161,6 @@ master.actualize(); | ||
_proto.toString = function toString() { | ||
var hc = this.owner.constructor; | ||
var k = this.key; | ||
return this.field + (k ? '(' + (typeof k === 'function' ? k.displayName || k.name : String(k)) + ')' : ''); | ||
var owner = this.owner; | ||
var parent = owner.displayName || owner.constructor.displayName || owner.constructor.name; | ||
return String(parent) + "." + this.field + (k ? '(' + (typeof k === 'function' ? k.displayName || k.name : String(k)) + ')' : ''); | ||
}; | ||
@@ -378,54 +378,2 @@ | ||
var BaseLogger = | ||
/*#__PURE__*/ | ||
function () { | ||
function BaseLogger() {} | ||
var _proto = BaseLogger.prototype; | ||
_proto.create = function create(owner, field, key, namespace) {}; | ||
_proto.onDestruct = function onDestruct(atom, namespace) {}; | ||
_proto.sync = function sync() {}; | ||
_proto.status = function status(_status, atom, namespace) {}; | ||
_proto.error = function error(atom, err, namespace) {}; | ||
_proto.newValue = function newValue(atom, from, to, isActualize, namespace) {}; | ||
return BaseLogger; | ||
}(); | ||
var ConsoleLogger = | ||
/*#__PURE__*/ | ||
function (_BaseLogger) { | ||
_inheritsLoose(ConsoleLogger, _BaseLogger); | ||
function ConsoleLogger() { | ||
return _BaseLogger.apply(this, arguments) || this; | ||
} | ||
var _proto2 = ConsoleLogger.prototype; | ||
_proto2.sync = function sync() { | ||
console.log('sync'); | ||
}; | ||
_proto2.status = function status(_status2, atom, namespace) { | ||
console.log(namespace, _status2, atom.displayName); | ||
}; | ||
_proto2.error = function error(atom, err, namespace) { | ||
console.log(namespace, 'error', atom.displayName, err); | ||
}; | ||
_proto2.newValue = function newValue(atom, from, to, isActualize, namespace) { | ||
console.log(namespace, isActualize ? 'actualize' : 'cacheSet', atom.displayName, 'from', from, 'to', to); | ||
}; | ||
return ConsoleLogger; | ||
}(BaseLogger); | ||
var Context = | ||
@@ -457,11 +405,11 @@ /*#__PURE__*/ | ||
var _proto3 = Context.prototype; | ||
var _proto = Context.prototype; | ||
_proto3.create = function create(atom) { | ||
_proto.create = function create(atom) { | ||
if (this._logger !== undefined) { | ||
return this._logger.create(atom.owner, atom.field, atom.key, this._namespace); | ||
return this._logger.create(atom.owner, atom.field, atom.key); | ||
} | ||
}; | ||
_proto3._destroyValue = function _destroyValue(atom, from) { | ||
_proto._destroyValue = function _destroyValue(atom, from) { | ||
if (this._owners.get(from) === atom) { | ||
@@ -472,3 +420,3 @@ try { | ||
console.error(e); | ||
if (this._logger) this._logger.error(atom, e, this._namespace); | ||
if (this._logger) this._logger.error(atom, e); | ||
} | ||
@@ -480,15 +428,15 @@ | ||
_proto3.destroyHost = function destroyHost(atom) { | ||
_proto.destroyHost = function destroyHost(atom) { | ||
this._destroyValue(atom, atom.current); | ||
if (this._logger !== undefined) { | ||
this._logger.onDestruct(atom, this._namespace); | ||
this._logger.onDestruct(atom); | ||
} | ||
}; | ||
_proto3.setLogger = function setLogger(logger) { | ||
_proto.setLogger = function setLogger(logger) { | ||
this._logger = logger; | ||
}; | ||
_proto3.newValue = function newValue(atom, from, to, isActualize) { | ||
_proto.newValue = function newValue(atom, from, to, isActualize) { | ||
this._destroyValue(atom, from); | ||
@@ -500,9 +448,14 @@ | ||
if (this._logger !== undefined) { | ||
if (to instanceof AtomWait) { | ||
this._logger.status('waiting', atom, this._namespace); | ||
} else if (to instanceof Error) { | ||
this._logger.error(atom, to, this._namespace); | ||
} else { | ||
this._logger.newValue(atom, from instanceof Error ? undefined : from, to, isActualize, this._namespace); | ||
var logger = this._logger; | ||
if (logger !== undefined) { | ||
try { | ||
if (!this._scheduled && this._logger !== undefined) { | ||
this._logger.beginGroup(this._namespace); | ||
} | ||
logger.newValue(atom, from instanceof Error && from[origId] ? from[origId] : from, to instanceof Error && to[origId] ? to[origId] : to, isActualize); | ||
} catch (error) { | ||
console.error(error); | ||
logger.error(atom, error); | ||
} | ||
@@ -512,7 +465,3 @@ } | ||
_proto3.proposeToPull = function proposeToPull(atom) { | ||
if (this._logger !== undefined) { | ||
this._logger.status('proposeToPull', atom, this._namespace); | ||
} | ||
_proto.proposeToPull = function proposeToPull(atom) { | ||
this._updating.push(atom); | ||
@@ -523,7 +472,3 @@ | ||
_proto3.proposeToReap = function proposeToReap(atom) { | ||
if (this._logger !== undefined) { | ||
this._logger.status('proposeToReap', atom, this._namespace); | ||
} | ||
_proto.proposeToReap = function proposeToReap(atom) { | ||
this._reaping.add(atom); | ||
@@ -534,7 +479,7 @@ | ||
_proto3.unreap = function unreap(atom) { | ||
_proto.unreap = function unreap(atom) { | ||
this._reaping.delete(atom); | ||
}; | ||
_proto3._schedule = function _schedule() { | ||
_proto._schedule = function _schedule() { | ||
if (!this._scheduled) { | ||
@@ -546,3 +491,3 @@ scheduleNative(this.__run); | ||
_proto3._run = function _run() { | ||
_proto._run = function _run() { | ||
this._schedule(); | ||
@@ -554,6 +499,2 @@ | ||
if (this._logger !== undefined) { | ||
this._logger.sync(); | ||
} | ||
do { | ||
@@ -582,2 +523,6 @@ var end = updating.length; | ||
if (this._logger !== undefined) { | ||
this._logger.endGroup(); | ||
} | ||
this._scheduled = false; | ||
@@ -587,3 +532,3 @@ this._pendCount = 0; | ||
_proto3.beginTransaction = function beginTransaction(namespace) { | ||
_proto.beginTransaction = function beginTransaction(namespace) { | ||
var result = this._namespace; | ||
@@ -595,3 +540,3 @@ this._namespace = namespace; | ||
_proto3.endTransaction = function endTransaction(prev) { | ||
_proto.endTransaction = function endTransaction(prev) { | ||
this._namespace = prev; | ||
@@ -615,7 +560,7 @@ | ||
function memMethod(proto, rname, descr, isComponent) { | ||
var name = getId(proto, rname); | ||
function memMethod(proto, name, descr, isComponent) { | ||
var longName = getId(proto, name); | ||
if (descr.value === undefined) { | ||
throw new TypeError(name + " is not an function (next?: V)"); | ||
throw new TypeError(longName + " is not an function (next?: V)"); | ||
} | ||
@@ -625,3 +570,3 @@ | ||
var hostAtoms = new WeakMap(); | ||
Object.defineProperty(proto, rname + "()", { | ||
Object.defineProperty(proto, name + "()", { | ||
get: function get() { | ||
@@ -633,7 +578,7 @@ return hostAtoms.get(this); | ||
var forcedFn = function forcedFn(next, force) { | ||
return this[rname](next, force === undefined ? ATOM_FORCE_CACHE : force); | ||
return this[name](next, force === undefined ? ATOM_FORCE_CACHE : force); | ||
}; | ||
setFunctionName(forcedFn, name + "*"); | ||
proto[rname + "*"] = forcedFn; | ||
setFunctionName(forcedFn, longName + "*"); | ||
proto[name + "*"] = forcedFn; | ||
return { | ||
@@ -682,4 +627,3 @@ enumerable: descr.enumerable, | ||
function memProp(proto, rname, descr) { | ||
var name = getId(proto, rname); | ||
function memProp(proto, name, descr) { | ||
var handlerKey = name + "$"; | ||
@@ -691,7 +635,8 @@ | ||
if (descr.initializer) setFunctionName(descr.initializer, name); | ||
if (descr.get) setFunctionName(descr.get, "get#" + name); | ||
if (descr.set) setFunctionName(descr.set, "set#" + name); | ||
var longName = getId(proto, name); | ||
if (descr.initializer) setFunctionName(descr.initializer, longName); | ||
if (descr.get) setFunctionName(descr.get, "get#" + longName); | ||
if (descr.set) setFunctionName(descr.set, "set#" + longName); | ||
var handler = proto[handlerKey] = descr.get === undefined && descr.set === undefined ? createValueHandler(descr.initializer) : createGetSetHandler(descr.get, descr.set); | ||
setFunctionName(handler, name + "()"); | ||
setFunctionName(handler, longName + "()"); | ||
var hostAtoms = new WeakMap(); | ||
@@ -753,8 +698,8 @@ Object.defineProperty(proto, name + "()", { | ||
function memKeyMethod(proto, rname, descr) { | ||
var name = getId(proto, rname); | ||
function memKeyMethod(proto, name, descr) { | ||
var longName = getId(proto, name); | ||
var handler = descr.value; | ||
if (handler === undefined) { | ||
throw new TypeError(name + " is not an function (rawKey: K, next?: V)"); | ||
throw new TypeError(longName + " is not an function (rawKey: K, next?: V)"); | ||
} | ||
@@ -764,3 +709,3 @@ | ||
var hostAtoms = new WeakMap(); | ||
Object.defineProperty(proto, rname + "()", { | ||
Object.defineProperty(proto, name + "()", { | ||
get: function get() { | ||
@@ -772,7 +717,7 @@ return hostAtoms.get(this); | ||
var forcedFn = function forcedFn(rawKey, next, force) { | ||
return this[rname](rawKey, next, force === undefined ? ATOM_FORCE_CACHE : force); | ||
return this[name](rawKey, next, force === undefined ? ATOM_FORCE_CACHE : force); | ||
}; | ||
setFunctionName(forcedFn, name + "*"); | ||
proto[rname + "*"] = forcedFn; | ||
setFunctionName(forcedFn, longName + "*"); | ||
proto[name + "*"] = forcedFn; | ||
return { | ||
@@ -857,8 +802,8 @@ enumerable: descr.enumerable, | ||
function createActionMethod(t, hk, context) { | ||
var name = getId(t, hk); | ||
function createActionMethod(t, name, context) { | ||
var longName = getId(t, name); | ||
function action() { | ||
var result; | ||
var oldNamespace = context.beginTransaction(name); | ||
var oldNamespace = context.beginTransaction(longName); | ||
var args = arguments; | ||
@@ -869,27 +814,27 @@ | ||
case 0: | ||
result = t[hk](); | ||
result = t[name](); | ||
break; | ||
case 1: | ||
result = t[hk](args[0]); | ||
result = t[name](args[0]); | ||
break; | ||
case 2: | ||
result = t[hk](args[0], args[1]); | ||
result = t[name](args[0], args[1]); | ||
break; | ||
case 3: | ||
result = t[hk](args[0], args[1], args[2]); | ||
result = t[name](args[0], args[1], args[2]); | ||
break; | ||
case 4: | ||
result = t[hk](args[0], args[1], args[2], args[3]); | ||
result = t[name](args[0], args[1], args[2], args[3]); | ||
break; | ||
case 5: | ||
result = t[hk](args[0], args[1], args[2], args[3], args[4]); | ||
result = t[name](args[0], args[1], args[2], args[3], args[4]); | ||
break; | ||
default: | ||
result = t[hk].apply(t, args); | ||
result = t[name].apply(t, args); | ||
} | ||
@@ -903,3 +848,3 @@ } finally { | ||
setFunctionName(action, name); | ||
setFunctionName(action, longName); | ||
return action; | ||
@@ -956,7 +901,7 @@ } | ||
function actionMethod(proto, field, descr, context) { | ||
var hk = field + "$"; | ||
function actionMethod(proto, name, descr, context) { | ||
var hk = name + "$"; | ||
if (descr.value === undefined) { | ||
throw new TypeError(field + " is not an function (next?: V)"); | ||
throw new TypeError(getId(proto, name) + " is not an function (next?: V)"); | ||
} | ||
@@ -976,3 +921,3 @@ | ||
var actionFn = createActionMethod(this, hk, context); | ||
Object.defineProperty(this, field, { | ||
Object.defineProperty(this, name, { | ||
configurable: true, | ||
@@ -1011,3 +956,56 @@ value: actionFn | ||
export { Atom, mem, memkey, detached, force, action, defaultContext, BaseLogger, ConsoleLogger, ATOM_FORCE_NONE, ATOM_FORCE_CACHE, ATOM_FORCE_UPDATE }; | ||
function stringToColor(str) { | ||
var hash = 0; | ||
for (var i = 0; i < str.length; i++) { | ||
hash = str.charCodeAt(i) + ((hash << 3) - hash); | ||
} | ||
var color = Math.abs(hash).toString(16).substring(0, 6); | ||
return 'font-weight: bold; color: #' + '000000'.substring(0, 6 - color.length) + color + ';'; | ||
} | ||
var ConsoleLogger = | ||
/*#__PURE__*/ | ||
function () { | ||
function ConsoleLogger(opts) { | ||
this._useColors = opts && opts.useColors !== undefined ? opts.useColors : true; | ||
this._filter = opts ? opts.filter : undefined; | ||
} | ||
var _proto = ConsoleLogger.prototype; | ||
_proto.create = function create(owner, field, key) {}; | ||
_proto.beginGroup = function beginGroup(name) { | ||
console.group(name, 'sync'); | ||
}; | ||
_proto.endGroup = function endGroup() { | ||
console.groupEnd(); | ||
}; | ||
_proto.onDestruct = function onDestruct(atom) { | ||
console.debug(atom.displayName, 'destruct'); | ||
}; | ||
_proto.error = function error(atom, err) {}; | ||
_proto.newValue = function newValue(atom, from, to, isActualize) { | ||
var name = atom.displayName; | ||
var filter = this._filter; | ||
if (filter && !filter.test(name)) return; | ||
if (atom.isComponent) { | ||
console.debug(name, 'rendered'); | ||
} else { | ||
var _useColors = this._useColors; | ||
console[from instanceof Error && !(from instanceof AtomWait) ? 'warn' : to instanceof Error && !(to instanceof AtomWait) ? 'error' : 'log'](_useColors ? '%c' + name : name, _useColors ? stringToColor(name) : '', from instanceof Error ? from.message : from, isActualize ? '➔' : '‣', to instanceof Error ? to.message : to); | ||
} | ||
}; | ||
return ConsoleLogger; | ||
}(); | ||
export { Atom, mem, memkey, detached, force, action, ConsoleLogger, defaultContext, ATOM_FORCE_NONE, ATOM_FORCE_CACHE, ATOM_FORCE_UPDATE }; | ||
//# sourceMappingURL=lom_atom.es.js.map |
@@ -37,5 +37,7 @@ 'use strict'; | ||
var catchedId = Symbol('lom_atom_catched'); | ||
var origId = Symbol('orig_error'); | ||
var throwOnAccess = { | ||
get: function get(target) { | ||
get: function get(target, key) { | ||
if (key === origId) return target.valueOf(); | ||
throw target.valueOf(); | ||
@@ -101,3 +103,3 @@ }, | ||
}]]); | ||
var done = Symbol('lom_conform_done'); | ||
var processed = new WeakMap(); | ||
function conform(target, source, isComponent, stack) { | ||
@@ -109,4 +111,4 @@ if (stack === void 0) { | ||
if (target === source) return source; | ||
if (isComponent || !target || typeof target !== 'object' || !source || typeof source !== 'object' || target instanceof Error || source instanceof Error || target.constructor !== source.constructor || target[done] !== undefined) return target; | ||
target[done] = true; | ||
if (isComponent || !target || typeof target !== 'object' || !source || typeof source !== 'object' || target instanceof Error || source instanceof Error || target.constructor !== source.constructor || processed.has(target)) return target; | ||
processed.set(target, true); | ||
var conformHandler = handlers.get(target.constructor); | ||
@@ -130,3 +132,2 @@ if (!conformHandler) return target; | ||
function disleadThis(master) { | ||
this; | ||
master.dislead(this); | ||
@@ -136,4 +137,2 @@ } | ||
function actualizeMaster(master) { | ||
this; | ||
if (this.status === ATOM_STATUS_CHECKING) { | ||
@@ -166,5 +165,6 @@ master.actualize(); | ||
_proto.toString = function toString() { | ||
var hc = this.owner.constructor; | ||
var k = this.key; | ||
return this.field + (k ? '(' + (typeof k === 'function' ? k.displayName || k.name : String(k)) + ')' : ''); | ||
var owner = this.owner; | ||
var parent = owner.displayName || owner.constructor.displayName || owner.constructor.name; | ||
return String(parent) + "." + this.field + (k ? '(' + (typeof k === 'function' ? k.displayName || k.name : String(k)) + ')' : ''); | ||
}; | ||
@@ -382,54 +382,2 @@ | ||
var BaseLogger = | ||
/*#__PURE__*/ | ||
function () { | ||
function BaseLogger() {} | ||
var _proto = BaseLogger.prototype; | ||
_proto.create = function create(owner, field, key, namespace) {}; | ||
_proto.onDestruct = function onDestruct(atom, namespace) {}; | ||
_proto.sync = function sync() {}; | ||
_proto.status = function status(_status, atom, namespace) {}; | ||
_proto.error = function error(atom, err, namespace) {}; | ||
_proto.newValue = function newValue(atom, from, to, isActualize, namespace) {}; | ||
return BaseLogger; | ||
}(); | ||
var ConsoleLogger = | ||
/*#__PURE__*/ | ||
function (_BaseLogger) { | ||
_inheritsLoose(ConsoleLogger, _BaseLogger); | ||
function ConsoleLogger() { | ||
return _BaseLogger.apply(this, arguments) || this; | ||
} | ||
var _proto2 = ConsoleLogger.prototype; | ||
_proto2.sync = function sync() { | ||
console.log('sync'); | ||
}; | ||
_proto2.status = function status(_status2, atom, namespace) { | ||
console.log(namespace, _status2, atom.displayName); | ||
}; | ||
_proto2.error = function error(atom, err, namespace) { | ||
console.log(namespace, 'error', atom.displayName, err); | ||
}; | ||
_proto2.newValue = function newValue(atom, from, to, isActualize, namespace) { | ||
console.log(namespace, isActualize ? 'actualize' : 'cacheSet', atom.displayName, 'from', from, 'to', to); | ||
}; | ||
return ConsoleLogger; | ||
}(BaseLogger); | ||
var Context = | ||
@@ -461,11 +409,11 @@ /*#__PURE__*/ | ||
var _proto3 = Context.prototype; | ||
var _proto = Context.prototype; | ||
_proto3.create = function create(atom) { | ||
_proto.create = function create(atom) { | ||
if (this._logger !== undefined) { | ||
return this._logger.create(atom.owner, atom.field, atom.key, this._namespace); | ||
return this._logger.create(atom.owner, atom.field, atom.key); | ||
} | ||
}; | ||
_proto3._destroyValue = function _destroyValue(atom, from) { | ||
_proto._destroyValue = function _destroyValue(atom, from) { | ||
if (this._owners.get(from) === atom) { | ||
@@ -476,3 +424,3 @@ try { | ||
console.error(e); | ||
if (this._logger) this._logger.error(atom, e, this._namespace); | ||
if (this._logger) this._logger.error(atom, e); | ||
} | ||
@@ -484,15 +432,15 @@ | ||
_proto3.destroyHost = function destroyHost(atom) { | ||
_proto.destroyHost = function destroyHost(atom) { | ||
this._destroyValue(atom, atom.current); | ||
if (this._logger !== undefined) { | ||
this._logger.onDestruct(atom, this._namespace); | ||
this._logger.onDestruct(atom); | ||
} | ||
}; | ||
_proto3.setLogger = function setLogger(logger) { | ||
_proto.setLogger = function setLogger(logger) { | ||
this._logger = logger; | ||
}; | ||
_proto3.newValue = function newValue(atom, from, to, isActualize) { | ||
_proto.newValue = function newValue(atom, from, to, isActualize) { | ||
this._destroyValue(atom, from); | ||
@@ -504,9 +452,14 @@ | ||
if (this._logger !== undefined) { | ||
if (to instanceof AtomWait) { | ||
this._logger.status('waiting', atom, this._namespace); | ||
} else if (to instanceof Error) { | ||
this._logger.error(atom, to, this._namespace); | ||
} else { | ||
this._logger.newValue(atom, from instanceof Error ? undefined : from, to, isActualize, this._namespace); | ||
var logger = this._logger; | ||
if (logger !== undefined) { | ||
try { | ||
if (!this._scheduled && this._logger !== undefined) { | ||
this._logger.beginGroup(this._namespace); | ||
} | ||
logger.newValue(atom, from instanceof Error && from[origId] ? from[origId] : from, to instanceof Error && to[origId] ? to[origId] : to, isActualize); | ||
} catch (error) { | ||
console.error(error); | ||
logger.error(atom, error); | ||
} | ||
@@ -516,7 +469,3 @@ } | ||
_proto3.proposeToPull = function proposeToPull(atom) { | ||
if (this._logger !== undefined) { | ||
this._logger.status('proposeToPull', atom, this._namespace); | ||
} | ||
_proto.proposeToPull = function proposeToPull(atom) { | ||
this._updating.push(atom); | ||
@@ -527,7 +476,3 @@ | ||
_proto3.proposeToReap = function proposeToReap(atom) { | ||
if (this._logger !== undefined) { | ||
this._logger.status('proposeToReap', atom, this._namespace); | ||
} | ||
_proto.proposeToReap = function proposeToReap(atom) { | ||
this._reaping.add(atom); | ||
@@ -538,7 +483,7 @@ | ||
_proto3.unreap = function unreap(atom) { | ||
_proto.unreap = function unreap(atom) { | ||
this._reaping.delete(atom); | ||
}; | ||
_proto3._schedule = function _schedule() { | ||
_proto._schedule = function _schedule() { | ||
if (!this._scheduled) { | ||
@@ -550,3 +495,3 @@ scheduleNative(this.__run); | ||
_proto3._run = function _run() { | ||
_proto._run = function _run() { | ||
this._schedule(); | ||
@@ -558,6 +503,2 @@ | ||
if (this._logger !== undefined) { | ||
this._logger.sync(); | ||
} | ||
do { | ||
@@ -586,2 +527,6 @@ var end = updating.length; | ||
if (this._logger !== undefined) { | ||
this._logger.endGroup(); | ||
} | ||
this._scheduled = false; | ||
@@ -591,3 +536,3 @@ this._pendCount = 0; | ||
_proto3.beginTransaction = function beginTransaction(namespace) { | ||
_proto.beginTransaction = function beginTransaction(namespace) { | ||
var result = this._namespace; | ||
@@ -599,3 +544,3 @@ this._namespace = namespace; | ||
_proto3.endTransaction = function endTransaction(prev) { | ||
_proto.endTransaction = function endTransaction(prev) { | ||
this._namespace = prev; | ||
@@ -619,7 +564,7 @@ | ||
function memMethod(proto, rname, descr, isComponent) { | ||
var name = getId(proto, rname); | ||
function memMethod(proto, name, descr, isComponent) { | ||
var longName = getId(proto, name); | ||
if (descr.value === undefined) { | ||
throw new TypeError(name + " is not an function (next?: V)"); | ||
throw new TypeError(longName + " is not an function (next?: V)"); | ||
} | ||
@@ -629,3 +574,3 @@ | ||
var hostAtoms = new WeakMap(); | ||
Object.defineProperty(proto, rname + "()", { | ||
Object.defineProperty(proto, name + "()", { | ||
get: function get() { | ||
@@ -637,7 +582,7 @@ return hostAtoms.get(this); | ||
var forcedFn = function forcedFn(next, force) { | ||
return this[rname](next, force === undefined ? ATOM_FORCE_CACHE : force); | ||
return this[name](next, force === undefined ? ATOM_FORCE_CACHE : force); | ||
}; | ||
setFunctionName(forcedFn, name + "*"); | ||
proto[rname + "*"] = forcedFn; | ||
setFunctionName(forcedFn, longName + "*"); | ||
proto[name + "*"] = forcedFn; | ||
return { | ||
@@ -686,4 +631,3 @@ enumerable: descr.enumerable, | ||
function memProp(proto, rname, descr) { | ||
var name = getId(proto, rname); | ||
function memProp(proto, name, descr) { | ||
var handlerKey = name + "$"; | ||
@@ -695,7 +639,8 @@ | ||
if (descr.initializer) setFunctionName(descr.initializer, name); | ||
if (descr.get) setFunctionName(descr.get, "get#" + name); | ||
if (descr.set) setFunctionName(descr.set, "set#" + name); | ||
var longName = getId(proto, name); | ||
if (descr.initializer) setFunctionName(descr.initializer, longName); | ||
if (descr.get) setFunctionName(descr.get, "get#" + longName); | ||
if (descr.set) setFunctionName(descr.set, "set#" + longName); | ||
var handler = proto[handlerKey] = descr.get === undefined && descr.set === undefined ? createValueHandler(descr.initializer) : createGetSetHandler(descr.get, descr.set); | ||
setFunctionName(handler, name + "()"); | ||
setFunctionName(handler, longName + "()"); | ||
var hostAtoms = new WeakMap(); | ||
@@ -757,8 +702,8 @@ Object.defineProperty(proto, name + "()", { | ||
function memKeyMethod(proto, rname, descr) { | ||
var name = getId(proto, rname); | ||
function memKeyMethod(proto, name, descr) { | ||
var longName = getId(proto, name); | ||
var handler = descr.value; | ||
if (handler === undefined) { | ||
throw new TypeError(name + " is not an function (rawKey: K, next?: V)"); | ||
throw new TypeError(longName + " is not an function (rawKey: K, next?: V)"); | ||
} | ||
@@ -768,3 +713,3 @@ | ||
var hostAtoms = new WeakMap(); | ||
Object.defineProperty(proto, rname + "()", { | ||
Object.defineProperty(proto, name + "()", { | ||
get: function get() { | ||
@@ -776,7 +721,7 @@ return hostAtoms.get(this); | ||
var forcedFn = function forcedFn(rawKey, next, force) { | ||
return this[rname](rawKey, next, force === undefined ? ATOM_FORCE_CACHE : force); | ||
return this[name](rawKey, next, force === undefined ? ATOM_FORCE_CACHE : force); | ||
}; | ||
setFunctionName(forcedFn, name + "*"); | ||
proto[rname + "*"] = forcedFn; | ||
setFunctionName(forcedFn, longName + "*"); | ||
proto[name + "*"] = forcedFn; | ||
return { | ||
@@ -861,8 +806,8 @@ enumerable: descr.enumerable, | ||
function createActionMethod(t, hk, context) { | ||
var name = getId(t, hk); | ||
function createActionMethod(t, name, context) { | ||
var longName = getId(t, name); | ||
function action() { | ||
var result; | ||
var oldNamespace = context.beginTransaction(name); | ||
var oldNamespace = context.beginTransaction(longName); | ||
var args = arguments; | ||
@@ -873,27 +818,27 @@ | ||
case 0: | ||
result = t[hk](); | ||
result = t[name](); | ||
break; | ||
case 1: | ||
result = t[hk](args[0]); | ||
result = t[name](args[0]); | ||
break; | ||
case 2: | ||
result = t[hk](args[0], args[1]); | ||
result = t[name](args[0], args[1]); | ||
break; | ||
case 3: | ||
result = t[hk](args[0], args[1], args[2]); | ||
result = t[name](args[0], args[1], args[2]); | ||
break; | ||
case 4: | ||
result = t[hk](args[0], args[1], args[2], args[3]); | ||
result = t[name](args[0], args[1], args[2], args[3]); | ||
break; | ||
case 5: | ||
result = t[hk](args[0], args[1], args[2], args[3], args[4]); | ||
result = t[name](args[0], args[1], args[2], args[3], args[4]); | ||
break; | ||
default: | ||
result = t[hk].apply(t, args); | ||
result = t[name].apply(t, args); | ||
} | ||
@@ -907,3 +852,3 @@ } finally { | ||
setFunctionName(action, name); | ||
setFunctionName(action, longName); | ||
return action; | ||
@@ -960,7 +905,7 @@ } | ||
function actionMethod(proto, field, descr, context) { | ||
var hk = field + "$"; | ||
function actionMethod(proto, name, descr, context) { | ||
var hk = name + "$"; | ||
if (descr.value === undefined) { | ||
throw new TypeError(field + " is not an function (next?: V)"); | ||
throw new TypeError(getId(proto, name) + " is not an function (next?: V)"); | ||
} | ||
@@ -980,3 +925,3 @@ | ||
var actionFn = createActionMethod(this, hk, context); | ||
Object.defineProperty(this, field, { | ||
Object.defineProperty(this, name, { | ||
configurable: true, | ||
@@ -1015,2 +960,55 @@ value: actionFn | ||
function stringToColor(str) { | ||
var hash = 0; | ||
for (var i = 0; i < str.length; i++) { | ||
hash = str.charCodeAt(i) + ((hash << 3) - hash); | ||
} | ||
var color = Math.abs(hash).toString(16).substring(0, 6); | ||
return 'font-weight: bold; color: #' + '000000'.substring(0, 6 - color.length) + color + ';'; | ||
} | ||
var ConsoleLogger = | ||
/*#__PURE__*/ | ||
function () { | ||
function ConsoleLogger(opts) { | ||
this._useColors = opts && opts.useColors !== undefined ? opts.useColors : true; | ||
this._filter = opts ? opts.filter : undefined; | ||
} | ||
var _proto = ConsoleLogger.prototype; | ||
_proto.create = function create(owner, field, key) {}; | ||
_proto.beginGroup = function beginGroup(name) { | ||
console.group(name, 'sync'); | ||
}; | ||
_proto.endGroup = function endGroup() { | ||
console.groupEnd(); | ||
}; | ||
_proto.onDestruct = function onDestruct(atom) { | ||
console.debug(atom.displayName, 'destruct'); | ||
}; | ||
_proto.error = function error(atom, err) {}; | ||
_proto.newValue = function newValue(atom, from, to, isActualize) { | ||
var name = atom.displayName; | ||
var filter = this._filter; | ||
if (filter && !filter.test(name)) return; | ||
if (atom.isComponent) { | ||
console.debug(name, 'rendered'); | ||
} else { | ||
var _useColors = this._useColors; | ||
console[from instanceof Error && !(from instanceof AtomWait) ? 'warn' : to instanceof Error && !(to instanceof AtomWait) ? 'error' : 'log'](_useColors ? '%c' + name : name, _useColors ? stringToColor(name) : '', from instanceof Error ? from.message : from, isActualize ? '➔' : '‣', to instanceof Error ? to.message : to); | ||
} | ||
}; | ||
return ConsoleLogger; | ||
}(); | ||
exports.Atom = Atom; | ||
@@ -1022,5 +1020,4 @@ exports.mem = mem; | ||
exports.action = action; | ||
exports.ConsoleLogger = ConsoleLogger; | ||
exports.defaultContext = defaultContext; | ||
exports.BaseLogger = BaseLogger; | ||
exports.ConsoleLogger = ConsoleLogger; | ||
exports.ATOM_FORCE_NONE = ATOM_FORCE_NONE; | ||
@@ -1027,0 +1024,0 @@ exports.ATOM_FORCE_CACHE = ATOM_FORCE_CACHE; |
@@ -39,5 +39,7 @@ (function (global, factory) { | ||
var catchedId = Symbol('lom_atom_catched'); | ||
var origId = Symbol('orig_error'); | ||
var throwOnAccess = { | ||
get: function get(target) { | ||
get: function get(target, key) { | ||
if (key === origId) return target.valueOf(); | ||
throw target.valueOf(); | ||
@@ -103,3 +105,3 @@ }, | ||
}]]); | ||
var done = Symbol('lom_conform_done'); | ||
var processed = new WeakMap(); | ||
function conform(target, source, isComponent, stack) { | ||
@@ -111,4 +113,4 @@ if (stack === void 0) { | ||
if (target === source) return source; | ||
if (isComponent || !target || typeof target !== 'object' || !source || typeof source !== 'object' || target instanceof Error || source instanceof Error || target.constructor !== source.constructor || target[done] !== undefined) return target; | ||
target[done] = true; | ||
if (isComponent || !target || typeof target !== 'object' || !source || typeof source !== 'object' || target instanceof Error || source instanceof Error || target.constructor !== source.constructor || processed.has(target)) return target; | ||
processed.set(target, true); | ||
var conformHandler = handlers.get(target.constructor); | ||
@@ -132,3 +134,2 @@ if (!conformHandler) return target; | ||
function disleadThis(master) { | ||
this; | ||
master.dislead(this); | ||
@@ -138,4 +139,2 @@ } | ||
function actualizeMaster(master) { | ||
this; | ||
if (this.status === ATOM_STATUS_CHECKING) { | ||
@@ -168,5 +167,6 @@ master.actualize(); | ||
_proto.toString = function toString() { | ||
var hc = this.owner.constructor; | ||
var k = this.key; | ||
return this.field + (k ? '(' + (typeof k === 'function' ? k.displayName || k.name : String(k)) + ')' : ''); | ||
var owner = this.owner; | ||
var parent = owner.displayName || owner.constructor.displayName || owner.constructor.name; | ||
return String(parent) + "." + this.field + (k ? '(' + (typeof k === 'function' ? k.displayName || k.name : String(k)) + ')' : ''); | ||
}; | ||
@@ -384,54 +384,2 @@ | ||
var BaseLogger = | ||
/*#__PURE__*/ | ||
function () { | ||
function BaseLogger() {} | ||
var _proto = BaseLogger.prototype; | ||
_proto.create = function create(owner, field, key, namespace) {}; | ||
_proto.onDestruct = function onDestruct(atom, namespace) {}; | ||
_proto.sync = function sync() {}; | ||
_proto.status = function status(_status, atom, namespace) {}; | ||
_proto.error = function error(atom, err, namespace) {}; | ||
_proto.newValue = function newValue(atom, from, to, isActualize, namespace) {}; | ||
return BaseLogger; | ||
}(); | ||
var ConsoleLogger = | ||
/*#__PURE__*/ | ||
function (_BaseLogger) { | ||
_inheritsLoose(ConsoleLogger, _BaseLogger); | ||
function ConsoleLogger() { | ||
return _BaseLogger.apply(this, arguments) || this; | ||
} | ||
var _proto2 = ConsoleLogger.prototype; | ||
_proto2.sync = function sync() { | ||
console.log('sync'); | ||
}; | ||
_proto2.status = function status(_status2, atom, namespace) { | ||
console.log(namespace, _status2, atom.displayName); | ||
}; | ||
_proto2.error = function error(atom, err, namespace) { | ||
console.log(namespace, 'error', atom.displayName, err); | ||
}; | ||
_proto2.newValue = function newValue(atom, from, to, isActualize, namespace) { | ||
console.log(namespace, isActualize ? 'actualize' : 'cacheSet', atom.displayName, 'from', from, 'to', to); | ||
}; | ||
return ConsoleLogger; | ||
}(BaseLogger); | ||
var Context = | ||
@@ -463,11 +411,11 @@ /*#__PURE__*/ | ||
var _proto3 = Context.prototype; | ||
var _proto = Context.prototype; | ||
_proto3.create = function create(atom) { | ||
_proto.create = function create(atom) { | ||
if (this._logger !== undefined) { | ||
return this._logger.create(atom.owner, atom.field, atom.key, this._namespace); | ||
return this._logger.create(atom.owner, atom.field, atom.key); | ||
} | ||
}; | ||
_proto3._destroyValue = function _destroyValue(atom, from) { | ||
_proto._destroyValue = function _destroyValue(atom, from) { | ||
if (this._owners.get(from) === atom) { | ||
@@ -478,3 +426,3 @@ try { | ||
console.error(e); | ||
if (this._logger) this._logger.error(atom, e, this._namespace); | ||
if (this._logger) this._logger.error(atom, e); | ||
} | ||
@@ -486,15 +434,15 @@ | ||
_proto3.destroyHost = function destroyHost(atom) { | ||
_proto.destroyHost = function destroyHost(atom) { | ||
this._destroyValue(atom, atom.current); | ||
if (this._logger !== undefined) { | ||
this._logger.onDestruct(atom, this._namespace); | ||
this._logger.onDestruct(atom); | ||
} | ||
}; | ||
_proto3.setLogger = function setLogger(logger) { | ||
_proto.setLogger = function setLogger(logger) { | ||
this._logger = logger; | ||
}; | ||
_proto3.newValue = function newValue(atom, from, to, isActualize) { | ||
_proto.newValue = function newValue(atom, from, to, isActualize) { | ||
this._destroyValue(atom, from); | ||
@@ -506,9 +454,14 @@ | ||
if (this._logger !== undefined) { | ||
if (to instanceof AtomWait) { | ||
this._logger.status('waiting', atom, this._namespace); | ||
} else if (to instanceof Error) { | ||
this._logger.error(atom, to, this._namespace); | ||
} else { | ||
this._logger.newValue(atom, from instanceof Error ? undefined : from, to, isActualize, this._namespace); | ||
var logger = this._logger; | ||
if (logger !== undefined) { | ||
try { | ||
if (!this._scheduled && this._logger !== undefined) { | ||
this._logger.beginGroup(this._namespace); | ||
} | ||
logger.newValue(atom, from instanceof Error && from[origId] ? from[origId] : from, to instanceof Error && to[origId] ? to[origId] : to, isActualize); | ||
} catch (error) { | ||
console.error(error); | ||
logger.error(atom, error); | ||
} | ||
@@ -518,7 +471,3 @@ } | ||
_proto3.proposeToPull = function proposeToPull(atom) { | ||
if (this._logger !== undefined) { | ||
this._logger.status('proposeToPull', atom, this._namespace); | ||
} | ||
_proto.proposeToPull = function proposeToPull(atom) { | ||
this._updating.push(atom); | ||
@@ -529,7 +478,3 @@ | ||
_proto3.proposeToReap = function proposeToReap(atom) { | ||
if (this._logger !== undefined) { | ||
this._logger.status('proposeToReap', atom, this._namespace); | ||
} | ||
_proto.proposeToReap = function proposeToReap(atom) { | ||
this._reaping.add(atom); | ||
@@ -540,7 +485,7 @@ | ||
_proto3.unreap = function unreap(atom) { | ||
_proto.unreap = function unreap(atom) { | ||
this._reaping.delete(atom); | ||
}; | ||
_proto3._schedule = function _schedule() { | ||
_proto._schedule = function _schedule() { | ||
if (!this._scheduled) { | ||
@@ -552,3 +497,3 @@ scheduleNative(this.__run); | ||
_proto3._run = function _run() { | ||
_proto._run = function _run() { | ||
this._schedule(); | ||
@@ -560,6 +505,2 @@ | ||
if (this._logger !== undefined) { | ||
this._logger.sync(); | ||
} | ||
do { | ||
@@ -588,2 +529,6 @@ var end = updating.length; | ||
if (this._logger !== undefined) { | ||
this._logger.endGroup(); | ||
} | ||
this._scheduled = false; | ||
@@ -593,3 +538,3 @@ this._pendCount = 0; | ||
_proto3.beginTransaction = function beginTransaction(namespace) { | ||
_proto.beginTransaction = function beginTransaction(namespace) { | ||
var result = this._namespace; | ||
@@ -601,3 +546,3 @@ this._namespace = namespace; | ||
_proto3.endTransaction = function endTransaction(prev) { | ||
_proto.endTransaction = function endTransaction(prev) { | ||
this._namespace = prev; | ||
@@ -621,7 +566,7 @@ | ||
function memMethod(proto, rname, descr, isComponent) { | ||
var name = getId(proto, rname); | ||
function memMethod(proto, name, descr, isComponent) { | ||
var longName = getId(proto, name); | ||
if (descr.value === undefined) { | ||
throw new TypeError(name + " is not an function (next?: V)"); | ||
throw new TypeError(longName + " is not an function (next?: V)"); | ||
} | ||
@@ -631,3 +576,3 @@ | ||
var hostAtoms = new WeakMap(); | ||
Object.defineProperty(proto, rname + "()", { | ||
Object.defineProperty(proto, name + "()", { | ||
get: function get() { | ||
@@ -639,7 +584,7 @@ return hostAtoms.get(this); | ||
var forcedFn = function forcedFn(next, force) { | ||
return this[rname](next, force === undefined ? ATOM_FORCE_CACHE : force); | ||
return this[name](next, force === undefined ? ATOM_FORCE_CACHE : force); | ||
}; | ||
setFunctionName(forcedFn, name + "*"); | ||
proto[rname + "*"] = forcedFn; | ||
setFunctionName(forcedFn, longName + "*"); | ||
proto[name + "*"] = forcedFn; | ||
return { | ||
@@ -688,4 +633,3 @@ enumerable: descr.enumerable, | ||
function memProp(proto, rname, descr) { | ||
var name = getId(proto, rname); | ||
function memProp(proto, name, descr) { | ||
var handlerKey = name + "$"; | ||
@@ -697,7 +641,8 @@ | ||
if (descr.initializer) setFunctionName(descr.initializer, name); | ||
if (descr.get) setFunctionName(descr.get, "get#" + name); | ||
if (descr.set) setFunctionName(descr.set, "set#" + name); | ||
var longName = getId(proto, name); | ||
if (descr.initializer) setFunctionName(descr.initializer, longName); | ||
if (descr.get) setFunctionName(descr.get, "get#" + longName); | ||
if (descr.set) setFunctionName(descr.set, "set#" + longName); | ||
var handler = proto[handlerKey] = descr.get === undefined && descr.set === undefined ? createValueHandler(descr.initializer) : createGetSetHandler(descr.get, descr.set); | ||
setFunctionName(handler, name + "()"); | ||
setFunctionName(handler, longName + "()"); | ||
var hostAtoms = new WeakMap(); | ||
@@ -759,8 +704,8 @@ Object.defineProperty(proto, name + "()", { | ||
function memKeyMethod(proto, rname, descr) { | ||
var name = getId(proto, rname); | ||
function memKeyMethod(proto, name, descr) { | ||
var longName = getId(proto, name); | ||
var handler = descr.value; | ||
if (handler === undefined) { | ||
throw new TypeError(name + " is not an function (rawKey: K, next?: V)"); | ||
throw new TypeError(longName + " is not an function (rawKey: K, next?: V)"); | ||
} | ||
@@ -770,3 +715,3 @@ | ||
var hostAtoms = new WeakMap(); | ||
Object.defineProperty(proto, rname + "()", { | ||
Object.defineProperty(proto, name + "()", { | ||
get: function get() { | ||
@@ -778,7 +723,7 @@ return hostAtoms.get(this); | ||
var forcedFn = function forcedFn(rawKey, next, force) { | ||
return this[rname](rawKey, next, force === undefined ? ATOM_FORCE_CACHE : force); | ||
return this[name](rawKey, next, force === undefined ? ATOM_FORCE_CACHE : force); | ||
}; | ||
setFunctionName(forcedFn, name + "*"); | ||
proto[rname + "*"] = forcedFn; | ||
setFunctionName(forcedFn, longName + "*"); | ||
proto[name + "*"] = forcedFn; | ||
return { | ||
@@ -863,8 +808,8 @@ enumerable: descr.enumerable, | ||
function createActionMethod(t, hk, context) { | ||
var name = getId(t, hk); | ||
function createActionMethod(t, name, context) { | ||
var longName = getId(t, name); | ||
function action() { | ||
var result; | ||
var oldNamespace = context.beginTransaction(name); | ||
var oldNamespace = context.beginTransaction(longName); | ||
var args = arguments; | ||
@@ -875,27 +820,27 @@ | ||
case 0: | ||
result = t[hk](); | ||
result = t[name](); | ||
break; | ||
case 1: | ||
result = t[hk](args[0]); | ||
result = t[name](args[0]); | ||
break; | ||
case 2: | ||
result = t[hk](args[0], args[1]); | ||
result = t[name](args[0], args[1]); | ||
break; | ||
case 3: | ||
result = t[hk](args[0], args[1], args[2]); | ||
result = t[name](args[0], args[1], args[2]); | ||
break; | ||
case 4: | ||
result = t[hk](args[0], args[1], args[2], args[3]); | ||
result = t[name](args[0], args[1], args[2], args[3]); | ||
break; | ||
case 5: | ||
result = t[hk](args[0], args[1], args[2], args[3], args[4]); | ||
result = t[name](args[0], args[1], args[2], args[3], args[4]); | ||
break; | ||
default: | ||
result = t[hk].apply(t, args); | ||
result = t[name].apply(t, args); | ||
} | ||
@@ -909,3 +854,3 @@ } finally { | ||
setFunctionName(action, name); | ||
setFunctionName(action, longName); | ||
return action; | ||
@@ -962,7 +907,7 @@ } | ||
function actionMethod(proto, field, descr, context) { | ||
var hk = field + "$"; | ||
function actionMethod(proto, name, descr, context) { | ||
var hk = name + "$"; | ||
if (descr.value === undefined) { | ||
throw new TypeError(field + " is not an function (next?: V)"); | ||
throw new TypeError(getId(proto, name) + " is not an function (next?: V)"); | ||
} | ||
@@ -982,3 +927,3 @@ | ||
var actionFn = createActionMethod(this, hk, context); | ||
Object.defineProperty(this, field, { | ||
Object.defineProperty(this, name, { | ||
configurable: true, | ||
@@ -1017,2 +962,55 @@ value: actionFn | ||
function stringToColor(str) { | ||
var hash = 0; | ||
for (var i = 0; i < str.length; i++) { | ||
hash = str.charCodeAt(i) + ((hash << 3) - hash); | ||
} | ||
var color = Math.abs(hash).toString(16).substring(0, 6); | ||
return 'font-weight: bold; color: #' + '000000'.substring(0, 6 - color.length) + color + ';'; | ||
} | ||
var ConsoleLogger = | ||
/*#__PURE__*/ | ||
function () { | ||
function ConsoleLogger(opts) { | ||
this._useColors = opts && opts.useColors !== undefined ? opts.useColors : true; | ||
this._filter = opts ? opts.filter : undefined; | ||
} | ||
var _proto = ConsoleLogger.prototype; | ||
_proto.create = function create(owner, field, key) {}; | ||
_proto.beginGroup = function beginGroup(name) { | ||
console.group(name, 'sync'); | ||
}; | ||
_proto.endGroup = function endGroup() { | ||
console.groupEnd(); | ||
}; | ||
_proto.onDestruct = function onDestruct(atom) { | ||
console.debug(atom.displayName, 'destruct'); | ||
}; | ||
_proto.error = function error(atom, err) {}; | ||
_proto.newValue = function newValue(atom, from, to, isActualize) { | ||
var name = atom.displayName; | ||
var filter = this._filter; | ||
if (filter && !filter.test(name)) return; | ||
if (atom.isComponent) { | ||
console.debug(name, 'rendered'); | ||
} else { | ||
var _useColors = this._useColors; | ||
console[from instanceof Error && !(from instanceof AtomWait) ? 'warn' : to instanceof Error && !(to instanceof AtomWait) ? 'error' : 'log'](_useColors ? '%c' + name : name, _useColors ? stringToColor(name) : '', from instanceof Error ? from.message : from, isActualize ? '➔' : '‣', to instanceof Error ? to.message : to); | ||
} | ||
}; | ||
return ConsoleLogger; | ||
}(); | ||
exports.Atom = Atom; | ||
@@ -1024,5 +1022,4 @@ exports.mem = mem; | ||
exports.action = action; | ||
exports.ConsoleLogger = ConsoleLogger; | ||
exports.defaultContext = defaultContext; | ||
exports.BaseLogger = BaseLogger; | ||
exports.ConsoleLogger = ConsoleLogger; | ||
exports.ATOM_FORCE_NONE = ATOM_FORCE_NONE; | ||
@@ -1029,0 +1026,0 @@ exports.ATOM_FORCE_CACHE = ATOM_FORCE_CACHE; |
{ | ||
"name": "lom_atom", | ||
"version": "2.0.9", | ||
"version": "2.0.10", | ||
"description": "Alternative implementation of eigenmethod mol_atom state management library", | ||
@@ -54,19 +54,19 @@ "publishConfig": { | ||
"devDependencies": { | ||
"@babel/core": "^7.0.0-beta.31", | ||
"@babel/plugin-external-helpers": "^7.0.0-beta.31", | ||
"@babel/plugin-proposal-class-properties": "^7.0.0-beta.31", | ||
"@babel/plugin-proposal-decorators": "^7.0.0-beta.31", | ||
"@babel/plugin-transform-flow-strip-types": "^7.0.0-beta.31", | ||
"@babel/preset-es2015": "^7.0.0-beta.31", | ||
"@babel/register": "^7.0.0-beta.31", | ||
"@babel/core": "^7.0.0-beta.32", | ||
"@babel/plugin-external-helpers": "^7.0.0-beta.32", | ||
"@babel/plugin-proposal-class-properties": "^7.0.0-beta.32", | ||
"@babel/plugin-proposal-decorators": "^7.0.0-beta.32", | ||
"@babel/plugin-transform-flow-strip-types": "^7.0.0-beta.32", | ||
"@babel/preset-es2015": "^7.0.0-beta.32", | ||
"@babel/register": "^7.0.0-beta.32", | ||
"chokidar-cli": "^1.2.0", | ||
"flow-bin": "^0.58.0", | ||
"flow-bin": "^0.59.0", | ||
"mocha": "^4.0.1", | ||
"rimraf": "^2.6.2", | ||
"rollup": "^0.48.2", | ||
"rollup": "^0.51.5", | ||
"rollup-plugin-babel": "^4.0.0-beta.0", | ||
"rollup-plugin-uglify": "^2.0.1", | ||
"standard-version": "^4.2.0", | ||
"uglify-es": "^3.1.6" | ||
"uglify-es": "^3.1.9" | ||
} | ||
} |
@@ -35,9 +35,7 @@ // @flow | ||
function disleadThis(master: IAtomInt) { | ||
(this: Atom<*>); | ||
master.dislead(this) | ||
master.dislead((this: Atom<*>)) | ||
} | ||
function actualizeMaster(master: IAtomInt) { | ||
(this: Atom<*>); | ||
if (this.status === ATOM_STATUS_CHECKING) { | ||
if ((this: Atom<*>).status === ATOM_STATUS_CHECKING) { | ||
master.actualize() | ||
@@ -91,6 +89,7 @@ } | ||
toString() { | ||
const hc = this.owner.constructor | ||
const k = this.key | ||
const owner = this.owner | ||
const parent = owner.displayName || owner.constructor.displayName || owner.constructor.name | ||
return this.field | ||
return `${String(parent)}.${this.field}` | ||
+ (k | ||
@@ -97,0 +96,0 @@ ? ('(' + (typeof k === 'function' ? (k.displayName || k.name) : String(k)) + ')') |
@@ -48,3 +48,3 @@ // @flow | ||
const done = Symbol('lom_conform_done') | ||
const processed: WeakMap<Object, boolean> = new WeakMap() | ||
@@ -61,7 +61,6 @@ export default function conform<Target, Source>(target: Target, source: Source, isComponent: boolean, stack: any[] = []): Target { | ||
|| target.constructor !== source.constructor | ||
|| (target: Object)[done] !== undefined | ||
|| processed.has(target) | ||
) return target | ||
processed.set(target, true) | ||
;(target: Object)[done] = true | ||
const conformHandler = handlers.get(target.constructor) | ||
@@ -68,0 +67,0 @@ if (!conformHandler) return target |
@@ -12,3 +12,3 @@ // @flow | ||
} from './interfaces' | ||
import {ATOM_FORCE_NONE, ATOM_STATUS_DESTROYED, ATOM_STATUS_ACTUAL} from './interfaces' | ||
import {origId, ATOM_FORCE_NONE, ATOM_STATUS_DESTROYED, ATOM_STATUS_ACTUAL} from './interfaces' | ||
import {AtomWait} from './utils' | ||
@@ -28,29 +28,2 @@ import Atom from './Atom' | ||
export class BaseLogger implements ILogger { | ||
create<V>(owner: Object, field: string, key?: mixed, namespace: string): V | void {} | ||
onDestruct(atom: IAtom<*>, namespace: string): void {} | ||
sync() {} | ||
status(status: ILoggerStatus, atom: IAtom<*>, namespace: string): void {} | ||
error<V>(atom: IAtom<V>, err: Error, namespace: string): void {} | ||
newValue<V>(atom: IAtom<any>, from?: V | Error, to: V, isActualize?: boolean, namespace: string): void {} | ||
} | ||
export class ConsoleLogger extends BaseLogger { | ||
sync() { | ||
console.log('sync') | ||
} | ||
status(status: ILoggerStatus, atom: IAtom<*>, namespace: string): void { | ||
console.log(namespace, status, atom.displayName) | ||
} | ||
error<V>(atom: IAtom<V>, err: Error, namespace: string): void { | ||
console.log(namespace, 'error', atom.displayName, err) | ||
} | ||
newValue<V>(atom: IAtom<V>, from?: V | Error, to: V, isActualize?: boolean, namespace: string): void { | ||
console.log(namespace, isActualize ? 'actualize' : 'cacheSet', atom.displayName, 'from', from, 'to', to) | ||
} | ||
} | ||
export default class Context implements IContext { | ||
@@ -68,3 +41,3 @@ last: ?IAtomInt = null | ||
if (this._logger !== undefined) { | ||
return this._logger.create(atom.owner, atom.field, atom.key, this._namespace) | ||
return this._logger.create(atom.owner, atom.field, atom.key) | ||
} | ||
@@ -79,3 +52,3 @@ } | ||
console.error(e) | ||
if (this._logger) this._logger.error(atom, e, this._namespace) | ||
if (this._logger) this._logger.error(atom, e) | ||
} | ||
@@ -89,3 +62,3 @@ this._owners.delete(from) | ||
if (this._logger !== undefined) { | ||
this._logger.onDestruct(atom, this._namespace) | ||
this._logger.onDestruct(atom) | ||
} | ||
@@ -108,9 +81,17 @@ } | ||
} | ||
if (this._logger !== undefined) { | ||
if (to instanceof AtomWait) { | ||
this._logger.status('waiting', atom, this._namespace) | ||
} else if (to instanceof Error) { | ||
this._logger.error(atom, to, this._namespace) | ||
} else { | ||
this._logger.newValue(atom, from instanceof Error ? undefined : from, to, isActualize, this._namespace) | ||
const logger = this._logger | ||
if (logger !== undefined) { | ||
try { | ||
if (!this._scheduled && this._logger !== undefined) { | ||
this._logger.beginGroup(this._namespace) | ||
} | ||
logger.newValue( | ||
atom, | ||
from instanceof Error && (from: Object)[origId] ? (from: Object)[origId] : from, | ||
to instanceof Error && (to: Object)[origId] ? (to: Object)[origId] : to, | ||
isActualize | ||
) | ||
} catch (error) { | ||
console.error(error) | ||
logger.error(atom, error) | ||
} | ||
@@ -121,5 +102,2 @@ } | ||
proposeToPull(atom: IAtomInt) { | ||
if (this._logger !== undefined) { | ||
this._logger.status('proposeToPull', atom, this._namespace) | ||
} | ||
this._updating.push(atom) | ||
@@ -130,5 +108,2 @@ this._schedule() | ||
proposeToReap(atom: IAtomInt) { | ||
if (this._logger !== undefined) { | ||
this._logger.status('proposeToReap', atom, this._namespace) | ||
} | ||
this._reaping.add(atom) | ||
@@ -163,5 +138,2 @@ this._schedule() | ||
let start = this._start | ||
if (this._logger !== undefined) { | ||
this._logger.sync() | ||
} | ||
do { | ||
@@ -186,2 +158,5 @@ const end = updating.length | ||
} | ||
if (this._logger !== undefined) { | ||
this._logger.endGroup() | ||
} | ||
this._scheduled = false | ||
@@ -188,0 +163,0 @@ this._pendCount = 0 |
@@ -5,3 +5,4 @@ // @flow | ||
export {default as mem, memkey, detached, force, action} from './mem' | ||
export {defaultContext, BaseLogger, ConsoleLogger} from './Context' | ||
export {default as ConsoleLogger} from './ConsoleLogger' | ||
export {defaultContext} from './Context' | ||
@@ -8,0 +9,0 @@ export type { |
@@ -10,4 +10,2 @@ // @flow | ||
export interface ILogger { | ||
sync(): void; | ||
/** | ||
@@ -20,21 +18,16 @@ * Invokes before atom creating | ||
*/ | ||
create<V>(owner: Object, field: string, key?: mixed, namespace: string): V | void; | ||
create<V>(owner: Object, field: string, key?: mixed): V | void; | ||
beginGroup(name: string): void; | ||
endGroup(): void; | ||
/** | ||
* After atom destructor | ||
*/ | ||
onDestruct(atom: IAtom<*>, namespace: string): void; | ||
onDestruct<V>(atom: IAtom<V>): void; | ||
/** | ||
* Atom status changes | ||
- 'waiting' - atom fetching from server (mem.Wait throwed) | ||
- 'proposeToReap' - atom probably will be destroyed on next tick | ||
- 'proposeToPull' - atom will be actualized on next tick | ||
*/ | ||
status(status: ILoggerStatus, atom: IAtom<*>, namespace: string): void; | ||
/** | ||
* Error while actualizing atom | ||
*/ | ||
error<V>(atom: IAtom<V>, err: Error, namespace: string): void; | ||
error<V>(atom: IAtom<V>, err: Error): void; | ||
@@ -45,3 +38,3 @@ /** | ||
*/ | ||
newValue<V>(atom: IAtom<V>, from?: V | Error, to: V, isActualize?: boolean, namespace: string): void; | ||
newValue<V>(atom: IAtom<V>, from?: V | Error, to: V | Error, isActualize?: boolean): void; | ||
} | ||
@@ -75,3 +68,3 @@ | ||
export const catchedId = Symbol('lom_atom_catched') | ||
export const origId = Symbol('orig_error') | ||
export type IAtomStatus = typeof ATOM_STATUS_OBSOLETE | ||
@@ -78,0 +71,0 @@ | typeof ATOM_STATUS_CHECKING | typeof ATOM_STATUS_PULLING | typeof ATOM_STATUS_ACTUAL |
@@ -14,13 +14,13 @@ // @flow | ||
proto: P, | ||
rname: string, | ||
name: string, | ||
descr: TypedPropertyDescriptor<*>, | ||
isComponent?: boolean | ||
): TypedPropertyDescriptor<*> { | ||
const name = getId(proto, rname) | ||
const longName = getId(proto, name) | ||
if (descr.value === undefined) { | ||
throw new TypeError(`${name} is not an function (next?: V)`) | ||
throw new TypeError(`${longName} is not an function (next?: V)`) | ||
} | ||
proto[`${name}$`] = descr.value | ||
const hostAtoms: WeakMap<Object, IAtom<V>> = new WeakMap() | ||
Object.defineProperty(proto, `${rname}()`, { | ||
Object.defineProperty(proto, `${name}()`, { | ||
get() { | ||
@@ -31,6 +31,6 @@ return hostAtoms.get(this) | ||
const forcedFn = function (next?: V | Error, force?: IAtomForce) { | ||
return this[rname](next, force === undefined ? ATOM_FORCE_CACHE : force) | ||
return this[name](next, force === undefined ? ATOM_FORCE_CACHE : force) | ||
} | ||
setFunctionName(forcedFn, `${name}*`) | ||
proto[`${rname}*`] = forcedFn | ||
setFunctionName(forcedFn, `${longName}*`) | ||
proto[`${name}*`] = forcedFn | ||
@@ -79,8 +79,8 @@ return { | ||
let propForced: IAtomForce = ATOM_FORCE_NONE | ||
function memProp<V, P: Object>( | ||
proto: P, | ||
rname: string, | ||
name: string, | ||
descr: TypedPropertyDescriptor<V> | ||
): TypedPropertyDescriptor<V> { | ||
const name = getId(proto, rname) | ||
const handlerKey = `${name}$` | ||
@@ -91,5 +91,6 @@ if (proto[handlerKey] !== undefined) { | ||
if (descr.initializer) setFunctionName(descr.initializer, name) | ||
if (descr.get) setFunctionName(descr.get, `get#${name}`) | ||
if (descr.set) setFunctionName(descr.set, `set#${name}`) | ||
const longName = getId(proto, name) | ||
if (descr.initializer) setFunctionName(descr.initializer, longName) | ||
if (descr.get) setFunctionName(descr.get, `get#${longName}`) | ||
if (descr.set) setFunctionName(descr.set, `set#${longName}`) | ||
const handler = proto[handlerKey] = descr.get === undefined && descr.set === undefined | ||
@@ -99,3 +100,3 @@ ? createValueHandler(descr.initializer) | ||
setFunctionName(handler, `${name}()`) | ||
setFunctionName(handler, `${longName}()`) | ||
@@ -160,13 +161,13 @@ const hostAtoms: WeakMap<Object, IAtom<V>> = new WeakMap() | ||
proto: P, | ||
rname: string, | ||
name: string, | ||
descr: TypedPropertyDescriptor<IAtomHandler<V, K>> | ||
): TypedPropertyDescriptor<IAtomHandler<V, K>> { | ||
const name = getId(proto, rname) | ||
const longName = getId(proto, name) | ||
const handler = descr.value | ||
if (handler === undefined) { | ||
throw new TypeError(`${name} is not an function (rawKey: K, next?: V)`) | ||
throw new TypeError(`${longName} is not an function (rawKey: K, next?: V)`) | ||
} | ||
proto[`${name}$`] = handler | ||
const hostAtoms: WeakMap<Object, Map<string, IAtom<V>>> = new WeakMap() | ||
Object.defineProperty(proto, `${rname}()`, { | ||
Object.defineProperty(proto, `${name}()`, { | ||
get() { | ||
@@ -177,6 +178,6 @@ return hostAtoms.get(this) | ||
const forcedFn = function (rawKey: K, next?: V | Error, force?: IAtomForce) { | ||
return this[rname](rawKey, next, force === undefined ? ATOM_FORCE_CACHE : force) | ||
return this[name](rawKey, next, force === undefined ? ATOM_FORCE_CACHE : force) | ||
} | ||
setFunctionName(forcedFn, `${name}*`) | ||
proto[`${rname}*`] = forcedFn | ||
setFunctionName(forcedFn, `${longName}*`) | ||
proto[`${name}*`] = forcedFn | ||
@@ -289,17 +290,17 @@ return { | ||
function createActionMethod(t: Object, hk: string, context: IContext): (...args: any[]) => any { | ||
const name = getId(t, hk) | ||
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(name) | ||
const oldNamespace = context.beginTransaction(longName) | ||
const args = arguments | ||
try { | ||
switch (args.length) { | ||
case 0: result = t[hk](); break | ||
case 1: result = t[hk](args[0]); break | ||
case 2: result = t[hk](args[0], args[1]); break | ||
case 3: result = t[hk](args[0], args[1], args[2]); break | ||
case 4: result = t[hk](args[0], args[1], args[2], args[3]); break | ||
case 5: result = t[hk](args[0], args[1], args[2], args[3], args[4]); break | ||
default: result = t[hk].apply(t, args) | ||
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) | ||
} | ||
@@ -312,3 +313,3 @@ } finally { | ||
} | ||
setFunctionName(action, name) | ||
setFunctionName(action, longName) | ||
@@ -347,9 +348,9 @@ return action | ||
proto: P, | ||
field: string, | ||
name: string, | ||
descr: TypedPropertyDescriptor<*>, | ||
context: IContext | ||
): TypedPropertyDescriptor<*> { | ||
const hk = `${field}$` | ||
const hk = `${name}$` | ||
if (descr.value === undefined) { | ||
throw new TypeError(`${field} is not an function (next?: V)`) | ||
throw new TypeError(`${getId(proto, name)} is not an function (next?: V)`) | ||
} | ||
@@ -368,3 +369,3 @@ proto[hk] = descr.value | ||
const actionFn = createActionMethod(this, hk, context) | ||
Object.defineProperty(this, field, { | ||
Object.defineProperty(this, name, { | ||
configurable: true, | ||
@@ -371,0 +372,0 @@ value: actionFn |
// @flow | ||
import {catchedId} from './interfaces' | ||
import {catchedId, origId} from './interfaces' | ||
const throwOnAccess = { | ||
get<V: Object>(target: Error): V { | ||
get<V: Object>(target: Error, key: string): V { | ||
if (key === origId) return (target: Object).valueOf() | ||
throw target.valueOf() | ||
}, | ||
ownKeys(target: Error) { | ||
ownKeys(target: Error): string[] { | ||
throw target.valueOf() | ||
@@ -11,0 +12,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
350894
22
3613