I've been using ImmutableJS with Angular 2 for some time, because of it's performance benefits in change detection. See here.
However, I'm not quite sure, why Immutable works with Angular 2 by default. How does it know how to iterate over the values and display them, when there's no explicit array? Does it just call toJS()
every time it accesses the values of the collection? Does it implement some kind of method that Angular 2 automatically calls?
And if so, is there a way to define your own collections which also implement this method?
An example:
Component({
selector: 'list',
template: '<ul><li *ngFor="#item of items">{{ item.id }}</li></ul>',
directives: [CORE_DIRECTIVES]
})
export class SiteComponent {
items: Immutable.List<Item>;
}