umap/umap/static/umap/js/modules/saving.js
2024-10-30 17:14:35 +01:00

48 lines
735 B
JavaScript

const _queue = new Set()
export let isDirty = false
export async function save() {
for (const obj of _queue) {
const ok = await obj.save()
if (!ok) break
remove(obj)
}
}
export function add(obj) {
_queue.add(obj)
_onUpdate()
}
export function remove(obj) {
_queue.delete(obj)
_onUpdate()
}
export function has(obj) {
return _queue.has(obj)
}
function _onUpdate() {
console.log(_queue)
isDirty = Boolean(_queue.size)
document.body.classList.toggle('umap-is-dirty', isDirty)
}
export class ServerStored {
set isDirty(status) {
if (status) {
add(this)
} else {
remove(this)
}
this.onDirty(status)
}
get isDirty() {
return has(this)
}
onDirty(status) {}
}