문제

Is there a more convenient way to always notify an observable of a change, even if the value is the same without using valueHasMutated on every call?

I have a grid of cells that has an inner list of observables of properties. I am keeping a history of the grid.

I know the grid is updated by using an observable boolean called hasUpdate below. However, this property below doesn't fire when I call it a second time because of a second change in the grid.

I'd hate to call valueHasMutated every time I update the hasUpdate property below.

app.viewModel.members.hasUpdate.subscribe(function (update) {
    if (update)
        viewModel.undo.add(viewModel.grid());
});
도움이 되었습니까?

해결책

Use the notify extender:

app.viewModel.members.hasUpdate.extend({
    notify: 'always' 
});

This will make sure hasUpdate's subscribers will always be notified, even if the new value did not change.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top