boring-router
Advanced tools
Comparing version 0.4.1 to 0.4.2
@@ -31,4 +31,2 @@ "use strict"; | ||
this._reactiveEntrySet = new Set(); | ||
/** @internal */ | ||
this._reactiveDisposers = []; | ||
if (extension) { | ||
@@ -123,2 +121,3 @@ for (let key of Object.keys(extension)) { | ||
options, | ||
disposer: undefined, | ||
}; | ||
@@ -128,6 +127,10 @@ this._reactiveEntrySet.add(autorunEntry); | ||
_utils_1.tolerate(() => { | ||
this._reactiveDisposers.push(mobx_1.autorun(view, options)); | ||
autorunEntry.disposer = mobx_1.autorun(view, options); | ||
}); | ||
} | ||
return () => { | ||
if (autorunEntry.disposer) { | ||
autorunEntry.disposer(); | ||
autorunEntry.disposer = undefined; | ||
} | ||
this._reactiveEntrySet.delete(autorunEntry); | ||
@@ -142,2 +145,3 @@ }; | ||
options, | ||
disposer: undefined, | ||
}; | ||
@@ -147,6 +151,10 @@ this._reactiveEntrySet.add(reactionEntry); | ||
_utils_1.tolerate(() => { | ||
this._reactiveDisposers.push(mobx_1.reaction(expression, effect, options)); | ||
reactionEntry.disposer = mobx_1.reaction(expression, effect, options); | ||
}); | ||
} | ||
return () => { | ||
if (reactionEntry.disposer) { | ||
reactionEntry.disposer(); | ||
reactionEntry.disposer = undefined; | ||
} | ||
this._reactiveEntrySet.delete(reactionEntry); | ||
@@ -346,4 +354,7 @@ }; | ||
async _willLeave() { | ||
for (let reactiveDisposer of this._reactiveDisposers) { | ||
reactiveDisposer(); | ||
for (let reactiveEntry of this._reactiveEntrySet) { | ||
if (reactiveEntry.disposer) { | ||
reactiveEntry.disposer(); | ||
reactiveEntry.disposer = undefined; | ||
} | ||
} | ||
@@ -408,9 +419,13 @@ await Promise.all([ | ||
for (let reactiveEntry of this._reactiveEntrySet) { | ||
if (reactiveEntry.disposer) { | ||
reactiveEntry.disposer(); | ||
console.warn('Unexpected disposer during afterEnter phase.'); | ||
} | ||
_utils_1.tolerate(() => { | ||
switch (reactiveEntry.type) { | ||
case 'autorun': | ||
this._reactiveDisposers.push(mobx_1.autorun(reactiveEntry.view, reactiveEntry.options)); | ||
reactiveEntry.disposer = mobx_1.autorun(reactiveEntry.view, reactiveEntry.options); | ||
break; | ||
case 'reaction': | ||
this._reactiveDisposers.push(mobx_1.reaction(reactiveEntry.expression, reactiveEntry.effect, reactiveEntry.options)); | ||
reactiveEntry.disposer = mobx_1.reaction(reactiveEntry.expression, reactiveEntry.effect, reactiveEntry.options); | ||
break; | ||
@@ -417,0 +432,0 @@ } |
{ | ||
"name": "boring-router", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"description": "A type-safe MobX router with parallel routing support.", | ||
@@ -36,3 +36,3 @@ "repository": { | ||
}, | ||
"gitHead": "4320e9f308883bbbaa0be18f8ca76c70bd5fb30f" | ||
"gitHead": "173f09eb9e63b83706c0ecd798b22e4d9f4adfa2" | ||
} |
@@ -147,2 +147,3 @@ import { | ||
options: RouteAutorunOptions | undefined; | ||
disposer: RouteReactiveDisposer | undefined; | ||
} | ||
@@ -164,2 +165,3 @@ | ||
options: RouteReactionOptions | undefined; | ||
disposer: RouteReactiveDisposer | undefined; | ||
} | ||
@@ -301,5 +303,2 @@ | ||
/** @internal */ | ||
private _reactiveDisposers: RouteReactiveDisposer[] = []; | ||
/** @internal */ | ||
@observable | ||
@@ -459,2 +458,3 @@ private _service: IRouteService | undefined; | ||
options, | ||
disposer: undefined, | ||
}; | ||
@@ -466,3 +466,3 @@ | ||
tolerate(() => { | ||
this._reactiveDisposers.push(autorun(view, options)); | ||
autorunEntry.disposer = autorun(view, options); | ||
}); | ||
@@ -472,2 +472,7 @@ } | ||
return () => { | ||
if (autorunEntry.disposer) { | ||
autorunEntry.disposer(); | ||
autorunEntry.disposer = undefined; | ||
} | ||
this._reactiveEntrySet.delete(autorunEntry); | ||
@@ -487,3 +492,5 @@ }; | ||
options, | ||
disposer: undefined, | ||
}; | ||
this._reactiveEntrySet.add(reactionEntry); | ||
@@ -493,3 +500,3 @@ | ||
tolerate(() => { | ||
this._reactiveDisposers.push(reaction(expression, effect, options)); | ||
reactionEntry.disposer = reaction(expression, effect, options); | ||
}); | ||
@@ -499,2 +506,7 @@ } | ||
return () => { | ||
if (reactionEntry.disposer) { | ||
reactionEntry.disposer(); | ||
reactionEntry.disposer = undefined; | ||
} | ||
this._reactiveEntrySet.delete(reactionEntry); | ||
@@ -777,4 +789,7 @@ }; | ||
async _willLeave(): Promise<void> { | ||
for (let reactiveDisposer of this._reactiveDisposers) { | ||
reactiveDisposer(); | ||
for (let reactiveEntry of this._reactiveEntrySet) { | ||
if (reactiveEntry.disposer) { | ||
reactiveEntry.disposer(); | ||
reactiveEntry.disposer = undefined; | ||
} | ||
} | ||
@@ -864,16 +879,20 @@ | ||
for (let reactiveEntry of this._reactiveEntrySet) { | ||
if (reactiveEntry.disposer) { | ||
reactiveEntry.disposer(); | ||
console.warn('Unexpected disposer during afterEnter phase.'); | ||
} | ||
tolerate(() => { | ||
switch (reactiveEntry.type) { | ||
case 'autorun': | ||
this._reactiveDisposers.push( | ||
autorun(reactiveEntry.view, reactiveEntry.options), | ||
reactiveEntry.disposer = autorun( | ||
reactiveEntry.view, | ||
reactiveEntry.options, | ||
); | ||
break; | ||
case 'reaction': | ||
this._reactiveDisposers.push( | ||
reaction( | ||
reactiveEntry.expression, | ||
reactiveEntry.effect, | ||
reactiveEntry.options, | ||
), | ||
reactiveEntry.disposer = reaction( | ||
reactiveEntry.expression, | ||
reactiveEntry.effect, | ||
reactiveEntry.options, | ||
); | ||
@@ -880,0 +899,0 @@ break; |
Sorry, the diff of this file is not supported yet
203797
4396