wip: allow to mark an operation as not undoable

Co-authored-by: David Larlet <david@larlet.fr>
This commit is contained in:
Yohan Boniface 2025-03-21 16:33:09 +01:00
parent 88382ab00b
commit 9718f11faf
3 changed files with 12 additions and 11 deletions

View file

@ -1098,7 +1098,11 @@ export class DataLayer extends ServerStored {
setReferenceVersion({ response, sync }) { setReferenceVersion({ response, sync }) {
this._referenceVersion = response.headers.get('X-Datalayer-Version') this._referenceVersion = response.headers.get('X-Datalayer-Version')
if (sync) this.sync.update('_referenceVersion', this._referenceVersion) if (sync) {
this.sync.update('_referenceVersion', this._referenceVersion, null, {
undo: false,
})
}
} }
async save() { async save() {

View file

@ -169,7 +169,7 @@ export class SyncEngine {
this._send(operation) this._send(operation)
} }
update(subject, metadata, key, value, oldValue) { update(subject, metadata, key, value, oldValue, { undo } = { undo: true }) {
const operation = { const operation = {
verb: 'update', verb: 'update',
subject, subject,
@ -186,7 +186,7 @@ export class SyncEngine {
this._batch.push(stage) this._batch.push(stage)
return return
} }
this._undoManager.add(stage) if (undo) this._undoManager.add(stage)
this._send(operation) this._send(operation)
} }
@ -211,7 +211,7 @@ export class SyncEngine {
async save() { async save() {
const needSave = new Map() const needSave = new Map()
if (!this._umap.id) { if (!this._umap.id) {
// There is no operation for fist map save // There is no operation for first map save
needSave.set(this._umap, []) needSave.set(this._umap, [])
} }
for (const operation of this._operations.sorted()) { for (const operation of this._operations.sorted()) {

View file

@ -35,13 +35,10 @@ export class UndoManager {
} }
add(stage) { add(stage) {
// FIXME make it more generic stage.operation.dirty = true
if (!stage.operation || stage.operation.key !== '_referenceVersion') { this._redoStack = []
stage.operation.dirty = true this._undoStack.push(stage)
this._redoStack = [] this.toggleState()
this._undoStack.push(stage)
this.toggleState()
}
} }
copyOperation(stage, redo) { copyOperation(stage, redo) {