The GitHub repository (github.com/Alpaq92/Riposte) is gone with the suspended account. These are the files npm installed for ReaderJS from commit 307ef7dfd9c5e8c0c07a840874e013cf94a85ada, so this is that commit's packaged content, without its history. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
24 lines
1.0 KiB
JavaScript
24 lines
1.0 KiB
JavaScript
// engine/save.js
|
|
// Helpers for save/restore — lazy copy-on-write snapshots of composite storage.
|
|
// We key snapshots by the BACKING store (array / Uint8Array) or the PSDict, so
|
|
// that windows sharing a backing are restored together and in place (sibling
|
|
// getinterval views see the rollback).
|
|
import { PSString, PSDict } from './object.js';
|
|
|
|
export function mutationKey(comp) {
|
|
return comp instanceof PSDict ? comp : comp.backing;
|
|
}
|
|
|
|
export function snapshotBacking(comp) {
|
|
if (comp instanceof PSDict) return { kind: 'dict', dict: comp, copy: new Map(comp.map) };
|
|
return { kind: comp instanceof PSString ? 'string' : 'array', backing: comp.backing, copy: comp.backing.slice() };
|
|
}
|
|
|
|
export function restoreBacking(b) {
|
|
if (b.kind === 'dict') { b.dict.map = b.copy; return; }
|
|
if (b.kind === 'string') { b.backing.set(b.copy); return; }
|
|
const back = b.backing, copy = b.copy; // array: restore contents in place
|
|
back.length = copy.length;
|
|
for (let i = 0; i < copy.length; i++) back[i] = copy[i];
|
|
}
|