How to combine entities's history? #384
Answered
by
EricPoul
toadfanszz
asked this question in
Q&A
-
Thank you for the awesome lib! I'm implement a database system. And my question is about Here is the store.// Sheet has many rows, and I want to manage row history via sheet.
const sheetsStore = createStore(
{ name: "sheet" },
withEntities<{id: string, rowIds: string[]}>(),
withRowsEntities<{id: string, data: string}>()
)
export const sheetsStateHistory = entitiesStateHistory(sheetsStore)
export const rowsStateHistory = entitiesStateHistory(sheetsStore, { entitiesRef: rowsEntitiesRef }) 1.// add row entity and update sheet entity in one transaction
sheetsStore.update(
updateEntities('sheet1', {rowIds: ["row1"]}),
addEntities({id: 'row1', data: 'first'}, { ref: rowsEntitiesRef })
)
// rollback the transaction, but row entity is still exist.
sheetsStateHistory.undo("sheet1") Is there something like 2.sheetsStore.update(
updateEntities('row1', {data: 'second'}),
)
// Is there a way to undo the above transaction via sheetId?
sheetsStateHistory.undo("sheet1") Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Answered by
EricPoul
Nov 22, 2022
Replies: 2 comments
-
@EricPoul can you help him please? |
Beta Was this translation helpful? Give feedback.
0 replies
-
@clszzyh
sheetsStateHistory.undo("sheet1");
rowsStateHistory.undo("row1");
sheetsStore.update(
updateEntities('row1', {data: 'second'}),
)
const sheetRows = sheetStore.query(getEntity("sheet1")).rowIds;
if (sheetRows.includes("row1")) {
rowsStateHistory.undo("row1");
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
toadfanszz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@clszzyh
undo
both of them independently:entityStateHistory
. But I guess you can do next: