Skip to content

Collections

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

Hibe supports two kind of collections: JS Arrays and Maps

Arrays

Hibe Arrays (identified through @datalist()) allow to track changes in list collections indexed by numbers. Hibe automatically creates a proxy object to track item changes. All JS Array methods are supported as the hibe proxy is 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))) list4: Record[][][];   // list of list of list of Record datasets
}

Maps

Hibe also supports Map collections based on JavaScript Maps (cf. @datamap()). Like for Arrays, hibe automatically creates a JS Proxy to track map and map item changes - so all Map properties and methods are supported

@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