-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathko.promise.min.js
More file actions
1 lines (1 loc) · 972 Bytes
/
ko.promise.min.js
File metadata and controls
1 lines (1 loc) · 972 Bytes
1
function k(c){var e=!1;function h(a){function b(a){if(!a?0:a.then){var b=a.then(function(a){g(a);d(e)});j(a)&&b()}else g(a),d(e)}var l=!0,d=c.observable(e),g=c.observable(),f=c.computed({read:function(){l&&(l=e,c.computed(function(){d(!0);a.apply(f,[b])}));return c.utils.unwrapObservable(g())},deferEvaluation:!0});f.loading=d;return f}function j(a){return(!a?e:a.then)&&a.loading}c.promise=function(a){return(!a?0:a.then)?h(function(b){a.then(function(a){b(a)})}):h(a)};c.subscribable.fn.then=function(a){var b=this;return j(b)?h(function(c){var d=b();b.loading()===e&&c(a(d))}):h(function(c){c(a(b()))})};c.subscribable.fn.when=function(){var a=this,b=Array.prototype.slice.call(arguments);b.push(a);return h(function(c){function d(){g++;g===b.length&&c(a())}for(var g=0,f=0;f<b.length;f++)b[f].then(d)();this.loading.subscribe(function(a){if(a===e)for(a=0;a<b.length;a++)if(j(b[a]))b[a]()})})}}"function"===typeof define&&define.amd?define(["knockout"],k):k(this.ko);