Skip to content

Instantly share code, notes, and snippets.

Created October 10, 2015 17:55
What would you like to do?
Knockout - Lazy data loading into observables
// thanks to rniemeyer!
ko.extenders.lazy = function(target, callback){
var result = ko.computed({
read: function(){
if (!result.loaded());
return target();
write: function(newValue){
deferEvaluation: true
result.loaded = ko.observable(false);
result.refresh = function(){ result.loaded(false); };
return result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment