-
Notifications
You must be signed in to change notification settings - Fork 2
Home
hibe is library to create immutable data objects through a 'mutable' api
Core concepts are explained in the main readme file. The present pages give a more detailed presentation of the APIs exposed to the developers
Tell if an object is being mutated
Tell if an object is immutable (i.e. if it has already been mutated and cannot be mutated again, in which case lastVersion() should be called to retrieve a mutable version)
Tell if an object is a dataset
Return the latest version of an object (note: this is not necessarily the immediate next version). Latest version is always mutable.
Return a promise that will be fulfilled when the mutation of the dataset passes as argument is completed (or immediately if the dataset is not being mutated). The result of the promise is the latest version of the dataset
@Dataset
class TestNode {
@string() value;
}
let o = new TestNode();
console.log(isMutating(o)); // print false
console.log(isDataset(o)); // print true
o.value = "foo";
console.log(isMutating(o)); // print true
console.log(isImmutable(o)); // print false
let o2 = await mutationComplete(o);
console.log(isImmutable(o)); // print true
console.log(isMutating(o)); // print false
console.log(isMutating(o2)); // print false
console.log(lastVersion(o) === o2); // print trueRegister a callback that will be called when a new version of a given dataset is spawn. The same callback will be called for any subsequent version (no need to re-register) - until unwatch() is called
Unregister a watch callback
let node = initNewArrTestNode();
let watchRef = watch(node, (newNode) => {
node = newNode;
// do something - e.g. UI refresh
});
unwatch(node, watchRef);