I'm currently working on implementing a synchronization mechanism using observable and Map structures from Immutable.js.
However, I'm encountering an issue where the Map is unable to function as an observable or perhaps I might be approaching it incorrectly.
I've explored the Rx documentation and tried various methods like just, return, from, of... but none seem to align with using a Map.
What I really need is to ensure that my Map is fully populated (with values retrieved from an http.GET request) before executing the actions in the subscribe callback.
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 makes an http GET request and returns an observable string (imsi)
this.apiService.getImsiFromAAA(ip).subscribe(
imsi => myMap = this.reduceEndpointsToMap( imsi, topology),
error => this.errorMessage = <any>error
);
return myMap; // I need to find a way to convert my map into an observable
}
private reduceEndpointsToMap(imsi: string, topology: List<Endpoint>): Map<string, any> {
// This function takes the imsi and a list of endpoints, builds the map, and returns it
// The imsi is obtained through an http.GET request
}
In another class, I call processNewTopology to retrieve the Map. It's crucial for me to have the map ready before proceeding with display actions.
this.topologyService.processNewTopology(endpoints).subscribe(
myMap => {
// In this section, I aim to access the content of myMap to display the new topology
}
...
);