如何撤消对数据库的未同步更改?
用例场景
我想让用户在他执行一个数据库操作后至少几秒钟内撤消数据库操作(即删除)的可能性。
一种可能性是保留从数据库中删除,直到撤消它的时间过去,但是我认为在代码中反映我将在 UI 中看到的内容会更加简化,只是为了保持 1:1 .
所以,我尝试在删除之前存储对象,然后更新它(这样_status
它就不会被删除了):
this.lastDeletedDoc = this.docs[this.lastDeletedDocIndex];
// remove from the db
this.documents.delete(docId)
.then(console.log.bind(console))
.catch(console.error.bind(console));
// ...
// user taps "UNDO"
this.documents.update(this.lastDeletedDoc)
.then(console.log.bind(console))
.catch(console.error.bind(console));
但我得到了错误Error: Record with id=65660f62-3eb1-47b7-8746-5d0b2ef44eeb not found
。
我还尝试使用以下方法再次创建对象:
// user taps "UNDO"
this.documents.create(this.lastDeletedDoc, { useRecordId: true })
.then(console.log.bind(console))
.catch(console.error.bind(console));
但我得到一个Id already present
错误。
我也快速浏览了源代码,但找不到任何undo
功能。
我通常如何撤消对未同步的 kinto 集合的更改?