-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support merge cells' data. #189
Comments
Please have a review @zhengjianhui @PainterPuppets @Daryl-L |
For the
What about adding a new strategy:
If a path exists in multiple cells, only one cell will be updated |
Of cause, from this code set(value: any, paths?: StorePath) {
if (this.useLatest) {
// get the latest cell to update and add capacity from old cells
return
}
//if update all, merge all cells to a new cell
// if updating one key, find the cell and use updated data, if capacity is not enough maybe use other cells.
} There are three situations:
|
For the situation 2, does it mean |
yes. |
I have a problem when finding the cell to change when call set. Here is the test case: const store = new JSONStore<{ data: { a: string, b?: BigNumber, c?: { d: string } } }>({ data: true })
const outPointTmp = { txHash: `0x01${'0'.repeat(62)}`, index: '0x0'}
const updates = [
createUpdateParams({ data: store.initOnChain({ data: { a: 'a1', c: { d: 'd1' } }}).data, outPoint: defaultOutpoint }),
createUpdateParams({ data: store.initOnChain({ data: { a: 'a2' }}).data, outPoint: outPointTmp })
]
store.handleCall(updates[0])
store.handleCall(updates[1])
const changedStore = store.set(['data', 'c', 'd'], 'd2') From the cells' order, before calling Now my problem is how to find the keys that need to remove to update the cell's state. I have an idea to achieve it: // used to save the mergedState's value exist in which cells
protected mergeStatesLocation: Record<OutPointString, string[]> = {}
private mergeCellsData(current, last, outPointString) {
const useCurrentPaths = []
// mergeWith need to achieve by myself that can get current value's full path
const res = mergeWith((obj, src, paths) => {
if (Array.isArray(obj)) {
useCurrentPaths.push(paths)
return obj.concat(src)
}
if (isSimpleType(obj) && src !== undefined) {
useCurrentPaths.push(paths)
}
}, last, current)
this.mergeStatesLocation[outPointString] = useCurrentPaths
return res
}
set(value: any, paths?: StorePath) {
const outPointString = this.findByPaths(paths)
const allPaths = getAllPaths(this.states[outPointString])
// remove paths that are in allPaths but not in this.mergeStatesLocation[outPointString]
} But it seems too complex, do you have any suggestions to resolve it? @Keith-CY @PainterPuppets @Daryl-L @zhengjianhui |
Maybe there exists another way to resolve it, when I will update the cell by calling set, I can replace all the values on this cell from the set(value: any, paths?: StorePath) {
const outPointString = this.findByPaths(paths)
// it will ergodic
deepForIn(this.states[outPointString])((value, keys) => {
if(isSimpleType(value) && get(this.mergedState, keys)) {
set(this.states[outPointString], keys, get(this.mergedState, key))
}
})
set(this.states[outPointString], paths, value)
} |
I didn't get the point of
Why should
And the state to outsides is
The reason is that Say we change the
|
Of cause, before the state sends to the blockchain, the state is still
Then after the tx success, the merged state will be |
And if we should not remove |
Got it, any idea from @PainterPuppets @zhengjianhui @Daryl-L |
If no other feedback on the question above, the strategy to override the duplicated key will be adopted. |
For merging the cells' data in
Store
, I think we should consider the following things.lodash.merge
get
, developers can get with merged data or appointedOutputPoint
set
, developers can merge all cells or update appointedOutputPoint
In my mind, here is my design to achive these:
mergeState
inStore
mergeState
whenaddState
orremoveState
get
andset
support calls without deliveringOuputPoint
The text was updated successfully, but these errors were encountered: