File: Qlite.min.js

Recommend this page to a friend!
  Classes of Javier Camelis   Qlite   Qlite.min.js   Download  
File: Qlite.min.js
Role: Sample output
Content type: text/plain
Description: Sample output
Class: Qlite
Processes conditions asynchronously using promises
Author: By
Last change: Update of Qlite.min.js
Date: 2 years ago
Size: 1,804 bytes
 

Contents

Class file image Download
/*! Qlite V0.0.4 https://github.com/jcamelis/Qlite 04-12-2014 */ !function(){"use strict";function a(a){return"function"==typeof a}function b(){this.stack=[],this.dependsStack=[],this.catchStack=[],this.status=d,this.reason="",this.resolvedArgs=[]}function c(a){return a instanceof b}var d="pending",e="resolved",f="rejected";b.prototype.isPending=function(){return this.status===d},b.prototype.isResolved=function(){return this.status===e},b.prototype.isRejected=function(){return this.status===f},b.prototype.resolve=function(){if(this.isPending()){this.status=e,this.resolvedArgs=Array.prototype.slice.call(arguments,0);var b;for(b=0;this.stack.length>b;b+=1)a(this.stack[b])&&this.stack[b].apply(this.stack[b],this.resolvedArgs)}},b.prototype.reject=function(b){if(this.isPending()){this.status=f,this.reason=b;var c;for(c=0;this.catchStack.length>c;c+=1)a(this.catchStack[c])&&this.catchStack[c].call(this.catchStack[c],this.reason)}},b.prototype.then=function(b){if(!a(b))throw new TypeError("Expected callback to be a function.");return this.isPending()?this.stack.push(b):b.call(b,this.resolvedArgs),this},b.prototype.depends=function(a){var b=this;if(!c(a))throw new TypeError("Expected promise to be a Promise instance");return this.dependsStack.push(a),a.then(function(){var a;for(a=0;b.dependsStack.length>a;a+=1)if(b.dependsStack[a].isPending())return;b.resolve()}).catch(function(a){b.reject(a)}),this},b.prototype["catch"]=function(b){if(!a(b))throw new TypeError("Expected callback to be a function.");return this.isPending()?this.catchStack.push(b):b.call(b,this.reason),this};var g={all:function(a){var d,e=new b;for(d=0;a.length>d;d+=1){if(!c(a[d]))throw new TypeError("Promise instance expected.");e.depends(a[d])}return e},defer:function(){return new b}};self?self.Q=g:window.Q=g}();