reactive-di
Advanced tools
Comparing version 3.1.8 to 3.1.9
@@ -24,2 +24,4 @@ 'use strict'; | ||
this._mounted = false; | ||
this; // eslint-disable-line | ||
@@ -101,3 +103,3 @@ this.t = 4; | ||
var target = this._target.cached; | ||
if (hook.willMount && target) { | ||
if ((hook.willMount || hook.pull) && target) { | ||
var notifier = this._notifier; | ||
@@ -108,8 +110,15 @@ var oldTrace = notifier.trace; | ||
this._inHook = true; | ||
var oldHook = notifier.hook; | ||
notifier.hook = this; | ||
try { | ||
hook.willMount(target); | ||
if (hook.pull && !this._mounted) { | ||
this._mounted = true;hook.pull(target); | ||
} | ||
if (hook.willMount) { | ||
hook.willMount(target); | ||
} | ||
} catch (e) { | ||
this._inHook = false; | ||
throw e; | ||
notifier.onError(e, this.displayName, false); | ||
} | ||
notifier.hook = oldHook; | ||
this._inHook = false; | ||
@@ -134,8 +143,10 @@ notifier.trace = oldTrace; | ||
this._inHook = true; | ||
var oldHook = notifier.hook; | ||
notifier.hook = this; | ||
try { | ||
hook.willUnmount(target); | ||
} catch (e) { | ||
this._inHook = false; | ||
throw e; | ||
notifier.onError(e, this.displayName, false); | ||
} | ||
notifier.hook = oldHook; | ||
this._inHook = false; | ||
@@ -158,8 +169,10 @@ notifier.trace = oldTrace; | ||
this._inHook = true; | ||
var oldHook = notifier.hook; | ||
notifier.hook = this; | ||
try { | ||
hook.willUpdate(target); | ||
} catch (e) { | ||
this._inHook = false; | ||
throw e; | ||
notifier.onError(e, this.displayName, false); | ||
} | ||
notifier.hook = oldHook; | ||
this._inHook = false; | ||
@@ -184,2 +197,4 @@ notifier.trace = oldTrace; | ||
notifier.opId++; | ||
var oldHook = notifier.hook; | ||
notifier.hook = this; | ||
this._inHook = true; | ||
@@ -189,5 +204,5 @@ try { | ||
} catch (e) { | ||
this._inHook = false; | ||
throw e; | ||
notifier.onError(e, this.displayName, false); | ||
} | ||
notifier.hook = oldHook; | ||
this._inHook = false; | ||
@@ -200,3 +215,3 @@ notifier.trace = oldTrace; | ||
var target = this._target.cached; | ||
if (!target) { | ||
if (!target || this._inHook) { | ||
return; | ||
@@ -208,2 +223,4 @@ } | ||
this._inHook = true; | ||
var oldHook = notifier.hook; | ||
notifier.hook = this; | ||
if (hook.selfUpdate) { | ||
@@ -214,6 +231,6 @@ notifier.trace = this.displayName + '.selfUpdate'; | ||
} catch (e) { | ||
this._inHook = false; | ||
throw e; | ||
notifier.onError(e, this.displayName, false); | ||
} | ||
} | ||
notifier.hook = oldHook; | ||
notifier.trace = oldTrace; | ||
@@ -220,0 +237,0 @@ this._inHook = false; |
@@ -11,2 +11,4 @@ 'use strict'; | ||
this.logger = null; | ||
this.hook = null; | ||
this._consumers = []; | ||
@@ -22,3 +24,9 @@ this.trace = ''; | ||
var ac = this._consumers; | ||
this._consumers = ac.length ? ac.concat(consumers) : consumers; | ||
var hook = this.hook; | ||
for (var i = 0, l = consumers.length; i < l; i++) { | ||
var consumer = consumers[i]; | ||
if (consumer !== hook) { | ||
ac.push(consumer); | ||
} | ||
} | ||
if (this.logger) { | ||
@@ -25,0 +33,0 @@ this.logger.get().onSetValue({ |
@@ -207,2 +207,10 @@ 'use strict'; | ||
Source.prototype.pend = function pend() { | ||
this.getStatus().merge({ pending: true, complete: false, error: null }); | ||
}; | ||
Source.prototype.error = function error(_error) { | ||
this.getStatus().merge({ pending: false, complete: false, error: _error }); | ||
}; | ||
Source.prototype.reset = function reset() { | ||
@@ -214,2 +222,5 @@ if (!this.cached) { | ||
this.set(val); | ||
if (this.status) { | ||
this.status.reset(); | ||
} | ||
}; | ||
@@ -225,5 +236,2 @@ | ||
} | ||
if (this.status) { | ||
this.status.reset(); | ||
} | ||
var computeds = this.computeds.items; | ||
@@ -230,0 +238,0 @@ for (var i = 0, l = computeds.length; i < l; i++) { |
@@ -157,5 +157,4 @@ 'use strict'; | ||
source.merge(v); | ||
} else { | ||
this._status.reset(); | ||
} | ||
this._status.reset(); | ||
this._promisable.resolve(v || this._v); | ||
@@ -162,0 +161,0 @@ notifier.opId = oldId; |
{ | ||
"name": "reactive-di", | ||
"version": "3.1.8", | ||
"version": "3.1.9", | ||
"description": "Reactive dependency injection", | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
@@ -116,2 +116,4 @@ // @flow | ||
_mounted: boolean = false | ||
willMount(): void { | ||
@@ -122,3 +124,3 @@ if (this._refs === 0) { | ||
const target = this._target.cached | ||
if (hook.willMount && target) { | ||
if ((hook.willMount || hook.pull) && target) { | ||
const notifier = this._notifier | ||
@@ -129,8 +131,16 @@ const oldTrace = notifier.trace | ||
this._inHook = true | ||
const oldHook = notifier.hook | ||
notifier.hook = this | ||
try { | ||
(hook: any).willMount(target) | ||
if ((hook: any).pull && !this._mounted) { | ||
this._mounted = true | ||
;(hook: any).pull(target) | ||
} | ||
if ((hook: any).willMount) { | ||
(hook: any).willMount(target) | ||
} | ||
} catch (e) { | ||
this._inHook = false | ||
throw e | ||
notifier.onError(e, this.displayName, false) | ||
} | ||
notifier.hook = oldHook | ||
this._inHook = false | ||
@@ -155,8 +165,10 @@ notifier.trace = oldTrace | ||
this._inHook = true | ||
const oldHook = notifier.hook | ||
notifier.hook = this | ||
try { | ||
(hook: any).willUnmount(target) | ||
} catch (e) { | ||
this._inHook = false | ||
throw e | ||
notifier.onError(e, this.displayName, false) | ||
} | ||
notifier.hook = oldHook | ||
this._inHook = false | ||
@@ -182,8 +194,10 @@ notifier.trace = oldTrace | ||
this._inHook = true | ||
const oldHook = notifier.hook | ||
notifier.hook = this | ||
try { | ||
(hook: any).willUpdate(target) | ||
} catch (e) { | ||
this._inHook = false | ||
throw e | ||
notifier.onError(e, this.displayName, false) | ||
} | ||
notifier.hook = oldHook | ||
this._inHook = false | ||
@@ -208,2 +222,4 @@ notifier.trace = oldTrace | ||
notifier.opId++ | ||
const oldHook = notifier.hook | ||
notifier.hook = this | ||
this._inHook = true | ||
@@ -213,5 +229,5 @@ try { | ||
} catch (e) { | ||
this._inHook = false | ||
throw e | ||
notifier.onError(e, this.displayName, false) | ||
} | ||
notifier.hook = oldHook | ||
this._inHook = false | ||
@@ -224,3 +240,3 @@ notifier.trace = oldTrace | ||
const target = this._target.cached | ||
if (!target) { | ||
if (!target || this._inHook) { | ||
return | ||
@@ -232,2 +248,4 @@ } | ||
this._inHook = true | ||
const oldHook = notifier.hook | ||
notifier.hook = this | ||
if (hook.selfUpdate) { | ||
@@ -238,6 +256,6 @@ notifier.trace = this.displayName + '.selfUpdate' | ||
} catch (e) { | ||
this._inHook = false | ||
throw e | ||
notifier.onError(e, this.displayName, false) | ||
} | ||
} | ||
notifier.hook = oldHook | ||
notifier.trace = oldTrace | ||
@@ -244,0 +262,0 @@ this._inHook = false |
@@ -7,3 +7,6 @@ // @flow | ||
export type IHasForceUpdate = { | ||
export type IHasDisplayName = { | ||
displayName: string; | ||
} | ||
export type IHasForceUpdate = IHasDisplayName & { | ||
forceUpdate(): void; | ||
@@ -33,2 +36,3 @@ } | ||
selfUpdate?: (v: V) => void; | ||
pull?: (v: V) => void; | ||
willMount?: (v: V) => void; | ||
@@ -53,2 +57,3 @@ willUnmount?: (v: V) => void; | ||
trace: string; | ||
hook: ?INotifierItem; | ||
flush(): void; | ||
@@ -55,0 +60,0 @@ onError(e: Error, name: string, isHandled: boolean): void; |
@@ -9,4 +9,5 @@ // @flow | ||
export default class Notifier { | ||
logger: ?IGetable<ILogger> | ||
logger: ?IGetable<ILogger> = null | ||
Updater: Class<IControllable> | ||
hook: ?INotifierItem = null | ||
@@ -23,5 +24,9 @@ _consumers: INotifierItem[] = [] | ||
const ac = this._consumers | ||
this._consumers = ac.length | ||
? ac.concat(consumers) | ||
: consumers | ||
const hook = this.hook | ||
for (let i = 0, l = consumers.length; i < l; i++) { | ||
const consumer = consumers[i] | ||
if (consumer !== hook) { | ||
ac.push(consumer) | ||
} | ||
} | ||
if (this.logger) { | ||
@@ -28,0 +33,0 @@ this.logger.get().onSetValue({ |
@@ -66,2 +66,4 @@ // @flow | ||
reset(): void; | ||
pend(): void; | ||
error(error: Error): void; | ||
merge(v?: {[id: $Keys<V>]: mixed}): void; | ||
@@ -68,0 +70,0 @@ update(updaterPayload: IUpdater<any>): () => void; |
@@ -223,2 +223,10 @@ // @flow | ||
pend(): void { | ||
this.getStatus().merge({pending: true, complete: false, error: null}) | ||
} | ||
error(error: Error): void { | ||
this.getStatus().merge({pending: false, complete: false, error}) | ||
} | ||
reset(): void { | ||
@@ -230,2 +238,5 @@ if (!this.cached) { | ||
this.set(val) | ||
if (this.status) { | ||
this.status.reset() | ||
} | ||
} | ||
@@ -241,5 +252,2 @@ | ||
} | ||
if (this.status) { | ||
this.status.reset() | ||
} | ||
const computeds = this.computeds.items | ||
@@ -246,0 +254,0 @@ for (let i = 0, l = computeds.length; i < l; i++) { |
@@ -167,5 +167,4 @@ // @flow | ||
source.merge(v) | ||
} else { | ||
this._status.reset() | ||
} | ||
this._status.reset() | ||
this._promisable.resolve(v || this._v) | ||
@@ -172,0 +171,0 @@ notifier.opId = oldId |
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
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
370931
5168