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

Hibe lists allow to track changes in item collections indexed by numbers (aka. Lists :-))

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. Note: new items can be directly created through a call to the newItem() method

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[];
}

Dictionary

Hibe dictionaries allow to track changes in item collections indexed by strings

Dictionary factory

Dictionaries must be created through a call to the hDictionary factory which allows to support any level of nested dictionaries & lists

let d = hDictionary(TestNode)(); // Dictionary of TestNodes
let d2 = hDictionary(hList(TestNode))(); // Dictionary of list of TestNodes
// note: dictionaries are datasets
console.log(isDataset(d)); // print true

List API

Dictionary provide an API similar to Java dictionaries. Note: new items can be directly created through a call to the newItem() method

interface Dictionary<T> {
    size: number;
    isEmpty: boolean;
    keys: string[];
    newItem(key: string): T;
    put(key: string, item: T | null): T | null;
    get(key: string): T | null;
    remove(key: string): void;
    toObject(): {};
    toString(): string;
    dispose(): {};
}

Clone this wiki locally