Repository navigation
v10.2.0-beta.1
Pre-release
Pre-release
·
0 commits
to main
since this release
Keeping Deletions In JSON
A MergeableStore marks a Cell or Value that has been deleted with an undefined value in its MergeableContent and MergeableChanges. Plain JSON turns that into null, which is a valid Cell or Value, and so content serialized with JSON.stringify alone brought deleted Cells and Values back as null ones when it was set or merged into another MergeableStore. The new jsonStringWithUndefined function and jsonParseWithUndefined function keep them deleted:
import {
createMergeableStore,
jsonParseWithUndefined,
jsonStringWithUndefined,
} from 'tinybase';
const petStore = createMergeableStore();
petStore.setRow('pets', 'fido', {species: 'dog'}).delRow('pets', 'fido');
const petJson = jsonStringWithUndefined(petStore.getMergeableContent());
const restoredPetStore = createMergeableStore();
restoredPetStore.setMergeableContent(jsonParseWithUndefined(petJson));
console.log(restoredPetStore.getTables());
// -> {}They serialize undefined in the same way that TinyBase's own Persisters and Synchronizers do. The example of a custom Persister in the documentation of the createCustomPersister function now uses them too, since following it with a MergeableStore had the same problem.
Reliability And Hardening
- Deleting a
Metricnow tells its listeners that its value has gone, and deleting aRelationshipnow tells the listeners of each remoteRowId, set of localRowIds, and linked list that it had. Until now, neither called them, though deleting anIndexdid. - An
Index,Metric,Relationship, or query that is defined during a transaction now catches up with theStoreonce the transaction has finished. Until now, it kept what it saw when it was defined, even if the rest of the transaction then undid it - by changing it back, by being rolled back, or by throwing. - Going backward or forward through checkpoints during a transaction no longer records the move as a new change to the
Store. Any other change made in the same transaction is still recorded, after the checkpoint moved to. - A
CheckpointIdsListeneris now called once a transaction has finished, and only if the checkpointIdsare then different. Until now, a transaction that undid the changes pending since the last checkpoint while making another called it twice, forIdsthat had changed only for a moment. - A
Persisterthat loads content into aMergeableStorethat already has some now merges the two, rather than replacing what theMergeableStorehad. So a change made while loading, or any other that is newer than what was persisted, is kept. Likewise, data that thecreatePersisterForPathfunction of thecreateWsServerfunction adds to a server'sMergeableStoreis now merged with what is persisted, rather than overwritten.