I have an object that I want to observe for changes using rxjs. The object has multiple properties, and when any of them change, I want to be notified of WHICH one was changed and what is its new value. I've put together the following simplified version of my code but it doesn't work as desired: http://jsbin.com/sidukulowi/1/edit?js,console
const store = Rx.Observable.create(function(observer) {
let state = { userActions: {
window: {
leftPanelWidth: 300,
backgroundColor: 0xffffff,
}
}};
observer.next(state);
state = { userActions: {
window: {
leftPanelWidth: 250,
backgroundColor: 0xffffff,
}
}};
observer.next(state);
state = { userActions: {
window: {
leftPanelWidth: 250,
backgroundColor: 0xff00ff,
}
}};
observer.next(state);
});
const subscribe = store
.map( state => state.userActions.window )
.distinctUntilChanged( ( a, b ) => {
return a.leftPanelWidth === b.leftPanelWidth && a.backgroundColor === b.backgroundColor
})
.subscribe(val => console.dir(val));
When the above code runs, I correctly get updates telling me when something in the window object is changed, however I don't know how to figure out which property is the one that changed.
How would I modify this so that I can see that in the first change, it is the leftPanelWidth that changed from 300 to 250, and in the next change it was the backgroundColor that changed from 0xffffff to 0xff00ff ?