This repository has been archived on 2024-02-11. You can view files and clone it, but cannot push or open issues or pull requests.
sitio/x/SyncedStore.md
Cat /dev/Nulo cc6091c7a0
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
oops
2023-11-11 23:37:38 -10:00

660 B

Gotchas

Sadly, SyncedStore has a ton of gotchas that, due to the nature of the types that it has, TypeScript can't catch.

Array items don't exist after being removed

let normalArray = [{ a: "a" }, { b: "b" }, { c: "c" }];
const item = normalArray[1]; // is {b:'b'}
normalArray.splice(2);
item; // is still {b:'b'}

while in SyncedStore land...

const anormalArray = $store.array;
const item = anormalArray[1]; // is {b:'b'}
anormalArray.splice(2);
item; // is undefined :(

Workaround by creating a new object:

const item = { ...anormalArray[1] };
// although if you have object or array children it may still break...