Delay in milliseconds before model data actually unloaded after call to Model.unload
Static
INITSAdds a document to the collection, under an id subpath corresponding
to either the document's id
property if present, or else a new randomly
generated id.
If a callback is provided, it's called when the write is committed or fails.
Document to add
Optional
cb: ValueCallback<string>Optional callback
Adds a document to the collection, under an id subpath corresponding
to either the document's id
property if present, or else a new randomly
generated id.
If a callback is provided, it's called when the write is committed or fails.
Optional Collection under which to add the document
Document to add
Optional
cb: ValueCallback<string>Optional callback
Returns a child model where ShareDB operations are always composed.
Returns a ChildModel scoped to the root path.
Returns a ChildModel scoped to a relative subpath under this model's path.
Creates a new child model with a specific named data-loading context. The child model has the same scoped path as this model.
Contexts are used to track counts of fetches and subscribes, so that all data relating to a context can be unloaded all at once, without having to manually track loaded data.
Contexts are in a global namespace for each root model, so calling
model.context(contextId)
from two different places will return child
models that both refer to the same context.
context id
Optional
cb: ErrorCallbackOptional
cb: ErrorCallbackOptional
cb: ErrorCallbackOptional
cb: ErrorCallbackDeletes the value at this relative subpath.
If a callback is provided, it's called when the write is committed or fails.
the old value at the path
Deletes the value at this model's path.
If a callback is provided, it's called when the write is committed or fails.
Optional
cb: Callbackthe old value at the path
Optional
subpath: PathCall the function with the values at the input paths, returning the value
on completion. Unlike start
, this only occurs once and does not create
a listener for updating based on changes.
The function should be a pure function - it should always return the same result given the same inputs, and it should be side-effect free.
Retrieve data from the server, loading it into the model.
Items to fetch
Optional
cb: ErrorCallbackCallback called when operation completed
Retrieve data from the server, loading it into the model.
Item to fetch
Optional
cb: ErrorCallbackCallback called when operation completed
Retrieve data from the server, loading it into the model.
Optional
cb: ErrorCallbackCallback called when operation completed
Retrieve data from the server, loading it into the model.
Name of colleciton to load item to
Id of doc to load
Optional
callback: ErrorCallbackCallback called when operation completed
Promised version of Model.fetchDoc. Instead of a callback, returns a promise that is resolved when operation completed
Name of colleciton to load item to
Id of doc to load
Promised version of Model.fetch. Instead of a callback, returns a promise that is resolved when operation completed
Promised version of Model.fetch. Instead of a callback, returns a promise that is resolved when operation completed
Promised version of Model.fetch. Instead of a callback, returns a promise that is resolved when operation completed
Creates a live-updating list from items in an object, which results in automatically updating as the input items change.
Path pointing to an object or array. The path's value is retrieved via model.get(), and each item checked against filter function
Other parameters can be set in the model, and the filter function will be re-evaluated when these parameters change as well.
skip - The number of first results to skip limit - The maximum number of results. A limit of zero is equivalent to no limit.
A function or the name of a function defined via model.fn(). The function should have the arguments function(item, key, object, additionalInputs...)
Gets the value located at this model's path.
If no value exists at the path, this returns undefined
.
Note: The value is returned by reference, and object values should not be directly modified - use the Model mutator methods instead. The TypeScript compiler will enforce no direct modifications, but there are no runtime guards, which means JavaScript source code could still improperly make direct modifications.
Gets the value located at a relative subpath.
If no value exists at the path, this returns undefined
.
Note: The value is returned by reference, and object values should not be directly modified - use the Model mutator methods instead. The TypeScript compiler will enforce no direct modifications, but there are no runtime guards, which means JavaScript source code could still improperly make direct modifications.
Optional
subpath: PathGets a shallow copy of the value located at this model's path or a relative subpath.
If no value exists at the path, this returns undefined
.
Gets value at the path if not nullish, otherwise returns provided default value
Gets the value located at this model's path or a relative subpath.
If no value exists at the path, or the value is nullish (null or undefined), this will throw an error.
Gets array of values of collection at this model's path or relative subpath
If no values exist at subpath, an empty array is returned
Optional
subpath: PathOptional
value: numberOptional
value: numberOptional
cb: ErrorCallbackOptional
cb: ErrorCallbackCheck if subpath is a PathLike
boolean
Optional
cb: ErrorCallbackOptional
cb: ErrorCallbackOptional
cb: ErrorCallbackOptional
cb: ErrorCallbackListen to Racer events matching a certain path or path pattern.
pathPattern
is a path pattern that will filter emitted events, calling
the handler function only when a mutator matches the pattern.
Path patterns support a single segment wildcard '*'
anywhere in a path,
and a multi-segment wildcard '**'
at the end of the path. The
multi-segment wildcard alone '**'
matches all paths.
Examples of path patterns:
'notes.abc-123.author'
- Trigger on a direct modification to a
specific note's author
. Will not trigger if a sub-property of the
author is modified or if the entire note is replaced.notes.*.author
- Trigger on a direct modification to any note's
author
. Will not trigger if a sub-property of the author is modified
or if an entire note is replaced.notes.*.author.**
- Trigger on a modification to any note's author
or any sub-property of author
. Will not trigger if an entire note is
replaced.Listen to Racer events matching a certain path or path pattern, removing the listener after it gets triggered once.
Get full path to given subpath
Optional
subpath: PathLikePathLike subpath
Returns a child model where ShareDB operations are never composed.
Push a value to a model array
the length of the array
Push a value to a model array at subpath
Optional
cb: ErrorCallbackthe length of the array
Creates a reference for this model pointing to another path to
. Like a
symlink, any reads/writes on this to
ref will work as if they were done on
path
directly.
Location that the reference points to
a model scoped to path
Creates a reference at path
pointing to another path to
. Like a
symlink, any reads/writes on path
will work as if they were done on
path
directly.
Location at which to create the reference. This must be
under a local collection, typically '_page'
or a component model.
Location that the reference points to
Optional
options: RefOptionsa model scoped to path
Optional
options: RefListOptionsOptional
options: RefListOptionsCreates an array at outputPath
that consists of references to all the
objects at collectionPath
that have ids matching the ids at idsPath
.
The array is automatically updated based on changes to the input paths.
Path at which to create the ref list. This must be
under a local collection, typically '_page'
or a component model.
Path to a Racer collection or a collection-like
object, where each id string key maps to an object value with matching
id
property.
Path to an array of string ids
Optional
options: RefListOptionsOptional
Removes one or more items from the array at this model's path or a relative subpath.
If a callback is provided, it's called when the write is committed or fails.
array of the removed items
Optional
howMany: numberOptional
cb: CallbackRemoves a model reference.
Location of the reference to remove
Returns a ChildModel scoped to the root path.
ChildModel
Returns a ChildModel scoped to an absolute path.
Path of GhildModel to scope to
ChildModel
Optional
cb: ErrorCallbackOptional
cb: ErrorCallbackSets the array value at this model's path or a relative subpath, based on
a strict equality comparison (===
) between array items.
This only issues array insert, remove, and move operations.
If a callback is provided, it's called when the write is committed or fails.
the value previously at the path
Sets the array value at this model's path or a relative subpath, based on a deep equality comparison between array items.
This only issues array insert, remove, and move operations. Unlike
setDiffDeep
, this will never issue fine-grained ops inside of array
items.
If a callback is provided, it's called when the write is committed or fails.
the value previously at the path
Sets the value at this model's path or a relative subpath, if different
from the current value based on a strict equality comparison (===
).
If a callback is provided, it's called when the write is committed or fails.
the value previously at the path
Sets the value at this model's path or a relative subpath, if different from the current value based on a recursive deep equal comparison.
This attempts to issue fine-grained ops on subpaths if possible.
If a callback is provided, it's called when the write is committed or fails.
the value previously at the path
Optional
cb: ErrorCallbackOptional
cb: ErrorCallbackOptional
cb: ErrorCallbackOptional
cb: ErrorCallbackOptional
subpath: PathOptional
cb: ErrorCallbackCreates a live-updating list from items in an object, which results in automatically updating as the input items change. The results are sorted by ascending order (default) or by a provided 'fn' parameter.
Path pointing to an object or array. The path's value is retrieved via model.get(), and each item checked against filter function
Other parameters can be set in the model, and the filter function will be re-evaluated when these parameters change as well.
skip - The number of first results to skip limit - The maximum number of results. A limit of zero is equivalent to no limit.
A function or the name of a function defined via model.fn().
Call the function with the values at the input paths, writing the return value to the output path. In addition, whenever any of the input values change, re-invoke the function and set the new return value to the output path.
The function should be a pure function - it should always return the same result given the same inputs, and it should be side-effect free.
Optional
cb: ErrorCallbackOptional
cb: ErrorCallbackOptional
cb: ErrorCallbackOptional
cb: ErrorCallbackOptional
cb: ErrorCallbackRetrieve data from the server, loading it into the model. In addition, subscribe to the items, such that updates from any other client will automatically get reflected in this client's model.
Any item that's already subscribed will not result in a network call.
Item to subscribe to
Optional
cb: ErrorCallbackCallback called when operation completed
Retrieve data from the server, loading it into the model. In addition, subscribe to the items, such that updates from any other client will automatically get reflected in this client's model.
Any item that's already subscribed will not result in a network call.
Item to subscribe to
Optional
cb: ErrorCallbackCallback called when operation completed
Retrieve data from the server, loading it into the model. In addition, subscribe to the items, such that updates from any other client will automatically get reflected in this client's model.
Any item that's already subscribed will not result in a network call.
Optional
cb: ErrorCallbackCallback called when operation completed
Optional
callback: ErrorCallbackPromised version of Model.subscribe. Instead of a callback, returns a promise that is resolved when operation completed
Items to subscribe to
Promised version of Model.subscribe. Instead of a callback, returns a promise that is resolved when operation completed
Item to subscribe to
Promised version of Model.subscribe. Instead of a callback, returns a promise that is resolved when operation completed
Optional
cb: ErrorCallbackOptional
cb: ErrorCallbackThe reverse of Model.fetch, marking the items as no longer needed in the model.
Items to unfetch
Optional
cb: ErrorCallbackOptional Called after operation completed
The reverse of Model.fetch, marking the items as no longer needed in the model.
Item to unfetch
Optional
cb: ErrorCallbackOptional Called after operation completed
The reverse of Model.fetch, marking the items as no longer needed in the model.
Optional
cb: ErrorCallbackOptional Called after operation completed
Promised Model.unfetchDoc. Instead of taking a callback, returns a promise that is resolved when operation completed
Collection name
Document id to be unfeched
Promise
Promised unfetch. See Model.unfetch. Instead of a callback, returns a promise that is resolved when operation completed
Items to unfetch
Promise
Promised unfetch. See Model.unfetch. Instead of a callback, returns a promise that is resolved when operation completed
Item to unfetch
Promise
Promised Model.unfetch. Instead of taking a callback, returns a promise that is resolved when operation completed
Promise
Optional
cb: ErrorCallbackThe reverse of Model.subscribe, marking the items as no longer needed in the model.
The items to unsubscribe
Optional
cb: ErrorCallbackOptional Called after operation completed
The reverse of Model.subscribe, marking the items as no longer needed in the model.
The item to unsubscribe
Optional
cb: ErrorCallbackOptional Called after operation completed
The reverse of Model.subscribe, marking the items as no longer needed in the model.
Optional
cb: ErrorCallbackOptional Called after operation completed
Promised version of Model.unsubscribeDoc
Name of collection containting document
Document id to unsbscribe
Promised version of Model.unsubscribe. Instead of taking a callback, returns a promise that is resolved when operation completed
Optional
cb: ErrorCallback
RootModel is the model that holds all data and maintains connection info