Skip to content

Collections

Bertrand Laporte edited this page Jul 27, 2018 · 7 revisions

Hibe supports 2 kinds of observable collections: List and Dictionary

List

List factory

Lists must be created through a call to the hList factory which allows to support any level of nested lists

let list = hList(TestNode)(); // List of TestNodes
let list2 = hList(hList(TestNode))(); // List of list of TestNodes
// note: lists are datasets
console.log(isDataset(list)); // print true

List API

List provide a subset of the JavaScript Array API. Most notable difference is that items must be accessed through get() and set() methods instead of [] accessors.

interface List<T> {
    length: number;
    set(index: number, item: T | null): T | null;
    get(index: number): T | null;
    newItem(index?: number): T;
    push(...items: T[]): void;
    forEach(cb: (item: T, index?: number, dataList?: List<T>) => void, cbThis?): void;
    filter(cb: (item: T, index?: number, dataList?: List<T>) => boolean, cbThis?): T[];
    filterItems(cb: (item: T, index?: number, dataList?: List<T>) => boolean, cbThis?): this;
    indexOf(searchElement: any, fromIndex?: number): number;
    splice(start: number, deleteCount: number | undefined, ...items: T[]): void;
    toArray(): T[];
    toString(): string;
    dispose(): T[];
}

Clone this wiki locally