How Do I Use The Rxjs Selector Function In The Observable.bindcallback Method?
I believe that to get two params properly mapped back to the callback when using Observable.bindCallback method you have to use the 'selector' function, but I cannot find documenta
Solution 1:
The subscribe
function can only ever take a single argument. So the selector
function is about converting a multiargument callback into a single element. In general this means that you will pack the arguments into an object, and you can destructure it later on:
function testLogin(username, password, callback){
// ...
callback(param1, param2);
}
//Convert this into a new object
function selectorFunction(param1, param2) {
return {param1, param2};
}
function onTestLoginComplete(param1, param2) {
// ...
}
var observableFactory = Observable.bindCallback(testLogin, selectorFunction);
var observable = observableFactory('username', 'password');
//De-structure the argument when it is passed to subscribe.
observable.subscribe( ({param1, param2}) => onTestLoginComplete(param1, param2) );
Post a Comment for "How Do I Use The Rxjs Selector Function In The Observable.bindcallback Method?"