Qlite: Processes conditions asynchronously using promises

Recommend this page to a friend!
     
  Info   Example   View files Files   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 22 All time: 533 This week: 1Up
Version License JavaScript version Categories
qlite 0.0.2BSD License1.0Language, Events
Description 

Author

This object can processes conditions asynchronously using promises.

It can register callback functions to handle the results of conditions that are evaluated asynchronously.

The object can register two functions that will be called when a promise is accepted or rejected.

It can also return the status of a promise as accepted, rejected or pending for when none of the status was set.

Picture of Javier Camelis
Name: Javier Camelis <contact>
Classes: 3 packages by
Country: Argentina Argentina
Age: ???
All time rank: 951 in Argentina Argentina
Week rank: 6 Up1 in Argentina Argentina Equal
Innovation award
Innovation award
Nominee: 1x

Example

<!DOCTYPE html> <html> <head> <title>Qlite Test</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="../Qlite.js"></script> <style> * { margin: 2px; padding: 2px 4px; font-family: Arial; } .resolved { background: #5f5; } .pending { background: #55f; color: #fff; font-weight: bold; } .rejected { background: #f55; } </style> </head> <body> <h1>Qlite Test</h1> <h4>Q.defer()</h4> <button onclick="resolve(a)">resolve(a)</button> <button onclick="delay(a)">delay(a)</button> <button onclick="reject(a)">reject(a)</button> <p id="a" class="pending">a Pending</p> <button onclick="resolve(b)">resolve(b)</button> <button onclick="delay(b)">delay(b)</button> <button onclick="reject(b)">reject(b)</button> <p id="b" class="pending">b Pending</p> <button onclick="resolve(c)">resolve(c)</button> <button onclick="delay(c)">delay(c)</button> <button onclick="reject(c)">reject(c)</button> <p id="c" class="pending">c Pending</p> <button onclick="resolve(d)">resolve(d)</button> <button onclick="delay(d)">delay(d)</button> <button onclick="reject(d)">reject(d)</button> <p id="d" class="pending">d Pending</p> <h4>Q.all()</h4> <p id="ab" class="pending">ab Pending</p> <p id="ac" class="pending">ac Pending</p> <p id="ad" class="pending">ad Pending</p> <p id="abc" class="pending">abc Pending</p> <p id="abd" class="pending">abd Pending</p> <p id="abcd" class="pending">abcd Pending</p> <script> var a = Q.defer(); var b = Q.defer(); var c = Q.defer(); var d = Q.defer(); var resolve = function (deferred) { deferred.resolve(); }; var reject = function (deferred) { deferred.reject(); }; var delay = function (deferred) { setTimeout(function () { deferred.resolve(); }, 4000); }; function update(elementId, status, message) { var element = document.getElementById(elementId); element.className = status; element.innerText = message || elementId + " " + status; } var foo = a.then(function () { update("a", "resolved"); }).catch(function () { update("a", "rejected"); }); b.then(function () { update("b", "resolved"); }).catch(function () { update("b", "rejected"); }); c.then(function () { update("c", "resolved"); }).catch(function () { update("c", "rejected"); }); d.then(function () { update("d", "resolved"); }).catch(function () { update("d", "rejected"); }); Q.all([a, b]).then(function () { update("ab", "resolved"); }).catch(function () { update("ab", "rejected"); }); Q.all([a, b, c]).then(function () { update("abc", "resolved"); }).catch(function () { update("abc", "rejected"); }); Q.all([a, b, d]).then(function () { update("abd", "resolved"); }).catch(function () { update("abd", "rejected"); }); Q.all([a, b, c, d]).then(function () { update("abcd", "resolved"); }).catch(function () { update("abcd", "rejected"); }); Q.all([a, c]).then(function () { update("ac", "resolved"); }).catch(function () { update("ac", "rejected"); }); Q.all([a, d]).then(function () { update("ad", "resolved"); }).catch(function () { update("ad", "rejected"); }); </script> </body> </html>

Details

Qlite

Little library for handling promises.


  Files folder image Files (12)  
File Role Description
Files folder imagetest (5 files)
Accessible without login Plain text file bower.json Data Auxiliary data
Accessible without login Plain text file Gruntfile.js Conf. Configuration script
Accessible without login Plain text file LICENSE Lic. Auxiliary data
Accessible without login Plain text file package.json Data Auxiliary data
Plain text file Qlite.js Class Class source
Accessible without login Plain text file Qlite.min.js Output Sample output
Accessible without login Plain text file README.md Data Auxiliary data

  Files folder image Files (12)  /  test  
File Role Description
  Accessible without login Plain text file index.html Example Documentation
  Accessible without login HTML file test.multiple.html Doc. Documentation
  Accessible without login Plain text file test.multiple.js Test Unit test script
  Accessible without login HTML file test.single.html Doc. Documentation
  Accessible without login Plain text file test.single.js Test Unit test script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:22
This week:0
All time:533
This week:1Up