Options
Menu

Class RealTimeNumber

This is a distributed number that wraps a native javascript number. It provides a few convenience functions for doing arithmetic and incrementing/decrementing.

See RealTimeNumberEvents for the events that can be emitted on remote changes to this object.

See the developer guide for the most common use cases.

Hierarchy

Implements

Index

Properties

Events

Events: RealTimeNumberEvents = ObservableNumberEventConstants

A mapping of the events this array could emit to each event's unique name. Use this to refer an event name, e.g.

rtNum.on(RealTimeNumber.Events.DELTA, function listener(e) {
  // ...
})

Methods

add

  • add(value: number): void
  • Adds the given number to this object's underlying number.

    rtNumber.value() // 13
    rtNumber.add(4)
    rtNumber.value() // 17
    

    On a successful add, a NumberDeltaEvent will be emitted for any remote users.

    Parameters

    • value: number

      the addend to be added

    Returns void

addListener

decrement

  • decrement(): void
  • Decrements the underlying number by 1. Equivalent to subtract(1)

    rtNumber.value() // 13
    rtNumber.decrement()
    rtNumber.value() // 12
    

    On a successful decrement, a NumberDeltaEvent will be emitted for any remote users.

    Returns void

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

increment

  • increment(): void
  • Increments the underlying number by 1. Equivalent to add(1)

    rtNumber.value() // 13
    rtNumber.increment()
    rtNumber.value() // 14
    

    On a successful increment, a NumberDeltaEvent will be emitted for any remote users.

    Returns void

isAttached

  • isAttached(): boolean

isDetached

  • isDetached(): boolean

model

off

on

once

parent

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

    • 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

subtract

  • subtract(value: number): void
  • Subtracts the given number from this object's underlying number.

    rtNumber.value() // 13
    rtNumber.subtract(4)
    rtNumber.value() // 9
    

    On a successful subtract, a NumberDeltaEvent will be emitted for any remote users.

    Parameters

    • value: number

      the subtrahend to be subtracted

    Returns void

toJSON

  • toJSON(): any

type

  • type(): string

value

  • value(): number
  • value(value: number): void