castle-web-sdk 0.4.21 → 0.4.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/storage.js +8 -4
- package/package.json +1 -1
package/dist/storage.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { CastleError } from "./errors";
|
|
2
2
|
import { hostRequest } from "./transport";
|
|
3
|
-
|
|
3
|
+
// The child coalesces writes -- a frame can set the same key many times -- and
|
|
4
|
+
// hands them to the host on this interval. The host, not the deck, talks to the
|
|
5
|
+
// server and owns retry: it lives in the page, so it is still alive to finish a
|
|
6
|
+
// write while the deck's frame is being torn down.
|
|
7
|
+
const FLUSH_INTERVAL_MS = 200;
|
|
4
8
|
// Per-player private storage. The host stamps deckId/sessionId, so one deck
|
|
5
9
|
// session = one stable blob: load once, then serve reads from cache and batch
|
|
6
10
|
// writes on a 2s flush. Dirty writes overlay the server blob so an in-flight
|
|
@@ -42,13 +46,13 @@ class PrivateStorageImpl {
|
|
|
42
46
|
if (this.dirty.size === 0)
|
|
43
47
|
return;
|
|
44
48
|
const snapshot = new Map(this.dirty);
|
|
45
|
-
|
|
49
|
+
await hostRequest("deckStorage.update", {
|
|
46
50
|
updates: updatesFromDirty(snapshot),
|
|
47
51
|
unload,
|
|
48
52
|
});
|
|
49
|
-
|
|
53
|
+
// Staged, not stored: the host has taken ownership, so these stop being the
|
|
54
|
+
// deck's problem. `cache` already carries them from the write.
|
|
50
55
|
clearAcknowledgedDirty(this.dirty, snapshot);
|
|
51
|
-
this.overlayDirty();
|
|
52
56
|
}
|
|
53
57
|
overlayDirty() {
|
|
54
58
|
for (const [key, encoded] of this.dirty) {
|