@nkeff/cardboard-js
    Preparing search index...

    Function listState

    • listState creates a reactive list of values that can be used with tags to manage dynamic and reactive apps. It wraps each item with a State (aka. IObservable) to allow for individual item reactivity.

      Type Parameters

      • T

      Parameters

      • initialData: T[]

      Returns {
          add: (item: T) => void;
          addAt: (item: T, index: number) => void;
          length: IObservable<number>;
          remove: any;
          removeWhere: any;
          get list(): State<State<T>[]>;
          get listValue(): State<T>[];
      }

      • add: (item: T) => void
      • addAt: (item: T, index: number) => void
      • length: IObservable<number>
      • remove: any
      • removeWhere: any
      • get list(): State<State<T>[]>

        The reactive list of items. Each item is wrapped in a State to allow for individual reactivity.

      • get listValue(): State<T>[]

        The raw list of items.

      const myList = listState([1, 2, 3]);

      myList.add(4);
      myList.addAt(0, 0);
      myList.remove(2);
      myList.removeWhere(item => item === 3);
      const listValues = myList.listValue;
      const listLength = myList.length;

      // Listen to changes in the list
      myList.list.changed(() => {
      // List has changed
      });