J'essaye d'implémenter un mécanisme de synchronisation avec observable et structure de carte de Immutable.js.Utilisation de la structure de mappe immuable en tant qu'observable
Cela ne fonctionne pas car Map ne peut pas être observable ou peut-être parce que je le fais de la mauvaise façon.
J'ai essayé de regarder dans le doc Rx, utiliser just, return, from, of ... rien ne semble convenir à une Map. Ce dont j'ai besoin est d'attendre que ma carte soit complétée (avec la valeur que je reçois d'un http.GET) avant de faire ce que j'ai mis dans le callback d'abonnement.
import {List, Map} from 'immutable';
import {Observable} from 'rxjs/Observable';
...
processNewTopology(topology: List<Endpoint>): Observable<Map<string, any>> {
let ip: string = JSON.stringify(topology.get(0).ueIpAddress);
//this function is just a http GET that returns an osbervable string (imsi)
this.apiService.getImsiFromAAA(ip).subscribe(
imsi => myMap = this.reduceEndpointsToMap(imsi, topology),
error => this.errorMessage = <any>error
);
return myMap; // I need in some way to convert my map into an obervable
}
private reduceEndpointsToMap(imsi: string, topology: List<Endpoint>): Map<string, any> {
// this function take the imsi and a list point and build the map and return it
// the imsi is provided by http.GET
}
donc dans une autre classe j'appelle processNewTopology pour obtenir la carte. Je dois avoir ma carte avant de faire les actions d'affichage
this.topologyService.processNewTopology(endpoints).subscribe(
myMap => {
// here I want to access the content of myMap to display the new topo
}
...
);
Merci beaucoup! Ça a marché. – Charles