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 }) {
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() {

View file

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

View file

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