Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Always Fire Observable Event on Same Value with Knockout.js without ValueHasMutated

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());
});
like image 343
Mike Flynn Avatar asked May 12 '14 18:05

Mike Flynn


1 Answers

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.

like image 86
sroes Avatar answered Sep 20 '22 14:09

sroes