-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update minimal effector version and fix bugs
- Loading branch information
1 parent
1a693de
commit e9213bb
Showing
3 changed files
with
39 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ export function getClientScope(values?: Values) { | |
if (!values) return _currentScope; | ||
|
||
HACK_injectValues(_currentScope, values); | ||
HACK_resetScopeRefs(_currentScope); | ||
HACK_updateScopeRefs(_currentScope, values); | ||
|
||
return _currentScope; | ||
} | ||
|
@@ -34,33 +34,36 @@ function HACK_injectValues(scope: Scope, values: Values) { | |
const oldValues = serialize(scope); | ||
|
||
// @ts-expect-error this is a really hacky way to "hydrate" scope | ||
if (scope.values) { | ||
/** | ||
* [email protected] and higher | ||
*/ | ||
scope.values.sidMap = { | ||
...oldValues, | ||
...values, | ||
}; | ||
} | ||
|
||
function HACK_updateScopeRefs(scope: Scope, values: Values) { | ||
const idSidMap = Object.fromEntries( | ||
// @ts-expect-error | ||
Object.entries(scope.sidIdMap).map(([sid, id]) => [id, sid]) | ||
); | ||
|
||
// @ts-expect-error | ||
for (const id in scope.reg) { | ||
// @ts-expect-error | ||
scope.values.sidMap = { | ||
...oldValues, | ||
...values, | ||
const ref = scope.reg[id]; | ||
if (!ref.meta || ref.meta?.derived) { | ||
/** | ||
* Force recalculation of derived values | ||
*/ | ||
// @ts-expect-error | ||
delete scope.reg[id]; | ||
} else { | ||
/** | ||
* Update non-derived values | ||
*/ | ||
const sid = idSidMap[id]; | ||
if (sid && sid in values) { | ||
ref.current = values[sid]; | ||
} | ||
} | ||
} else { | ||
/** | ||
* effector before 22.8.0 | ||
*/ | ||
// @ts-expect-error this is a really hacky way to "hydrate" scope | ||
scope.sidValuesMap = { | ||
...oldValues, | ||
...values, | ||
}; | ||
} | ||
} | ||
|
||
function HACK_resetScopeRefs(scope: Scope) { | ||
/** | ||
* Kind of equal to proposed fork(scope) behaviour | ||
*/ | ||
// @ts-expect-error hacky way to reset state refs owned by this scope | ||
scope.reg = {}; | ||
// @ts-expect-error hacky way to reset state refs owned by this scope | ||
scope.sidIdMap = {}; | ||
} |