Let's say I would like to get a set of records from the repository, display them in a list using *ngFor , for example.
<ul> <li *ngFor="let record in records | async"> ... </li> </ul>
Now the user clicks the "Create ..." button, another record is added to the repository and
recordAdded: EventEmitter<string>;
lights up to tell me the location. So I get this new entry - and only this entry - from the store and ... yells, how do I get my *ngFor to display this extra entry?
Ok, so I could store all the records in an array, like
_records: Record[];
and populate this array by subscribing to Observable<Record[]> as
this.recordService.getAll().subscribe(r => this._records = r);
But this array must be Observable itself in order to notify consumers of the appearance of a new record. So
observableRecords = Observable.create(obs => { this.recordService.getAll().subscribe(rec => { this._records = rec; obs.next(rec);
Ugh ... Not only is it painful to watch, there is also a ton of overhead, since the entire array is republished each time a new record is added and, most likely, Angular 2 will rebuild the entire list from scratch at every step.
Since this is such a common scenario, I believe there should be a much better way to do this.