Error thrown when there isn't enough data to update local state automatically.
Removes all update listeners.
Extracts updates from the given resource and sends them to the appropriate listeners.
// on creation
rumour.share({
related: ['https://example.com/foos'], // collection URI
source: 'https://example.com/foos/0',
data: { foo: 'bar' },
});
// on update
rumour.share({
source: 'https://example.com/foos/0',
data: { foo: 'bar' }
});
// on deletion
rumour.share({
source: 'https://example.com/foos/0',
data: null
});
Resource metadata and contents.
Subscribes to updates, returning a function that you can call later to unsubscribe. Note that your listener will be notified of every update, even if it doesn't apply to your resource – be sure to call the update function provided as the first argument of the callback to see if there are any changes.
const unsubscribe = rumour.track(update => {
try {
const newResource = update(oldResource);
if (oldResource !== newResource) renderView(newResource);
} catch {
if (err instanceof Rumour.UpdateError) reloadFromServer();
}
});
// later in your code when you no longer need Rumour:
unsubscribe();
Function that will be called on every update.
Function that you can call to unsubscribe from updates.
Generated using TypeDoc
Rumour is a schemaless state manager for
application/hal+json
resources.Unlike many other state managers, Rumour neither stores a global state nor knows its structure – instead it links multiple local HAL+JSON states together and keeps them in sync.
To get started, subscribe your local state to Rumour updates using the
.track()
method, and then subscribe Rumour to the local state updates using the.share()
method. Rumour will run the callback function passed to.track()
whenever an update becomes available, and if that update applies to your local state, Rumour will recursively patch it on demand when you invokectx.update()
from the callback.If you no longer need to receive updates, remember to unsubscribe to avoid memory leaks (see
.track()
docs for more info).All updates are scoped to a Rumour instance, so if you share a resource to an instance, only its own trackers will be notified.