npm add [email protected]
This release adds numerous quality-of-life API improvements. Though there are technically breaking changes, you are unlikely to encounter them.
tx.get()
and tx.scan()
now accept an optional type parameter:
// before:
(await tx.get("foo")) as Todo|undefined
(await tx.scan().toArray()) as Todo[]
// now:
await tx.get<Todo>("foo");
await tx.scan<Todo>.toArray();
push()
and pull()
now support an optional now: true
argument:
r.push({now: true});
r.pull({now: true});
This bypasses all debouncing and runs the push/pull immediately.
push()
and pull()
now return a Promise
. The promise resolves if the next push/pull succeeds, and rejects otherwise.
try {
await r.push();
console.log("yay, push succeeded!");
} catch {
console.error("boo, push failed");
}
Replicache.subscribe
now supports an isEqual
option to implement custom comparison of results. The default implementation is deepEqual
, which is what it has always been.
r.subscribe(
tx => new Map(...await getMapData(tx)), {
isEqual: (a, b) => a === b,
}
);
Replicache.subscribe
now allows passing a bare callback function directly to the second parameter, rather than wrapping in an options
object:
// before:
r.subscribe(tx => tx.get("foo"), { onData: val => console.log(val) });
// now:
r.subscribe(tx => tx.get("foo"), val => console.log(val));
tx.put()
has been renamed to tx.set()
for consistency with ES6 Map
. tx.put()
remains but is deprecated.
// before:
tx.put("foo", "bar");
// now:
tx.set("foo", "bar");
Replicache.clientID
is now synchronous, not asynchronous.
// before:
console.log(await r.clientID);
// now:
console.log(r.clientID);
Note that await r.clientID
will still work since it’s fine to await
anything in JavaScript. It just doesn’t do anything.
tx.environment
renamed to tx.location
to avoid confusion with environment variables.
// before:
launchMissles: tx => {
if (tx.environment === 'server') {
// check auth
}
...
}
// now:
if (tx.location === 'server')
The old field name remains but is deprecated.