Issue
I want to fire .subscribe() for my oberservable if one of three object keys have changed.
it works, if I copy & paste the method for each key:
this.myService.loadData(this.dataContainer.id, true)
.distinctUntilChanged((updatedData) => { return updatedData.relations; })
.subscribe(updatedData => {
console.log("relations changed",updatedData);
});
this.myService.loadData(this.dataContainer.id, true)
.distinctUntilChanged((updatedData) => { return updatedData.parent; })
.subscribe(updatedData => {
console.log("parent changed",updatedData);
});
this.myService.loadData(this.dataContainer.id, true)
.distinctUntilChanged((updatedData) => { return updatedData.children; })
.subscribe(updatedData => {
console.log("children changed",updatedData);
});
if I set the distinctUntilChanged comparer to return the whole updatedData object, my subscribe never fires.
How can I combine the three dinstinctUntilChanged into one reducer?
Solution
One way:
const data$ = this.myService.loadData(this.dataContainer.id, true);
Observable
.combineLatest(
$data.distinctUntilChanged(data => updatedData.relations),
$data.distinctUntilChanged(data => updatedData.parent),
$data.distinctUntilChanged(data => updatedData.children),
data => data
)
.subscribe(updatedData => {
console.log("relation|parent|children changed", updatedData);
});
Answered By - Lukas Neicelis
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.