Skip to content

Instantly share code, notes, and snippets.

@danielmackay
Last active December 19, 2015 11:38
Show Gist options
  • Save danielmackay/5948776 to your computer and use it in GitHub Desktop.
Save danielmackay/5948776 to your computer and use it in GitHub Desktop.
Knockout dump binding handler.
ko.bindingHandlers.dump = {
init: function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext){
var context = valueAccessor();
var allBindings = allBindingsAccessor)();
var pre = document.createElement('pre');
element.appendChild(pre);
var dumpJSON = ko.computed({
read: function(){
return ko.toJSON(context, null, 2);
},
disposeWhenNodeIsRemoved: element
});
// Lets you apply bindings programatically instead of declaritively
ko.applyBindingsToNode(pre, {text: dumpJSON});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment