Comparing version 4.0.2 to 4.0.3
@@ -5,2 +5,7 @@ # Change Log | ||
<a name="4.0.3"></a> | ||
## [4.0.3](https://github.com/zerkalica/lom_atom/compare/v4.0.2...v4.0.3) (2018-03-26) | ||
<a name="4.0.2"></a> | ||
@@ -7,0 +12,0 @@ ## [4.0.2](https://github.com/zerkalica/lom_atom/compare/v4.0.1...v4.0.2) (2018-03-26) |
@@ -183,2 +183,3 @@ var actionId = Symbol('lom_action'); | ||
var catchedId = Symbol('lom_cached'); | ||
var atomId = Symbol('lom_atom'); | ||
function isPromise(target) { | ||
@@ -192,24 +193,11 @@ return target !== null && typeof target === 'object' && typeof target.then === 'function'; | ||
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; | ||
} | ||
return AtomWait; | ||
}(); | ||
var AtomWait = function AtomWait(message, promise) { | ||
var t = Error.call(this, message || '[Pending]') // super(message) | ||
// $FlowFixMe new.target | ||
; | ||
t['__proto__'] = new.target.prototype; | ||
t[catchedId] = undefined; | ||
t.promise = promise; | ||
return t; | ||
}; | ||
AtomWait.prototype = Object.create(Error.prototype); | ||
@@ -460,2 +448,3 @@ AtomWait.prototype.constructor = AtomWait; | ||
next = nextRaw[origId] === undefined ? nextRaw : nextRaw[origId]; | ||
if (next[atomId] === undefined) next[atomId] = this; | ||
} else { | ||
@@ -497,14 +486,19 @@ next = this._conform(nextRaw, prev); | ||
} catch (error) { | ||
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); | ||
} | ||
if (error[catchedId] === undefined) { | ||
newValue = isPromise(error) ? new AtomWaitInt(undefined, error) : error; | ||
newValue[catchedId] = true; | ||
newValue = error; | ||
if (newValue instanceof AtomWaitInt) { | ||
var promise = newValue.promise; | ||
if (promise) { | ||
if (this._setForced === undefined) this._setForced = function (value) { | ||
return _this.value(value, ATOM_FORCE_CACHE); | ||
}; | ||
promise.then(this._setForced).catch(this._setForced); | ||
} | ||
} else { | ||
console.error(newValue.stack || newValue); | ||
} | ||
} else newValue = error; | ||
} | ||
@@ -604,5 +598,8 @@ | ||
_this = _Atom.call(this, displayName, function (next) { | ||
return _assertThisInitialized(_this)._update(next); | ||
return t._update(next); | ||
}) || this; | ||
_this._propsChanged = true; | ||
var t = _assertThisInitialized(_this); | ||
_this._owner = owner; | ||
@@ -878,2 +875,7 @@ return _this; | ||
function getRetry(error) { | ||
var atom = error[atomId]; | ||
return atom ? atom.getRetry() : undefined; | ||
} | ||
Object.defineProperties(mem, { | ||
@@ -892,2 +894,5 @@ cache: { | ||
}, | ||
retry: { | ||
value: getRetry | ||
}, | ||
async: { | ||
@@ -951,3 +956,3 @@ get: function get() { | ||
var _useColors = this._useColors; | ||
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); | ||
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); | ||
} | ||
@@ -954,0 +959,0 @@ }; |
@@ -187,2 +187,3 @@ 'use strict'; | ||
var catchedId = Symbol('lom_cached'); | ||
var atomId = Symbol('lom_atom'); | ||
function isPromise(target) { | ||
@@ -196,24 +197,11 @@ return target !== null && typeof target === 'object' && typeof target.then === 'function'; | ||
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; | ||
} | ||
return AtomWait; | ||
}(); | ||
var AtomWait = function AtomWait(message, promise) { | ||
var t = Error.call(this, message || '[Pending]') // super(message) | ||
// $FlowFixMe new.target | ||
; | ||
t['__proto__'] = new.target.prototype; | ||
t[catchedId] = undefined; | ||
t.promise = promise; | ||
return t; | ||
}; | ||
AtomWait.prototype = Object.create(Error.prototype); | ||
@@ -464,2 +452,3 @@ AtomWait.prototype.constructor = AtomWait; | ||
next = nextRaw[origId] === undefined ? nextRaw : nextRaw[origId]; | ||
if (next[atomId] === undefined) next[atomId] = this; | ||
} else { | ||
@@ -501,14 +490,19 @@ next = this._conform(nextRaw, prev); | ||
} catch (error) { | ||
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); | ||
} | ||
if (error[catchedId] === undefined) { | ||
newValue = isPromise(error) ? new AtomWaitInt(undefined, error) : error; | ||
newValue[catchedId] = true; | ||
newValue = error; | ||
if (newValue instanceof AtomWaitInt) { | ||
var promise = newValue.promise; | ||
if (promise) { | ||
if (this._setForced === undefined) this._setForced = function (value) { | ||
return _this.value(value, ATOM_FORCE_CACHE); | ||
}; | ||
promise.then(this._setForced).catch(this._setForced); | ||
} | ||
} else { | ||
console.error(newValue.stack || newValue); | ||
} | ||
} else newValue = error; | ||
} | ||
@@ -608,5 +602,8 @@ | ||
_this = _Atom.call(this, displayName, function (next) { | ||
return _assertThisInitialized(_this)._update(next); | ||
return t._update(next); | ||
}) || this; | ||
_this._propsChanged = true; | ||
var t = _assertThisInitialized(_this); | ||
_this._owner = owner; | ||
@@ -882,2 +879,7 @@ return _this; | ||
function getRetry(error) { | ||
var atom = error[atomId]; | ||
return atom ? atom.getRetry() : undefined; | ||
} | ||
Object.defineProperties(mem, { | ||
@@ -896,2 +898,5 @@ cache: { | ||
}, | ||
retry: { | ||
value: getRetry | ||
}, | ||
async: { | ||
@@ -955,3 +960,3 @@ get: function get() { | ||
var _useColors = this._useColors; | ||
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); | ||
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); | ||
} | ||
@@ -958,0 +963,0 @@ }; |
@@ -189,2 +189,3 @@ (function (global, factory) { | ||
var catchedId = Symbol('lom_cached'); | ||
var atomId = Symbol('lom_atom'); | ||
function isPromise(target) { | ||
@@ -198,24 +199,11 @@ return target !== null && typeof target === 'object' && typeof target.then === 'function'; | ||
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; | ||
} | ||
return AtomWait; | ||
}(); | ||
var AtomWait = function AtomWait(message, promise) { | ||
var t = Error.call(this, message || '[Pending]') // super(message) | ||
// $FlowFixMe new.target | ||
; | ||
t['__proto__'] = new.target.prototype; | ||
t[catchedId] = undefined; | ||
t.promise = promise; | ||
return t; | ||
}; | ||
AtomWait.prototype = Object.create(Error.prototype); | ||
@@ -466,2 +454,3 @@ AtomWait.prototype.constructor = AtomWait; | ||
next = nextRaw[origId] === undefined ? nextRaw : nextRaw[origId]; | ||
if (next[atomId] === undefined) next[atomId] = this; | ||
} else { | ||
@@ -503,14 +492,19 @@ next = this._conform(nextRaw, prev); | ||
} catch (error) { | ||
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); | ||
} | ||
if (error[catchedId] === undefined) { | ||
newValue = isPromise(error) ? new AtomWaitInt(undefined, error) : error; | ||
newValue[catchedId] = true; | ||
newValue = error; | ||
if (newValue instanceof AtomWaitInt) { | ||
var promise = newValue.promise; | ||
if (promise) { | ||
if (this._setForced === undefined) this._setForced = function (value) { | ||
return _this.value(value, ATOM_FORCE_CACHE); | ||
}; | ||
promise.then(this._setForced).catch(this._setForced); | ||
} | ||
} else { | ||
console.error(newValue.stack || newValue); | ||
} | ||
} else newValue = error; | ||
} | ||
@@ -610,5 +604,8 @@ | ||
_this = _Atom.call(this, displayName, function (next) { | ||
return _assertThisInitialized(_this)._update(next); | ||
return t._update(next); | ||
}) || this; | ||
_this._propsChanged = true; | ||
var t = _assertThisInitialized(_this); | ||
_this._owner = owner; | ||
@@ -884,2 +881,7 @@ return _this; | ||
function getRetry(error) { | ||
var atom = error[atomId]; | ||
return atom ? atom.getRetry() : undefined; | ||
} | ||
Object.defineProperties(mem, { | ||
@@ -898,2 +900,5 @@ cache: { | ||
}, | ||
retry: { | ||
value: getRetry | ||
}, | ||
async: { | ||
@@ -957,3 +962,3 @@ get: function get() { | ||
var _useColors = this._useColors; | ||
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); | ||
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); | ||
} | ||
@@ -960,0 +965,0 @@ }; |
{ | ||
"name": "lom_atom", | ||
"version": "4.0.2", | ||
"version": "4.0.3", | ||
"description": "Alternative implementation of eigenmethod mol_atom state management library", | ||
@@ -72,5 +72,3 @@ "publishConfig": { | ||
}, | ||
"dependencies": { | ||
"urc": "^1.0.3" | ||
} | ||
"dependencies": {} | ||
} |
@@ -81,3 +81,3 @@ # lom_atom | ||
@mem set todos(todos: Todo | Error) { | ||
fetch({ | ||
const promise = fetch({ | ||
url: '/todos', | ||
@@ -87,8 +87,6 @@ method: 'POST', | ||
}) | ||
.then((data) => mem.cache(this.todos = data)) | ||
.catch(error => mem.cache(this.todos = error)) | ||
console.log('set handler') | ||
throw new mem.Wait() | ||
throw new mem.Wait('Loading /todos...', promise) | ||
} | ||
@@ -125,2 +123,4 @@ | ||
* ``` mem.async(this.todos) ``` - initiate parallel loading todos and user (wrap error in proxy, do not throw error if data are fetching). | ||
* ``` throw new Promise(...) ``` - Load data and handle errors and pending State | ||
* ``` throw new mem.Wait('Loading /todos...', promise) ``` - Add some debug info to fetching payload | ||
@@ -127,0 +127,0 @@ ## Key-value |
@@ -19,3 +19,3 @@ // @flow | ||
import Context, {defaultContext} from './Context' | ||
import {isPromise, setFunctionName, origId, catchedId, proxify} from './utils' | ||
import {atomId, AtomWait, isPromise, setFunctionName, origId, catchedId, proxify} from './utils' | ||
import conform, {processed} from './conform' | ||
@@ -160,4 +160,4 @@ | ||
if (forceCache !== ATOM_FORCE_NONE) { | ||
if ((current: Object)[proxyId] === undefined) (current: Object)[proxyId] = proxify((current: any)) | ||
return (current: Object)[proxyId] | ||
if ((current: any)[proxyId] === undefined) (current: any)[proxyId] = proxify((current: any)) | ||
return (current: any)[proxyId] | ||
} | ||
@@ -212,2 +212,3 @@ throw current | ||
: (nextRaw: Object)[origId] | ||
if ((next: Object)[atomId] === undefined) (next: Object)[atomId] = this | ||
} else { | ||
@@ -248,13 +249,19 @@ next = this._conform(nextRaw, prev) | ||
} catch (error) { | ||
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) | ||
} | ||
newValue = error | ||
if ((error: Object)[catchedId] === undefined) { | ||
newValue = isPromise(error) ? new AtomWait(undefined, (error: any)) : error | ||
;(newValue: Object)[catchedId] = true | ||
if (newValue instanceof AtomWait) { | ||
const promise = newValue.promise | ||
if (promise) { | ||
if (this._setForced === undefined) this._setForced = value => { | ||
return this.value(value, ATOM_FORCE_CACHE) | ||
} | ||
promise | ||
.then(this._setForced) | ||
.catch(this._setForced) | ||
} | ||
} else { | ||
console.error(newValue.stack || newValue) | ||
} | ||
} else newValue = error | ||
} | ||
@@ -261,0 +268,0 @@ context.current = slave |
@@ -52,5 +52,5 @@ // @flow | ||
console[ | ||
from instanceof Error && !AtomWait.is(from) | ||
from instanceof Error && !(from instanceof AtomWait) | ||
? 'warn' | ||
: (to instanceof Error && !AtomWait.is(to) ? 'error' : 'log') | ||
: (to instanceof Error && !(to instanceof AtomWait) ? 'error' : 'log') | ||
]( | ||
@@ -57,0 +57,0 @@ useColors ? '%c' + name : name, |
@@ -5,3 +5,3 @@ // @flow | ||
import {defaultContext} from '../Context' | ||
import {getId, setFunctionName} from '../utils' | ||
import {atomId, getId, setFunctionName} from '../utils' | ||
import Atom from '../Atom' | ||
@@ -174,2 +174,7 @@ | ||
function getRetry(error: Error): void | () => void { | ||
const atom = (error: Object)[atomId] | ||
return atom ? atom.getRetry() : undefined | ||
} | ||
Object.defineProperties(mem, { | ||
@@ -188,2 +193,5 @@ cache: ({ | ||
}: any), | ||
retry: { | ||
value: getRetry | ||
}, | ||
async: ({ | ||
@@ -211,4 +219,5 @@ get<V>(): (v: V) => V { | ||
getRetry<V>(v: V): () => void; | ||
retry(error: Error): void | () => void; | ||
key: IMemKey; | ||
} | ||
export default ((mem: any): IMem) |
@@ -5,8 +5,9 @@ // @flow | ||
import {ATOM_STATUS_OBSOLETE} from './interfaces' | ||
import type { | ||
IReactHost, | ||
IReactAtom | ||
} from 'urc' | ||
export default class ReactAtom<Element> extends Atom<Element> implements IReactAtom<Element> { | ||
interface IReactHost<Element> { | ||
__value(propsChanged: boolean): Element; | ||
forceUpdate(): void; | ||
} | ||
export default class ReactAtom<Element> extends Atom<Element> { | ||
_propsChanged = true | ||
@@ -16,3 +17,4 @@ _owner: IReactHost<Element> | ||
constructor(displayName: string, owner: IReactHost<Element>) { | ||
super(displayName, (next?: Element) => (this: any)._update(next)) | ||
super(displayName, (next?: Element) => t._update(next)) | ||
let t = this | ||
this._owner = owner | ||
@@ -19,0 +21,0 @@ } |
// @flow | ||
export const catchedId = Symbol('lom_cached') | ||
export const atomId = Symbol('lom_atom') | ||
@@ -16,13 +17,11 @@ export function isPromise(target: mixed): boolean { | ||
stack: string | ||
promise: ?Promise<*> | ||
static is(target: mixed): boolean { | ||
return target instanceof AtomWait || isPromise(target) | ||
} | ||
constructor(message?: string = '[Pending]') { | ||
const t = Error.call(this, message) | ||
constructor(message?: string, promise?: Promise<*>) { | ||
const t = Error.call(this, message || '[Pending]') | ||
// super(message) | ||
// $FlowFixMe new.target | ||
;(t: Object)['__proto__'] = new.target.prototype | ||
;(t: Object)[catchedId] = true | ||
;(t: Object)[catchedId] = undefined | ||
;(t: Object).promise = promise | ||
return t | ||
@@ -29,0 +28,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
374750
0
4175
- Removedurc@^1.0.3
- Removedurc@1.0.8(transitive)