Skip to content
This repository has been archived by the owner on Jul 19, 2019. It is now read-only.

Call .setAsync(promise) on a Knockout observable to set it once the promise resolves

License

Notifications You must be signed in to change notification settings

DouglasLivingstone/AsyncExtender

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Async Extender

Sets a Knockout observable property to the result of a promise. If the observable's value is set directly, or set to a different promise, then the first promise will be ignored.

A loading observable property is added to the extended observable, which returns true while the asynchronous operation is in progress.

Demo

Extend an observable with the async extender, then bind it to the view model. Once the promise resolves, the view model will be updated.

  var viewModel = {
    message: ko.observable().extend({ async: true })
  };

  ko.applyBindings(viewModel);

  var request = jQuery.getJSON("http://echo.jsontest.com/message/hello");

  viewModel.message.setAsync(request.then(function(json) {
    return json.message;
  }));
  <div data-bind="text: message"></div>

About

Call .setAsync(promise) on a Knockout observable to set it once the promise resolves

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published