Skip to content

Collections

Bertrand Laporte edited this page Jan 11, 2019 · 7 revisions

Hibe supports 2 kinds of observable collections: JS Arrays and Maps

Arrays

Hibe Arrays (identified through @datalist()) allow to track changes in array collections indexed by numbers (aka. Lists :-)). Hibe automatically creates a proxy object to track item changes. All JS Array methods are supported as the hibe proxy is fully transparent.

@Dataset()
export class Record {
    @value() name = "";
}

@Dataset()
export class ListSamples {
    @datalist(String) list1: string[];                   // list of strings
    @datalist(Record) list2: Record[];                   // list of Record datasets
    @datalist(list(Record)) list3: Record[][];           // list of list of Record datasets
    @datalist(list(list(Record))) list3: Record[][][];   // list of list of list of Record datasets
}

Maps

Hibe also support Map collections based on JavaScript Maps (cf. @datamap()). Like for Arrays, hibe automatically creates a JS Proxy to track map and map item changes.

@Dataset()
export class MapSamples {
    @datamap(String) map1: Map<string,string>;                            // map of strings
    @datamap(Record) map2: Map<string,string>;                            // map of Record datasets
    @datamap(map(Record)) map3: Map<string,Map<string,Record>>;           // map of map of Record datasets
    @datamap(list(map(Record))) map4: Map<string,Map<string,Record>[]>;   // map of list of map of Records
}

Clone this wiki locally