mirror of
https://github.com/umap-project/umap.git
synced 2025-04-28 19:42:36 +02:00
48 lines
735 B
JavaScript
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) {}
|
|
}
|