Class RootModel

RootModel is the model that holds all data and maintains connection info

Hierarchy (view full)

Constructors

Properties

Methods

Constructors

Properties

backend: RacerBackend
bundleTimeout: number
ChildModel: typeof ChildModel = ChildModel
closePromised: Object
collections: ModelCollections
connection: Connection
data: ModelData
fetchOnly: boolean
removeAllFilters: Object
root: RootModel
unbundle: Object
unloadDelay: number

Delay in milliseconds before model data actually unloaded after call to Model.unload

INITS: ModelInitFunction[] = []

Methods

  • 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.

    Parameters

    • value: any

      Document to add

    • Optionalcb: ValueCallback<string>

      Optional callback

    Returns string

  • 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.

    Parameters

    • subpath: Path

      Optional Collection under which to add the document

    • value: any

      Document to add

    • Optionalcb: ValueCallback<string>

      Optional callback

    Returns string

  • Parameters

    • event: string
    • listener: any
    • Optionalarg2: any
    • Optionalarg3: any

    Returns any

  • 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.

    Parameters

    • contextId: string

      context id

    Returns ChildModel<ModelData>

  • Deletes the value at this relative subpath.

    If a callback is provided, it's called when the write is committed or fails.

    Type Parameters

    • S

      Type of the data returned by delete operation

    Parameters

    Returns S

    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.

    Type Parameters

    • T

      Type of the data returned by delete operation

    Parameters

    Returns T

    the old value at the path

  • Deletes the value at this relative subpath. If not provided deletes at model path

    Promise resolves when commit succeeds, rejected on commit failure.

    Parameters

    • Optionalsubpath: Path

      Optional subpath to delete

    Returns Promise<void>

    promise

  • Defines a named reactive function.

    It's not recommended to use this in most cases. Instead, to share reactive functions, have the components import a shared function to pass to model.start.

    Type Parameters

    • Ins extends unknown[]
    • Out

    Parameters

    • name: string

      name of the function to define

    • fn: ModelFn<Ins, Out>

      either a reactive function that accepts inputs and returns output, or a { get: Function; set: Function } object defining a two-way reactive function

    Returns void

    The use of named functions is deprecated. Instead, to share a reactive function, you should export it and then require/import it into each file that needs to use it.

  • 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.

    Returns Object

  • 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.

    Type Parameters

    • S

    Parameters

    • Optionalsubpath: Path

    Returns ReadonlyDeep<S>

  • Returns a reference to the ShareDB agent if it is connected directly on the server. Will return null if the ShareDB connection has been disconnected or if we are not in the same process and we do not have a reference to the server-side agent object

    Returns Agent<any>

  • Listen 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.

    Type Parameters

    • T extends
          | "load"
          | "insert"
          | "remove"
          | "move"
          | "change"
          | "unload"

    Parameters

    • eventType: T
    • pathPattern: PathLike
    • options: Object
    • listener: Object

    Returns Object

  • Parameters

    • eventType: "all"
    • pathPattern: PathLike
    • options: Object
    • listener: Object

    Returns Object

  • Type Parameters

    • T extends
          | "load"
          | "insert"
          | "remove"
          | "move"
          | "change"
          | "unload"

    Parameters

    • eventType: T
    • options: Object
    • listener: Object

    Returns Object

  • Parameters

    • eventType: "all"
    • options: Object
    • listener: Object

    Returns Object

  • Type Parameters

    • T extends
          | "changeImmediate"
          | "insertImmediate"
          | "removeImmediate"
          | "moveImmediate"
          | "loadImmediate"
          | "unloadImmediate"

    Parameters

    • eventType: T
    • listener: Object

    Returns Object

  • Parameters

    • eventType: "all"
    • listener: Object

    Returns Object

  • Parameters

    • eventType: "error"
    • listener: Object

    Returns Object

  • Listen to Racer events matching a certain path or path pattern, removing the listener after it gets triggered once.

    Type Parameters

    • T extends
          | "load"
          | "insert"
          | "remove"
          | "move"
          | "change"
          | "unload"

    Parameters

    • eventType: T
    • pathPattern: string
    • options: Object
    • listener: Object

    Returns Function

  • Type Parameters

    • T extends
          | "load"
          | "insert"
          | "remove"
          | "move"
          | "change"
          | "unload"

    Parameters

    • eventType: T
    • options: Object
    • listener: Object

    Returns Function

  • Get the parent {levels} up from current model or root model

    Parameters

    • Optionallevels: number

      number of levels to traverse the tree

    Returns Model<unknown>

    parent or root model

  • Passes data to event listeners

    Parameters

    • object: object

      An object whose properties will each be set on the passed argument

    • Optionalinvert: boolean

    Returns Model<ModelData>

    back a model scoped to the same path

  • Removes an item from the end of 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.

    Type Parameters

    • V

      type of data at subpath

    Parameters

    Returns V

    the removed item

  • Type Parameters

    • V extends never

    Parameters

    Returns V

  • 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.

    Type Parameters

    • V

    Parameters

    • subpath: Path

      Subpath to remove

    • index: number

      0-based index at which to start removing items

    • OptionalhowMany: number

      Number of items to remove. Defaults to 1.

    • Optionalcb: Callback

    Returns V[]

    array of the removed items

  • Type Parameters

    • V extends never

    Parameters

    • index: number
    • OptionalhowMany: number
    • Optionalcb: Callback

    Returns V[]

  • Parameters

    • eventType:
          | "load"
          | "insert"
          | "remove"
          | "move"
          | "change"
          | "unload"
          | "changeImmediate"
          | "insertImmediate"
          | "removeImmediate"
          | "moveImmediate"
          | "loadImmediate"
          | "unloadImmediate"
          | "all"
    • listener: Function

    Returns void

  • Sets 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.

    Type Parameters

    • S extends any[]

    Parameters

    Returns S

    the value previously at the path

  • Type Parameters

    Parameters

    • value: S

    Returns S

  • 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.

    Type Parameters

    • S extends any[]

    Parameters

    Returns S

    the value previously at the path

  • Type Parameters

    Parameters

    • value: S

    Returns S

  • 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.

    Type Parameters

    • S

    Parameters

    Returns ReadonlyDeep<S>

    the value previously at the path

  • Parameters

    Returns Object

  • 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.

    Type Parameters

    • Out
    • Ins extends unknown[]

    Parameters

    • outputPath: PathLike
    • inputPaths: PathLike[]
    • options: ModelStartOptions
    • fn: string | ModelFn<Ins, Out>

      a reactive function that accepts inputs and returns output; a { get: Function; set: Function } object defining a two-way reactive function; or the name of a function defined via model.fn()

    Returns Out

  • Type Parameters

    • Out
    • Ins extends unknown[]

    Parameters

    Returns Out

  • Unfetch a document give collection name and document id

    Parameters

    • collectionName: string

      Collection name

    • id: string

      Document id to be unfeched

    • Optionalcallback: Object

    Returns void

  • Unsubscribe document by collection name and id

    Parameters

    • collectionName: string

      Name of collection containting document

    • id: string

      Document id to unsubscribe

    • Optionalcallback: Object

      Optional Called after operation completed

    Returns void