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 an IConsumable

    Type Parameters

    • T

    Parameters

    • initialData: T[]

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

    • add: ((item) => void)
        • (item): void
        • Parameters

          • item: T

          Returns void

    • addAt: ((item, index) => void)
        • (item, index): void
        • Parameters

          • item: T
          • index: number

          Returns void

    • length: IConsumable<number>
    • remove: any
    • removeWhere: any
    • get list(): IConsumable<IConsumable<T>[]>
    • get listValue(): IConsumable<T>[]

    See

    https://github.com/nombrekeff/cardboard-js/wiki/ListState

    Example

    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
    });

Generated using TypeDoc