Options
Menu

Class RealTimeElement<T>

This is an abstract representation of a particular node in a RealTimeModel's contents. If you think of the contents of a model as a JSON tree, this could be the root object, an array, or any other element. This provides utilities common to all data elements, like getting the element's value, a unique id, its path within the complete data tree, and much more.

See the developer guide for a more in-depth analysis of the potential types of data this could wrap.

Use value to get the current actual value of this element.

Type parameters

  • T

    The underlying javascript data type of this element. For instance, T would be number for a RealTimeNumber and string for a RealTimeString. This is the type that value returns.

Hierarchy

Implements

Index

Properties

StaticEvents

Events: RealTimeElementEvents = ObservableElementEventConstants

An interface enumerating the different events that could be fired on this RealTimeElement.

Methods

addListener

events

  • Provides the events emitted by this object as an Observable stream.

    example
    
    eventEmitter.events()
      .filter(e => e.name === "myevent")
      .subscribe(e => console.log(e));

    Returns Observable<IConvergenceEvent>

    An Observable stream of all events emitted by this object.

id

  • id(): string
  • Each node within a RealTimeModel has a system-generated ID that is unique within this model's contents.

    Returns string

    a unique (to the model) ID for this element

isAttached

  • isAttached(): boolean
  • True if the element is currently set up to synchronize with the server.

    Returns boolean

isDetached

  • isDetached(): boolean

model

off

on

once

parent

path

  • The Path representing this element's location in the containing model's data. For instance, with model data

    {
      user: {
        age: 32
      }
    }

    The RealTimeNumber representing 32 would have path ['user', 'age'].

    Returns Path

reference

  • Returns the remote ModelReference created by the given sessionId with the unique name key, or undefined if no such reference exists.

    See Remote References in the developer guide.

    Parameters

    • sessionId: string

      The session ID that created the reference

    • key: string

      the reference's unique key

    Returns ModelReference

references

  • Returns any remote references that match the given filter. You can provide a single key which could return references from multiple users, sessionId which would return all of a particular user session's references, or both, which is really just the same as using the reference method.

    Parameters

    • Optional referenceFilter: ReferenceFilter

      an object containing either a sessionId, key, or both

    Returns ModelReference[]

    An array of remote ModelReferences, or an empty array if there were no matches.

relativePath

  • This returns the PathElement representing this element's location relevant to its parent. For example, given a model with contents

    {
      obj: {
        with: 1,
        stuff: ['a', 'string']
      }
    }
    let rtNumber = rtModel.elementAt(['obj', 'with']);
    rtNumber.value() // 1
    rtNumber.relativePath() // 'with'
    
    let rtString = rtModel.elementAt(['obj', 'stuff', 0]);
    rtString.value() // 'a'
    rtString.relativePath() // 0

    Returns PathElement

    a PathElement representing this node's location relative to its parent, or null if it has no parent.

removeAllListeners

removeFromParent

  • removeFromParent(): void
  • A convenience function to delete this element. Throws an error if this is the root object in a model.

    Returns void

removeListener

removeListeners

toJSON

  • toJSON(): any

type

  • type(): string
  • This element's type. See [[ModelElementType]] for an enumeration of types.

    Returns string

value

  • value(): T
  • value(value: T): void