UmbArrayState

  • A RxJS BehaviorSubject which deepFreezes the object-data to ensure its not manipulated from any implementations. Additionally the Subject ensures the data is unique, not updating any Observes unless there is an actual change of the content.

The ArrayState provides methods to append data when the data is an Object.

Type Parameters

  • T

Hierarchy (View Summary, Expand)

Constructors

Properties

_subject: BehaviorSubject<T[]>
getUniqueMethod: (entry: T) => unknown

Accessors

  • get value(): T

    Returns T

    Observable that

    • Holds the current data of this state.
    const myState = new UmbArrayState('Hello world');
    console.log("Value is: ", myState.value);

Methods

  • Parameters

    • entries: T[]

      A array of new data to be added in this Subject.

    Returns UmbArrayState<T>

    Reference to it self.

    append

    • Append some new data to this Subject, if it compares to existing data it will replace it.
    const data = [
    { key: 1, value: 'foo'},
    { key: 2, value: 'bar'}
    ];
    const myState = new UmbArrayState(data);
    myState.append([
    { key: 1, value: 'replaced-foo'},
    { key: 3, value: 'another-bla'}
    ]);
  • Parameters

    • entry: T

      new data to be added in this Subject.

    Returns UmbArrayState<T>

    Reference to it self.

    appendOne

    • Append some new data to this Subject.
    const data = [
    { key: 1, value: 'foo'},
    { key: 2, value: 'bar'}
    ];
    const myState = new UmbArrayState(data);
    myState.append({ key: 1, value: 'replaced-foo'});
  • Parameters

    • entry: T

      new data to be added in this Subject.

    • index: number

      index of where to append this data into the Subject.

    Returns UmbArrayState<T>

    Reference to it self.

    appendOneAt

    • Append some new data to this Subject.
    const data = [
    { key: 1, value: 'foo'},
    { key: 3, value: 'bar'}
    ];
    const myState = new UmbArrayState(data);
    myState.appendOneAt({ key: 2, value: 'in-between'}, 1);
  • Returns Observable<T[]>

    Observable that the State casts to.

    asObservable

    • Creates a new Observable with this State as the source. Observe this to subscribe to its value and future changes.
    const myState = new UmbArrayState('Hello world');

    this.observe(myState, (latestStateValue) => console.log("Value is: ", latestStateValue));
  • Parameters

    • predicate: (value: T, index: number, array: T[]) => boolean

    Returns UmbArrayState<T>

    Reference to it self.

    filter

    • Remove some new data of this Subject.
    const data = [
    { key: 1, value: 'foo'},
    { key: 2, value: 'bar'},
    { key: 3, value: 'poo'}
    ];
    const myState = new UmbArrayState(data, (x) => x.key);
    myState.filter((entry) => entry.key !== 1);

    Result:
    [
    { key: 2, value: 'bar'},
    { key: 3, value: 'poo'}
    ]
  • Returns T[]

    The current data of this state.

    getValue

    • Provides the current data of this state.
    const myState = new UmbArrayState('Hello world');
    console.log("Value is: ", myState.value);
  • Parameters

    • uniques: unknown[]

      The unique values to remove.

    Returns UmbArrayState<T>

    Reference to it self.

    remove

    • Remove some new data of this Subject.
    const data = [
    { id: 1, value: 'foo'},
    { id: 2, value: 'bar'}
    ];
    const myState = new UmbArrayState(data, (x) => x.id);
    myState.remove([1, 2]);
  • Parameters

    • unique: unknown

      The unique value to remove.

    Returns UmbArrayState<T>

    Reference to it self.

    removeOne

    • Remove some new data of this Subject.
    const data = [
    { id: 1, value: 'foo'},
    { id: 2, value: 'bar'}
    ];
    const myState = new UmbArrayState(data, (x) => x.id);
    myState.removeOne(1);
  • Parameters

    • value: T[]

    Returns void

    setValue

    • Set the data of this state, if sortBy has been defined for this state the data will be sorted before set. If data is different than current this will trigger observations to update.
    const myState = new UmbArrayState('Good morning');
    // myState.value is equal 'Good morning'.
    myState.setValue('Goodnight')
    // myState.value is equal 'Goodnight'.
  • Parameters

    • OptionalsortMethod: (a: T, b: T) => number

      A method to be used for sorting every time data is set.

    Returns UmbArrayState<T>

    Reference to it self.

    sortBy

    • A sort method to this Subject.
    const data = [
    { key: 1, value: 'foo'},
    { key: 2, value: 'bar'}
    ];
    const myState = new UmbArrayState(data, (x) => x.key);
    myState.sortBy((a, b) => (a.sortOrder || 0) - (b.sortOrder || 0));
  • Parameters

    • unique: unknown

      Unique value to find entry to update.

    • entry: Partial<T>

      new data to be added in this Subject.

    Returns UmbArrayState<T>

    Reference to it self.

    updateOne

    • Update a item with some new data, requires the ArrayState to be constructed with a getUnique method.
    const data = [
    { key: 1, value: 'foo'},
    { key: 2, value: 'bar'}
    ];
    const myState = new UmbArrayState(data, (x) => x.key);
    myState.updateOne(2, {value: 'updated-bar'});
MMNEPVFCICPMFPCPTTAAATR