Skip to content

Instantly share code, notes, and snippets.

@beyond-code-github
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beyond-code-github/8742947 to your computer and use it in GitHub Desktop.
Save beyond-code-github/8742947 to your computer and use it in GitHub Desktop.
Example usage of change tracking in a complex view model, including a primitive array
var viewModel = {
Name: ko.observable("Pete"),
Age: ko.observable(29),
Skills: ko.observableArray([
"TDD", "Knockout", "WebForms"
}),
Occupation: ko.observable("Developer")
};
applyChangeTracking(viewModel);
viewModel.Occupation("Blogger");
viewModel.Skills.push("Change tracking");
viewModel.Skills.remove("WebForms");
getChangesFromModel(viewModel);
/* -> {
"Skills": {
added: ["Change tracking"],
removed: ["WebForms"]
},
Occupation: "Blogger"
} */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment