I've added the changeTracker here to my ko application but can't get it to initialize after all my bindings have updated. I'm doing several ajax calls to load data from a sql server database, and call
viewModel.tracker().markCurrentStateAsClean();
after updating everything from the database but apparently ko is still busy loading data after attempting to reset/initial the tracking mechanism. That is, the somethingHasChanged function is still true even after resetting it. I've tentatively added
setTimeout(function () { viewModel.tracker().markCurrentStateAsClean(); }, 4000);
and this works, but it just seems like it could cause problems with slow networks or low bandwidth situations where it takes longer to load. You can refer to my previous SO question here. Is there a better way to do this?
UPDATE
My database calls use
$.when(fcn1(), fcn2(), fcn3(), fcn4())
.done(function msg1, msg2, msg3, msg4) {
// initialize ko objects, "assistants", "teachers", "assistants" not assigned, etc.
})
.fail(function blah blah blah) {});
and so I've tried adding
viewModel.tracker().markCurrentStateAsClean();
at the end of the doneCallback and even to the end of jQuery/javascript fcns that call those view model functions to no avail - the somethingHasChanged() remains at true even when I try to reset it. If I wait for 4 seconds with the setTimeout call, clearly after ko has finished updating/binding, the somethingHasChanged() method returns false. So between 0 and 4 seconds after I'd think it's finished, it's really finished, when somethingHasChanged() is false.
And my view model has a lot of extenders due to race condition dependencies that are getting set up initially so I don't want the observables/observable arrays to notify subscribers but just once at the end of all updates, like this:
self.teachers = ko.observableArray().extend({ rateLimit: 0 });
self.columns = ko.observableArray().extend({ rateLimit: 0 });
self.assistants = ko.observableArray().extend({ rateLimit: 0 });
HTH in the explanation.