Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Subscribers

Hierarchy

  • Map
    • Subscribers

Implements

Index

Constructors

constructor

Properties

delete$s

delete$s: Subject<string> = new Subject<MapName>()

Subject than can be used to delete an element by sending the key of the element to delete.

obs$

obs$: Observable<MapState>

An observable on the contained data.

Example:

const s = new State<number>(0)
s.obs$.filter(v => v%2==0 ).subscribe(stateContent => console.dir(stateContent))

set$s

set$s: Subject<object> = new Subject<MapSetMessage>()

Subject that can be used to set a new element value by sending a MapSetMessage into.

unregister

unregister: delete = this.delete

Accessors

length$

  • get length$(): Observable<number>
  • return an Observable of the length

    Returns Observable<number>

updater$s

  • Property to retrieve a subject to be used to update the content.

    Examples:

    The following add a value to the content of a State that contain a list of number. Subscribers will receive updates. (see update for an example with more explanations)

    const s = new State<number[]>([1])
    s.obs$.subscribe(stateContent => console.dir(stateContent))
    const append => newVal => stateContent => [...stateContent, newVal]
    s.updater$s.next(append(2)); // see below the update syntax shortcut.

    It is also possible to directly set the state instead of passing a function updating the state

    const s = new State<number[]>([1])
    s.obs$.subscribe(stateContent => console.dir(stateContent))
    s.updater$s.next([3,4,5])

    In some case it is not required have any initial value

    const s = new State<number>() // no initial value
    s.obs$.subscribe(stateContent => console.dir(stateContent)) // triggered with a 1 second delay
    setTimeout(() => s.update(1), 1000) // delay the update

    Returns PartialObserver<StateUpdateFn<MapState> | MapState>

    A subject for updating the content.

    Remark: The returned observer is partial and will ignore error and complete messages.

Methods

delete

  • remove an element from the map.

    Parameters

    • name: MapName

      key of the data todelete

    Returns void

flush

  • flush(): void
  • remove all element from the map.

    Returns void

get$

  • retrieve an element. This function tries to return the value associated to the name key

    Parameters

    • name: MapName

      key of the data to retrieve

    Returns MapData

getOr$

  • retrieve an element with default value.

    This function tries to return the value associated to the name key or otherwise return the default value defValue.

    Parameters

    • defValue: MapData

      the default value to be returned

    • name: MapName

      key of the data to retrieve

    Returns MapData

    an observable on the data found.

isSet$

  • isSet$(name: MapName): Observable<Boolean>
  • check if an element exist.

    Parameters

    • name: MapName

      key of the data to check

    Returns Observable<Boolean>

    an boolean observable indicating whetever the element exists or not.

register$1

  • register$1<T>(name: string, cb: function): Observable<boolean>
  • Type parameters

    • T: __type

    Parameters

    • name: string
    • cb: function
        • (state: T): void
        • Parameters

          • state: T

          Returns void

    Returns Observable<boolean>

set

  • Set an element value

    Parameters

    • name: MapName

      key of the data to update in the Map;

    • data: MapData

      the new element value.

    Returns void

update

  • Method to be used to update the content.

    Example 1:

    The following add a value to the content of a State that contain a list of number. Subscribers will receive updates.

    // Create a state with an initial value
    const s = new State<number[]>([1])
    
    // Subscribe to the state
    s.obs$.subscribe(stateContent => console.dir(stateContent))
    
    // transformation function that append a value at the end of an array and
    // return the new array.
    const append => newVal => stateContent => {return [...stateContent, newVal]}
    
    // Append 2 at the end of the array contained in the state s.
    // (Subscribers, like above will be triggered)
    s.update(append(2))

    Example 2:

    The following set the content of a State that contain a list of number. Subscribers will receive updates.

    // Create a state with an initial value
    const s = new State<number[]>([1])
    
    // Subscribe to the state
    s.obs$.subscribe(stateContent => console.dir(stateContent))
    
    // Set the new array contained in the state s.
    // (Subscribers, like above will be triggered)
    s.update([3,4])

    Example 3:

    The following exemple create a state without initial value. Later the content is set and latter it is updated

    // Create a state with an initial value
    
    const s = new State<number[]>()
    
    // Subscribe to the state
    s.obs$.subscribe(stateContent => console.dir(stateContent))
    
    // transformation function that append a value at the end of an array and
    // return the new array.
    const append => newVal => stateContent => [...stateContent, newVal]
    
    // Set an initial value
    // Set the new array contained in the state s.
    // (Subscribers, like above will be triggered)
    s.update([1])
    
    // Update the content by adding a value to the list
    // Set the new array contained in the state s.
    // (Subscribers, like above will be triggered)
    s.update(append(2));

    Parameters

    • fn: StateUpdateFn<MapState> | MapState

      A transformation function that takes as argument the current data of the state and return the updated data.

    Returns void

    nothing

Generated using TypeDoc