- Bytes and Blobs by David Flanagan
- Conference Wifi Redux by Malte Ubi
- Sashimi - https://github.com/cramforce/Sashimi
- Run Your JS everywhere with Jellyfish by Adam Christian - http://jelly.io Project
- Fighting Crime and Kicking Apps with Batman.js by Nick Small
- Hello Jo by Dave Balmer - Project - http://joapp.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function join(promises) { | |
var promise = new Promise(); | |
promise.then( | |
function(val) { | |
for (var i = 0; i < promises.length; i++) { | |
promises[i].resolve(val); | |
} | |
}, | |
function(err) { | |
for (var i = 0; i < promises.length; i++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Promise.prototype.then = function (onResolve, onReject, onProgress) { | |
if(isPromise(onResolve)) { | |
// Chain promise | |
this.then( | |
function(val) { onResolve.resolve(onReject ? onReject : val); }, | |
function(err) { onResolve.reject(err); }, | |
function(update) { onResolve.progress(update); } | |
); | |
} else { | |
// capture calls to then() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Function: chain | |
Chain two <Promises> such that when the first completes, the second | |
is completed with either the completion value of the first, or | |
in the case of resolve, completed with the optional resolveValue. | |
Parameters: | |
first - first <Promise> | |
second - <Promise> to complete when first <Promise> completes | |
resolveValue - optional value to use as the resolution value |
Using the new wire.js prototype factory. You can use the prototype factory with any Javascript object, including object literals, just like you'd expect, since it's based on Javascript prototype chains.
This example shows it being used on an object literal, parent1, to create child1, and on a Controller (parent2) created from an AMD module, to create a specialized child2.
As you probably guessed, this will log:
Mom 1: Hello Billy
Billy 1: Hi Mom
Also check out this example of creating dojo datastores using the prototype factory.
Using the new wire.js prototype factory to create dojo datastores that share a query engine. This is coming in v0.5, so check it out in the dev-05 branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Using hitch to setup an event to be disconnected later | |
var cxn = events.connect(newlySelected, 'onAction', this, 'onItemAction'); | |
this._disconnectSelected = lang.hitch(events, 'disconnect', cxn); | |
// As a (hideous?) one-liner: | |
this._disconnectSelected = lang.hitch(events, 'disconnect', events.connect(newlySelected, 'onAction', this, 'onItemAction')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load a collection of images and return an array of promises | |
function loadImages(srcs) { | |
// srcs = array of image src urls | |
// Array to hold deferred for each image being loaded | |
var promises = []; | |
// Call loadImage for each src, and push the returned deferred | |
// onto the deferreds array | |
for(var i = 0, len = srcs.length; i < len; i++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define a global define() that works in the current environment | |
(function(global) { | |
var define; | |
define = global.define; | |
// If AMD, just use existing global.define | |
if(!(typeof define === 'function' && define.amd)) { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (namespace, myLib) { | |
//Set up myLib here. | |
if (typeof define == 'function' && define.amd) { | |
define(myLib); | |
} | |
else { | |
namespace.myLib = myLib; | |
} |