-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: hydrate rows subscribed in listeners
- Loading branch information
Showing
17 changed files
with
130 additions
and
81 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
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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "amos-boxes", | ||
"version": "0.3.0-beta.32", | ||
"version": "0.3.0-beta.33", | ||
"private": true, | ||
"files": [] | ||
} |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "amos-core", | ||
"version": "0.3.0-beta.32", | ||
"version": "0.3.0-beta.33", | ||
"private": true, | ||
"files": [] | ||
} |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "amos-io", | ||
"version": "0.3.0-beta.32", | ||
"version": "0.3.0-beta.33", | ||
"private": true, | ||
"files": [] | ||
} |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "amos-persist", | ||
"version": "0.3.0-beta.32", | ||
"version": "0.3.0-beta.33", | ||
"private": true, | ||
"files": [] | ||
} |
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
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 |
---|---|---|
|
@@ -3,8 +3,8 @@ | |
* @author junbao <[email protected]> | ||
*/ | ||
|
||
import { Box, type Selectable, type Selector, StoreEnhancer } from 'amos-core'; | ||
import { append, isAmosObject, once, override, PartialRequired } from 'amos-utils'; | ||
import { Box, type Mutation, type Selectable, type Selector, StoreEnhancer } from 'amos-core'; | ||
import { append, isAmosObject, once, override, PartialRequired, StackObserver } from 'amos-utils'; | ||
import { createHydrate } from './hydrate'; | ||
import { createPersist } from './persist'; | ||
import { persistBox, type PersistState } from './state'; | ||
|
@@ -23,24 +23,19 @@ export function withPersist(options: PartialRequired<PersistOptions, 'storage'>) | |
const hydrate = createHydrate(store, finalOptions); | ||
const persist = createPersist(store, finalOptions); | ||
|
||
const selecting = new StackObserver(); | ||
const initial = new Map<string, any>(); | ||
|
||
const state: PersistState = { | ||
...finalOptions, | ||
selecting: false, | ||
init: once(async () => options.storage.init?.()), | ||
snapshot: new Map(), | ||
select: selecting.observe((s: any) => store.select(s)), | ||
getInitial: (box) => { | ||
if (initial.has(box.key)) { | ||
return initial.get(box.key); | ||
} | ||
const selecting = state.selecting; | ||
state.selecting = true; | ||
try { | ||
store.select(box); | ||
} finally { | ||
state.selecting = selecting; | ||
} | ||
state.select(box); | ||
return state.getInitial(box); | ||
}, | ||
hydrate, | ||
|
@@ -52,6 +47,21 @@ export function withPersist(options: PartialRequired<PersistOptions, 'storage'>) | |
initial.set(box.key, initialState); | ||
}); | ||
|
||
let dispatchingMutation = 0; | ||
override(store, 'dispatch', (dispatch) => { | ||
return (dispatchables: any) => { | ||
if (!isAmosObject<Mutation>(dispatchables, 'mutation')) { | ||
return dispatch(dispatchables); | ||
} | ||
try { | ||
dispatchingMutation++; | ||
return dispatch(dispatchables); | ||
} finally { | ||
dispatchingMutation--; | ||
} | ||
}; | ||
}); | ||
|
||
let selectingRows: PersistRowKey<any> | undefined = void 0; | ||
override(store, 'select', (select) => { | ||
return (selectable: any): any => { | ||
|
@@ -64,7 +74,7 @@ export function withPersist(options: PartialRequired<PersistOptions, 'storage'>) | |
} | ||
try { | ||
const r = select(selectable as Selectable); | ||
if (state.selecting) { | ||
if (selecting.count || dispatchingMutation) { | ||
return r; | ||
} | ||
// hydrate rows for multi-row boxes | ||
|
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
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
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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "amos-shapes", | ||
"version": "0.3.0-beta.32", | ||
"version": "0.3.0-beta.33", | ||
"private": true, | ||
"files": [] | ||
} |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "amos-testing", | ||
"version": "0.3.0-beta.32", | ||
"version": "0.3.0-beta.33", | ||
"private": true, | ||
"files": [] | ||
} |
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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "amos-utils", | ||
"version": "0.3.0-beta.32", | ||
"version": "0.3.0-beta.33", | ||
"private": true, | ||
"files": [] | ||
} |
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
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