Pregunta

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());
});
¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top