Comparing version 4.0.1 to 4.0.2
@@ -5,2 +5,7 @@ # Change Log | ||
<a name="4.0.2"></a> | ||
## [4.0.2](https://github.com/zerkalica/lom_atom/compare/v4.0.1...v4.0.2) (2018-03-26) | ||
<a name="4.0.1"></a> | ||
@@ -7,0 +12,0 @@ ## [4.0.1](https://github.com/zerkalica/lom_atom/compare/v4.0.0...v4.0.1) (2018-03-09) |
@@ -47,3 +47,3 @@ var actionId = Symbol('lom_action'); | ||
if (!atom.slaves) { | ||
if (!atom._slaves) { | ||
atom.destructor(); | ||
@@ -184,2 +184,5 @@ } | ||
var catchedId = Symbol('lom_cached'); | ||
function isPromise(target) { | ||
return target !== null && typeof target === 'object' && typeof target.then === 'function'; | ||
} | ||
/** | ||
@@ -190,14 +193,24 @@ * Can't extend Error | ||
var AtomWait = function AtomWait(message) { | ||
if (message === void 0) { | ||
message = '[Pending]'; | ||
var AtomWait = | ||
/*#__PURE__*/ | ||
function () { | ||
AtomWait.is = function is(target) { | ||
return target instanceof AtomWait || isPromise(target); | ||
}; | ||
function AtomWait(message) { | ||
if (message === void 0) { | ||
message = '[Pending]'; | ||
} | ||
var t = Error.call(this, message) // super(message) | ||
// $FlowFixMe new.target | ||
; | ||
t['__proto__'] = new.target.prototype; | ||
t[catchedId] = true; | ||
return t; | ||
} | ||
var t = Error.call(this, message) // super(message) | ||
// $FlowFixMe new.target | ||
; | ||
t['__proto__'] = new.target.prototype; | ||
t[catchedId] = true; | ||
return t; | ||
}; | ||
return AtomWait; | ||
}(); | ||
AtomWait.prototype = Object.create(Error.prototype); | ||
@@ -303,2 +316,3 @@ AtomWait.prototype.constructor = AtomWait; | ||
this._slaves = null; | ||
this._setForced = undefined; | ||
this._retry = undefined; | ||
@@ -353,2 +367,3 @@ this.displayName = displayName; | ||
_proto.value = function value(next, forceCache) { | ||
if (this.status === ATOM_STATUS_DESTROYED) return this.current; | ||
var context = defaultContext; | ||
@@ -466,2 +481,4 @@ var current = this.current; | ||
_proto.refresh = function refresh() { | ||
var _this = this; | ||
var masters = this._masters; | ||
@@ -483,4 +500,10 @@ | ||
} catch (error) { | ||
if (error[catchedId] === undefined) { | ||
if (isPromise(error)) { | ||
if (this._setForced === undefined) this._setForced = function (value) { | ||
return _this.value(value, ATOM_FORCE_CACHE); | ||
}; | ||
error.then(this._setForced).catch(this._setForced); | ||
error[catchedId] = true; | ||
} else if (error[catchedId] === undefined) { | ||
error[catchedId] = true; | ||
console.error(error.stack || error); | ||
@@ -542,7 +565,7 @@ } | ||
_proto.getRetry = function getRetry() { | ||
var _this = this; | ||
var _this2 = this; | ||
if (this._retry === undefined) { | ||
var fn = function fn() { | ||
return _this.refresh(); | ||
return _this2.refresh(); | ||
}; | ||
@@ -929,3 +952,3 @@ | ||
var _useColors = this._useColors; | ||
console[from instanceof Error && !(from instanceof AtomWaitInt) ? 'warn' : to instanceof Error && !(to instanceof AtomWaitInt) ? 'error' : 'log'](_useColors ? '%c' + name : name, _useColors ? stringToColor(name) : '', from instanceof Error ? from.message : from, '➔', to instanceof Error ? to.message : to); | ||
console[from instanceof Error && !AtomWaitInt.is(from) ? 'warn' : to instanceof Error && !AtomWaitInt.is(to) ? 'error' : 'log'](_useColors ? '%c' + name : name, _useColors ? stringToColor(name) : '', from instanceof Error ? from.message : from, '➔', to instanceof Error ? to.message : to); | ||
} | ||
@@ -932,0 +955,0 @@ }; |
@@ -51,3 +51,3 @@ 'use strict'; | ||
if (!atom.slaves) { | ||
if (!atom._slaves) { | ||
atom.destructor(); | ||
@@ -188,2 +188,5 @@ } | ||
var catchedId = Symbol('lom_cached'); | ||
function isPromise(target) { | ||
return target !== null && typeof target === 'object' && typeof target.then === 'function'; | ||
} | ||
/** | ||
@@ -194,14 +197,24 @@ * Can't extend Error | ||
var AtomWait = function AtomWait(message) { | ||
if (message === void 0) { | ||
message = '[Pending]'; | ||
var AtomWait = | ||
/*#__PURE__*/ | ||
function () { | ||
AtomWait.is = function is(target) { | ||
return target instanceof AtomWait || isPromise(target); | ||
}; | ||
function AtomWait(message) { | ||
if (message === void 0) { | ||
message = '[Pending]'; | ||
} | ||
var t = Error.call(this, message) // super(message) | ||
// $FlowFixMe new.target | ||
; | ||
t['__proto__'] = new.target.prototype; | ||
t[catchedId] = true; | ||
return t; | ||
} | ||
var t = Error.call(this, message) // super(message) | ||
// $FlowFixMe new.target | ||
; | ||
t['__proto__'] = new.target.prototype; | ||
t[catchedId] = true; | ||
return t; | ||
}; | ||
return AtomWait; | ||
}(); | ||
AtomWait.prototype = Object.create(Error.prototype); | ||
@@ -307,2 +320,3 @@ AtomWait.prototype.constructor = AtomWait; | ||
this._slaves = null; | ||
this._setForced = undefined; | ||
this._retry = undefined; | ||
@@ -357,2 +371,3 @@ this.displayName = displayName; | ||
_proto.value = function value(next, forceCache) { | ||
if (this.status === ATOM_STATUS_DESTROYED) return this.current; | ||
var context = defaultContext; | ||
@@ -470,2 +485,4 @@ var current = this.current; | ||
_proto.refresh = function refresh() { | ||
var _this = this; | ||
var masters = this._masters; | ||
@@ -487,4 +504,10 @@ | ||
} catch (error) { | ||
if (error[catchedId] === undefined) { | ||
if (isPromise(error)) { | ||
if (this._setForced === undefined) this._setForced = function (value) { | ||
return _this.value(value, ATOM_FORCE_CACHE); | ||
}; | ||
error.then(this._setForced).catch(this._setForced); | ||
error[catchedId] = true; | ||
} else if (error[catchedId] === undefined) { | ||
error[catchedId] = true; | ||
console.error(error.stack || error); | ||
@@ -546,7 +569,7 @@ } | ||
_proto.getRetry = function getRetry() { | ||
var _this = this; | ||
var _this2 = this; | ||
if (this._retry === undefined) { | ||
var fn = function fn() { | ||
return _this.refresh(); | ||
return _this2.refresh(); | ||
}; | ||
@@ -933,3 +956,3 @@ | ||
var _useColors = this._useColors; | ||
console[from instanceof Error && !(from instanceof AtomWaitInt) ? 'warn' : to instanceof Error && !(to instanceof AtomWaitInt) ? 'error' : 'log'](_useColors ? '%c' + name : name, _useColors ? stringToColor(name) : '', from instanceof Error ? from.message : from, '➔', to instanceof Error ? to.message : to); | ||
console[from instanceof Error && !AtomWaitInt.is(from) ? 'warn' : to instanceof Error && !AtomWaitInt.is(to) ? 'error' : 'log'](_useColors ? '%c' + name : name, _useColors ? stringToColor(name) : '', from instanceof Error ? from.message : from, '➔', to instanceof Error ? to.message : to); | ||
} | ||
@@ -936,0 +959,0 @@ }; |
@@ -53,3 +53,3 @@ (function (global, factory) { | ||
if (!atom.slaves) { | ||
if (!atom._slaves) { | ||
atom.destructor(); | ||
@@ -190,2 +190,5 @@ } | ||
var catchedId = Symbol('lom_cached'); | ||
function isPromise(target) { | ||
return target !== null && typeof target === 'object' && typeof target.then === 'function'; | ||
} | ||
/** | ||
@@ -196,14 +199,24 @@ * Can't extend Error | ||
var AtomWait = function AtomWait(message) { | ||
if (message === void 0) { | ||
message = '[Pending]'; | ||
var AtomWait = | ||
/*#__PURE__*/ | ||
function () { | ||
AtomWait.is = function is(target) { | ||
return target instanceof AtomWait || isPromise(target); | ||
}; | ||
function AtomWait(message) { | ||
if (message === void 0) { | ||
message = '[Pending]'; | ||
} | ||
var t = Error.call(this, message) // super(message) | ||
// $FlowFixMe new.target | ||
; | ||
t['__proto__'] = new.target.prototype; | ||
t[catchedId] = true; | ||
return t; | ||
} | ||
var t = Error.call(this, message) // super(message) | ||
// $FlowFixMe new.target | ||
; | ||
t['__proto__'] = new.target.prototype; | ||
t[catchedId] = true; | ||
return t; | ||
}; | ||
return AtomWait; | ||
}(); | ||
AtomWait.prototype = Object.create(Error.prototype); | ||
@@ -309,2 +322,3 @@ AtomWait.prototype.constructor = AtomWait; | ||
this._slaves = null; | ||
this._setForced = undefined; | ||
this._retry = undefined; | ||
@@ -359,2 +373,3 @@ this.displayName = displayName; | ||
_proto.value = function value(next, forceCache) { | ||
if (this.status === ATOM_STATUS_DESTROYED) return this.current; | ||
var context = defaultContext; | ||
@@ -472,2 +487,4 @@ var current = this.current; | ||
_proto.refresh = function refresh() { | ||
var _this = this; | ||
var masters = this._masters; | ||
@@ -489,4 +506,10 @@ | ||
} catch (error) { | ||
if (error[catchedId] === undefined) { | ||
if (isPromise(error)) { | ||
if (this._setForced === undefined) this._setForced = function (value) { | ||
return _this.value(value, ATOM_FORCE_CACHE); | ||
}; | ||
error.then(this._setForced).catch(this._setForced); | ||
error[catchedId] = true; | ||
} else if (error[catchedId] === undefined) { | ||
error[catchedId] = true; | ||
console.error(error.stack || error); | ||
@@ -548,7 +571,7 @@ } | ||
_proto.getRetry = function getRetry() { | ||
var _this = this; | ||
var _this2 = this; | ||
if (this._retry === undefined) { | ||
var fn = function fn() { | ||
return _this.refresh(); | ||
return _this2.refresh(); | ||
}; | ||
@@ -935,3 +958,3 @@ | ||
var _useColors = this._useColors; | ||
console[from instanceof Error && !(from instanceof AtomWaitInt) ? 'warn' : to instanceof Error && !(to instanceof AtomWaitInt) ? 'error' : 'log'](_useColors ? '%c' + name : name, _useColors ? stringToColor(name) : '', from instanceof Error ? from.message : from, '➔', to instanceof Error ? to.message : to); | ||
console[from instanceof Error && !AtomWaitInt.is(from) ? 'warn' : to instanceof Error && !AtomWaitInt.is(to) ? 'error' : 'log'](_useColors ? '%c' + name : name, _useColors ? stringToColor(name) : '', from instanceof Error ? from.message : from, '➔', to instanceof Error ? to.message : to); | ||
} | ||
@@ -938,0 +961,0 @@ }; |
{ | ||
"name": "lom_atom", | ||
"version": "4.0.1", | ||
"version": "4.0.2", | ||
"description": "Alternative implementation of eigenmethod mol_atom state management library", | ||
@@ -63,3 +63,3 @@ "publishConfig": { | ||
"chokidar-cli": "^1.2.0", | ||
"flow-bin": "^0.66.0", | ||
"flow-bin": "^0.68.0", | ||
"mocha": "^5.0.1", | ||
@@ -66,0 +66,0 @@ "rimraf": "^2.6.2", |
@@ -97,13 +97,7 @@ # lom_atom | ||
fetch('/todos') | ||
.then((data) => mem.cache(this.todos = data)) | ||
.catch(error => mem.cache(this.todos = error)) | ||
throw new mem.Wait() | ||
throw fetch('/todos') | ||
} | ||
@mem.manual get user(): IUser { | ||
fetch('/user') | ||
.then((data) => mem.cache(this.user = data)) | ||
.catch(error => mem.cache(this.user = error)) | ||
throw fetch('/user') | ||
} | ||
@@ -110,0 +104,0 @@ |
@@ -19,3 +19,3 @@ // @flow | ||
import Context, {defaultContext} from './Context' | ||
import {AtomWait, setFunctionName, origId, catchedId, proxify} from './utils' | ||
import {isPromise, setFunctionName, origId, catchedId, proxify} from './utils' | ||
import conform, {processed} from './conform' | ||
@@ -114,2 +114,3 @@ | ||
value(next?: V | Error, forceCache?: IAtomForce): V { | ||
if (this.status === ATOM_STATUS_DESTROYED) return this.current | ||
const context = defaultContext | ||
@@ -228,2 +229,4 @@ let current: V | Error = this.current | ||
_setForced: void | (v: V | Error) => any = undefined | ||
refresh(): void { | ||
@@ -245,4 +248,10 @@ const masters = this._masters | ||
} catch (error) { | ||
if (error[catchedId] === undefined) { | ||
if (isPromise(error)) { | ||
if (this._setForced === undefined) this._setForced = value => this.value(value, ATOM_FORCE_CACHE) | ||
error | ||
.then(this._setForced) | ||
.catch(this._setForced) | ||
error[catchedId] = true | ||
} else if (error[catchedId] === undefined) { | ||
error[catchedId] = true | ||
console.error(error.stack || error) | ||
@@ -249,0 +258,0 @@ } |
@@ -52,5 +52,5 @@ // @flow | ||
console[ | ||
from instanceof Error && !(from instanceof AtomWait) | ||
from instanceof Error && !AtomWait.is(from) | ||
? 'warn' | ||
: (to instanceof Error && !(to instanceof AtomWait) ? 'error' : 'log') | ||
: (to instanceof Error && !AtomWait.is(to) ? 'error' : 'log') | ||
]( | ||
@@ -57,0 +57,0 @@ useColors ? '%c' + name : name, |
@@ -13,3 +13,3 @@ // @flow | ||
reaping.delete(atom) | ||
if (!atom.slaves) { | ||
if (!atom._slaves) { | ||
atom.destructor() | ||
@@ -16,0 +16,0 @@ } |
@@ -9,4 +9,4 @@ // @flow | ||
static schedule = scheduleNative | ||
_queue: (() => void)[] = [] | ||
add = (handler: () => void) => { | ||
_queue: (() => any)[] = [] | ||
add = (handler: () => any) => { | ||
if (this._queue.length === 0) this.constructor.schedule(this.rewind) | ||
@@ -13,0 +13,0 @@ this._queue.push(handler) |
@@ -55,2 +55,3 @@ // @flow | ||
manualReset: boolean; | ||
_slaves: ?Set<IAtomInt>; | ||
actualize(): void; | ||
@@ -57,0 +58,0 @@ check(): void; |
@@ -5,2 +5,6 @@ // @flow | ||
export function isPromise(target: mixed): boolean { | ||
return target !== null && typeof target === 'object' && typeof target.then === 'function' | ||
} | ||
/** | ||
@@ -14,2 +18,6 @@ * Can't extend Error | ||
static is(target: mixed): boolean { | ||
return target instanceof AtomWait || isPromise(target) | ||
} | ||
constructor(message?: string = '[Pending]') { | ||
@@ -16,0 +24,0 @@ const t = Error.call(this, message) |
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
369684
29
4144
176