Commit efdb4704 authored by Yehuda Katz's avatar Yehuda Katz

Make RSVP.async hookable

parent 5f0fe0dd
...@@ -2,3 +2,4 @@ ...@@ -2,3 +2,4 @@
source "https://rubygems.org" source "https://rubygems.org"
gem "js_module_transpiler", github: "wycats/js_module_transpiler", branch: "master" gem "js_module_transpiler", github: "wycats/js_module_transpiler", branch: "master"
gem "rake"
GIT GIT
remote: git://github.com/wycats/js_module_transpiler.git remote: git://github.com/wycats/js_module_transpiler.git
revision: c2f2d529c2e45f32f6c71a5beaef23a75e8286e8 revision: c9f0ada0f7b7ec654ddec25f4a1fb07bcf41c9f7
branch: master branch: master
specs: specs:
js_module_transpiler (0.0.1) js_module_transpiler (0.0.1)
...@@ -9,6 +9,7 @@ GIT ...@@ -9,6 +9,7 @@ GIT
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
rake (10.0.2)
thor (0.16.0) thor (0.16.0)
PLATFORMS PLATFORMS
...@@ -16,3 +17,4 @@ PLATFORMS ...@@ -16,3 +17,4 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
js_module_transpiler! js_module_transpiler!
rake
define("rsvp", define("rsvp",
["exports"], [],
function(__exports__) { function() {
"use strict"; "use strict";
var browserGlobal = (typeof window !== 'undefined') ? window : {}; var browserGlobal = (typeof window !== 'undefined') ? window : {};
var MutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver; var MutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
var async; var RSVP, async;
if (typeof process !== 'undefined' && if (typeof process !== 'undefined' &&
{}.toString.call(process) === '[object process]') { {}.toString.call(process) === '[object process]') {
...@@ -42,7 +42,6 @@ define("rsvp", ...@@ -42,7 +42,6 @@ define("rsvp",
}; };
} }
var Event = function(type, options) { var Event = function(type, options) {
this.type = type; this.type = type;
...@@ -53,7 +52,6 @@ define("rsvp", ...@@ -53,7 +52,6 @@ define("rsvp",
} }
}; };
var indexOf = function(callbacks, callback) { var indexOf = function(callbacks, callback) {
for (var i=0, l=callbacks.length; i<l; i++) { for (var i=0, l=callbacks.length; i<l; i++) {
if (callbacks[i][0] === callback) { return i; } if (callbacks[i][0] === callback) { return i; }
...@@ -137,7 +135,6 @@ define("rsvp", ...@@ -137,7 +135,6 @@ define("rsvp",
} }
}; };
var Promise = function() { var Promise = function() {
this.on('promise:resolved', function(event) { this.on('promise:resolved', function(event) {
this.trigger('success', { detail: event.detail }); this.trigger('success', { detail: event.detail });
...@@ -148,7 +145,6 @@ define("rsvp", ...@@ -148,7 +145,6 @@ define("rsvp",
}, this); }, this);
}; };
var noop = function() {}; var noop = function() {};
var invokeCallback = function(type, promise, callback, event) { var invokeCallback = function(type, promise, callback, event) {
...@@ -184,13 +180,13 @@ define("rsvp", ...@@ -184,13 +180,13 @@ define("rsvp",
var thenPromise = new Promise(); var thenPromise = new Promise();
if (this.isResolved) { if (this.isResolved) {
async(function() { rsvp.async(function() {
invokeCallback('resolve', thenPromise, done, { detail: this.resolvedValue }); invokeCallback('resolve', thenPromise, done, { detail: this.resolvedValue });
}, this); }, this);
} }
if (this.isRejected) { if (this.isRejected) {
async(function() { rsvp.async(function() {
invokeCallback('reject', thenPromise, fail, { detail: this.rejectedValue }); invokeCallback('reject', thenPromise, fail, { detail: this.rejectedValue });
}, this); }, this);
} }
...@@ -222,7 +218,7 @@ define("rsvp", ...@@ -222,7 +218,7 @@ define("rsvp",
}; };
function resolve(promise, value) { function resolve(promise, value) {
async(function() { rsvp.async(function() {
promise.trigger('promise:resolved', { detail: value }); promise.trigger('promise:resolved', { detail: value });
promise.isResolved = true; promise.isResolved = true;
promise.resolvedValue = value; promise.resolvedValue = value;
...@@ -230,7 +226,7 @@ define("rsvp", ...@@ -230,7 +226,7 @@ define("rsvp",
} }
function reject(promise, value) { function reject(promise, value) {
async(function() { rsvp.async(function() {
promise.trigger('promise:failed', { detail: value }); promise.trigger('promise:failed', { detail: value });
promise.isRejected = true; promise.isRejected = true;
promise.rejectedValue = value; promise.rejectedValue = value;
...@@ -238,8 +234,7 @@ define("rsvp", ...@@ -238,8 +234,7 @@ define("rsvp",
} }
EventTarget.mixin(Promise.prototype); EventTarget.mixin(Promise.prototype);
__exports__.async = async;
__exports__.Event = Event; RSVP = { async: async, Promise: Promise, Event: Event, EventTarget: EventTarget };
__exports__.EventTarget = EventTarget; return RSVP;
__exports__.Promise = Promise;
}); });
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
var browserGlobal = (typeof window !== 'undefined') ? window : {}; var browserGlobal = (typeof window !== 'undefined') ? window : {};
var MutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver; var MutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
var async; var RSVP, async;
if (typeof process !== 'undefined' && if (typeof process !== 'undefined' &&
{}.toString.call(process) === '[object process]') { {}.toString.call(process) === '[object process]') {
...@@ -40,7 +40,6 @@ ...@@ -40,7 +40,6 @@
}; };
} }
var Event = function(type, options) { var Event = function(type, options) {
this.type = type; this.type = type;
...@@ -51,7 +50,6 @@ ...@@ -51,7 +50,6 @@
} }
}; };
var indexOf = function(callbacks, callback) { var indexOf = function(callbacks, callback) {
for (var i=0, l=callbacks.length; i<l; i++) { for (var i=0, l=callbacks.length; i<l; i++) {
if (callbacks[i][0] === callback) { return i; } if (callbacks[i][0] === callback) { return i; }
...@@ -135,7 +133,6 @@ ...@@ -135,7 +133,6 @@
} }
}; };
var Promise = function() { var Promise = function() {
this.on('promise:resolved', function(event) { this.on('promise:resolved', function(event) {
this.trigger('success', { detail: event.detail }); this.trigger('success', { detail: event.detail });
...@@ -146,7 +143,6 @@ ...@@ -146,7 +143,6 @@
}, this); }, this);
}; };
var noop = function() {}; var noop = function() {};
var invokeCallback = function(type, promise, callback, event) { var invokeCallback = function(type, promise, callback, event) {
...@@ -182,13 +178,13 @@ ...@@ -182,13 +178,13 @@
var thenPromise = new Promise(); var thenPromise = new Promise();
if (this.isResolved) { if (this.isResolved) {
async(function() { rsvp.async(function() {
invokeCallback('resolve', thenPromise, done, { detail: this.resolvedValue }); invokeCallback('resolve', thenPromise, done, { detail: this.resolvedValue });
}, this); }, this);
} }
if (this.isRejected) { if (this.isRejected) {
async(function() { rsvp.async(function() {
invokeCallback('reject', thenPromise, fail, { detail: this.rejectedValue }); invokeCallback('reject', thenPromise, fail, { detail: this.rejectedValue });
}, this); }, this);
} }
...@@ -220,7 +216,7 @@ ...@@ -220,7 +216,7 @@
}; };
function resolve(promise, value) { function resolve(promise, value) {
async(function() { rsvp.async(function() {
promise.trigger('promise:resolved', { detail: value }); promise.trigger('promise:resolved', { detail: value });
promise.isResolved = true; promise.isResolved = true;
promise.resolvedValue = value; promise.resolvedValue = value;
...@@ -228,7 +224,7 @@ ...@@ -228,7 +224,7 @@
} }
function reject(promise, value) { function reject(promise, value) {
async(function() { rsvp.async(function() {
promise.trigger('promise:failed', { detail: value }); promise.trigger('promise:failed', { detail: value });
promise.isRejected = true; promise.isRejected = true;
promise.rejectedValue = value; promise.rejectedValue = value;
...@@ -236,8 +232,7 @@ ...@@ -236,8 +232,7 @@
} }
EventTarget.mixin(Promise.prototype); EventTarget.mixin(Promise.prototype);
exports.async = async;
exports.Event = Event; RSVP = { async: async, Promise: Promise, Event: Event, EventTarget: EventTarget };
exports.EventTarget = EventTarget; exports.RSVP = RSVP;
exports.Promise = Promise; })(window);
})(window.RSVP = {});
(function(a){function p(a,b){d(function(){a.trigger("promise:failed",{detail:b}),a.isRejected=!0,a.rejectedValue=b})}function o(a,b){d(function(){a.trigger("promise:resolved",{detail:b}),a.isResolved=!0,a.resolvedValue=b})}"use strict";var b=typeof window!="undefined"?window:{},c=b.MutationObserver||b.WebKitMutationObserver,d;if(typeof process!="undefined"&&{}.toString.call(process)==="[object process]")d=function(a,b){process.nextTick(function(){a.call(b)})};else if(c){var e=[],f=new c(function(){var a=e.slice();e=[],a.forEach(function(a){var b=a[0],c=a[1];b.call(c)})}),g=document.createElement("div");f.observe(g,{attributes:!0}),d=function(a,b){e.push([a,b]),g.setAttribute("drainQueue","drainQueue")}}else d=function(a,b){setTimeout(function(){a.call(b)},1)};var h=function(a,b){this.type=a;for(var c in b){if(!b.hasOwnProperty(c))continue;this[c]=b[c]}},i=function(a,b){for(var c=0,d=a.length;c<d;c++)if(a[c][0]===b)return c;return-1},j=function(a){var b=a._promiseCallbacks;b||(b=a._promiseCallbacks={});return b},k={mixin:function(a){a.on=this.on,a.off=this.off,a.trigger=this.trigger;return a},on:function(a,b,c){var d=j(this),e,f;a=a.split(/\s+/),c=c||this;while(f=a.shift())e=d[f],e||(e=d[f]=[]),i(e,b)===-1&&e.push([b,c])},off:function(a,b){var c=j(this),d,e,f;a=a.split(/\s+/);while(e=a.shift()){if(!b){c[e]=[];continue}d=c[e],f=i(d,b),f!==-1&&d.splice(f,1)}},trigger:function(a,b){var c=j(this),d,e,f,g,i;if(d=c[a])for(var k=0,l=d.length;k<l;k++)e=d[k],f=e[0],g=e[1],typeof b!="object"&&(b={detail:b}),i=new h(a,b),f.call(g,i)}},l=function(){this.on("promise:resolved",function(a){this.trigger("success",{detail:a.detail})},this),this.on("promise:failed",function(a){this.trigger("error",{detail:a.detail})},this)},m=function(){},n=function(a,b,c,d){var e,f;if(c)try{e=c(d.detail)}catch(g){f=g}else e=d.detail;e instanceof l?e.then(function(a){b.resolve(a)},function(a){b.reject(a)}):c&&e?b.resolve(e):f?b.reject(f):b[a](e)};l.prototype={then:function(a,b){var c=new l;this.isResolved&&d(function(){n("resolve",c,a,{detail:this.resolvedValue})},this),this.isRejected&&d(function(){n("reject",c,b,{detail:this.rejectedValue})},this),this.on("promise:resolved",function(b){n("resolve",c,a,b)}),this.on("promise:failed",function(a){n("reject",c,b,a)});return c},resolve:function(a){o(this,a),this.resolve=m,this.reject=m},reject:function(a){p(this,a),this.resolve=m,this.reject=m}},k.mixin(l.prototype),a.async=d,a.Event=h,a.EventTarget=k,a.Promise=l})(window.RSVP={}) (function(a){function q(a,b){rsvp.async(function(){a.trigger("promise:failed",{detail:b}),a.isRejected=!0,a.rejectedValue=b})}function p(a,b){rsvp.async(function(){a.trigger("promise:resolved",{detail:b}),a.isResolved=!0,a.resolvedValue=b})}"use strict";var b=typeof window!="undefined"?window:{},c=b.MutationObserver||b.WebKitMutationObserver,d,e;if(typeof process!="undefined"&&{}.toString.call(process)==="[object process]")e=function(a,b){process.nextTick(function(){a.call(b)})};else if(c){var f=[],g=new c(function(){var a=f.slice();f=[],a.forEach(function(a){var b=a[0],c=a[1];b.call(c)})}),h=document.createElement("div");g.observe(h,{attributes:!0}),e=function(a,b){f.push([a,b]),h.setAttribute("drainQueue","drainQueue")}}else e=function(a,b){setTimeout(function(){a.call(b)},1)};var i=function(a,b){this.type=a;for(var c in b){if(!b.hasOwnProperty(c))continue;this[c]=b[c]}},j=function(a,b){for(var c=0,d=a.length;c<d;c++)if(a[c][0]===b)return c;return-1},k=function(a){var b=a._promiseCallbacks;b||(b=a._promiseCallbacks={});return b},l={mixin:function(a){a.on=this.on,a.off=this.off,a.trigger=this.trigger;return a},on:function(a,b,c){var d=k(this),e,f;a=a.split(/\s+/),c=c||this;while(f=a.shift())e=d[f],e||(e=d[f]=[]),j(e,b)===-1&&e.push([b,c])},off:function(a,b){var c=k(this),d,e,f;a=a.split(/\s+/);while(e=a.shift()){if(!b){c[e]=[];continue}d=c[e],f=j(d,b),f!==-1&&d.splice(f,1)}},trigger:function(a,b){var c=k(this),d,e,f,g,h;if(d=c[a])for(var j=0,l=d.length;j<l;j++)e=d[j],f=e[0],g=e[1],typeof b!="object"&&(b={detail:b}),h=new i(a,b),f.call(g,h)}},m=function(){this.on("promise:resolved",function(a){this.trigger("success",{detail:a.detail})},this),this.on("promise:failed",function(a){this.trigger("error",{detail:a.detail})},this)},n=function(){},o=function(a,b,c,d){var e,f;if(c)try{e=c(d.detail)}catch(g){f=g}else e=d.detail;e instanceof m?e.then(function(a){b.resolve(a)},function(a){b.reject(a)}):c&&e?b.resolve(e):f?b.reject(f):b[a](e)};m.prototype={then:function(a,b){var c=new m;this.isResolved&&rsvp.async(function(){o("resolve",c,a,{detail:this.resolvedValue})},this),this.isRejected&&rsvp.async(function(){o("reject",c,b,{detail:this.rejectedValue})},this),this.on("promise:resolved",function(b){o("resolve",c,a,b)}),this.on("promise:failed",function(a){o("reject",c,b,a)});return c},resolve:function(a){p(this,a),this.resolve=n,this.reject=n},reject:function(a){q(this,a),this.resolve=n,this.reject=n}},l.mixin(m.prototype),d={async:e,Promise:m,Event:i,EventTarget:l},a.RSVP=d})(window)
var browserGlobal = (typeof window !== 'undefined') ? window : {}; var browserGlobal = (typeof window !== 'undefined') ? window : {};
var MutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver; var MutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
var async; var RSVP, async;
if (typeof process !== 'undefined' && if (typeof process !== 'undefined' &&
{}.toString.call(process) === '[object process]') { {}.toString.call(process) === '[object process]') {
...@@ -38,8 +38,6 @@ if (typeof process !== 'undefined' && ...@@ -38,8 +38,6 @@ if (typeof process !== 'undefined' &&
}; };
} }
export async;
var Event = function(type, options) { var Event = function(type, options) {
this.type = type; this.type = type;
...@@ -50,8 +48,6 @@ var Event = function(type, options) { ...@@ -50,8 +48,6 @@ var Event = function(type, options) {
} }
}; };
export Event;
var indexOf = function(callbacks, callback) { var indexOf = function(callbacks, callback) {
for (var i=0, l=callbacks.length; i<l; i++) { for (var i=0, l=callbacks.length; i<l; i++) {
if (callbacks[i][0] === callback) { return i; } if (callbacks[i][0] === callback) { return i; }
...@@ -135,8 +131,6 @@ var EventTarget = { ...@@ -135,8 +131,6 @@ var EventTarget = {
} }
}; };
export EventTarget;
var Promise = function() { var Promise = function() {
this.on('promise:resolved', function(event) { this.on('promise:resolved', function(event) {
this.trigger('success', { detail: event.detail }); this.trigger('success', { detail: event.detail });
...@@ -147,8 +141,6 @@ var Promise = function() { ...@@ -147,8 +141,6 @@ var Promise = function() {
}, this); }, this);
}; };
export Promise;
var noop = function() {}; var noop = function() {};
var invokeCallback = function(type, promise, callback, event) { var invokeCallback = function(type, promise, callback, event) {
...@@ -184,13 +176,13 @@ Promise.prototype = { ...@@ -184,13 +176,13 @@ Promise.prototype = {
var thenPromise = new Promise(); var thenPromise = new Promise();
if (this.isResolved) { if (this.isResolved) {
async(function() { RSVP.async(function() {
invokeCallback('resolve', thenPromise, done, { detail: this.resolvedValue }); invokeCallback('resolve', thenPromise, done, { detail: this.resolvedValue });
}, this); }, this);
} }
if (this.isRejected) { if (this.isRejected) {
async(function() { RSVP.async(function() {
invokeCallback('reject', thenPromise, fail, { detail: this.rejectedValue }); invokeCallback('reject', thenPromise, fail, { detail: this.rejectedValue });
}, this); }, this);
} }
...@@ -222,7 +214,7 @@ Promise.prototype = { ...@@ -222,7 +214,7 @@ Promise.prototype = {
}; };
function resolve(promise, value) { function resolve(promise, value) {
async(function() { RSVP.async(function() {
promise.trigger('promise:resolved', { detail: value }); promise.trigger('promise:resolved', { detail: value });
promise.isResolved = true; promise.isResolved = true;
promise.resolvedValue = value; promise.resolvedValue = value;
...@@ -230,7 +222,7 @@ function resolve(promise, value) { ...@@ -230,7 +222,7 @@ function resolve(promise, value) {
} }
function reject(promise, value) { function reject(promise, value) {
async(function() { RSVP.async(function() {
promise.trigger('promise:failed', { detail: value }); promise.trigger('promise:failed', { detail: value });
promise.isRejected = true; promise.isRejected = true;
promise.rejectedValue = value; promise.rejectedValue = value;
...@@ -238,3 +230,6 @@ function reject(promise, value) { ...@@ -238,3 +230,6 @@ function reject(promise, value) {
} }
EventTarget.mixin(Promise.prototype); EventTarget.mixin(Promise.prototype);
RSVP = { async: async, Promise: Promise, Event: Event, EventTarget: EventTarget };
export = RSVP;
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
var browserGlobal = (typeof window !== 'undefined') ? window : {}; var browserGlobal = (typeof window !== 'undefined') ? window : {};
var MutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver; var MutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
var async; var RSVP, async;
if (typeof process !== 'undefined' && if (typeof process !== 'undefined' &&
{}.toString.call(process) === '[object process]') { {}.toString.call(process) === '[object process]') {
...@@ -39,7 +39,6 @@ if (typeof process !== 'undefined' && ...@@ -39,7 +39,6 @@ if (typeof process !== 'undefined' &&
}; };
} }
var Event = function(type, options) { var Event = function(type, options) {
this.type = type; this.type = type;
...@@ -50,7 +49,6 @@ var Event = function(type, options) { ...@@ -50,7 +49,6 @@ var Event = function(type, options) {
} }
}; };
var indexOf = function(callbacks, callback) { var indexOf = function(callbacks, callback) {
for (var i=0, l=callbacks.length; i<l; i++) { for (var i=0, l=callbacks.length; i<l; i++) {
if (callbacks[i][0] === callback) { return i; } if (callbacks[i][0] === callback) { return i; }
...@@ -134,7 +132,6 @@ var EventTarget = { ...@@ -134,7 +132,6 @@ var EventTarget = {
} }
}; };
var Promise = function() { var Promise = function() {
this.on('promise:resolved', function(event) { this.on('promise:resolved', function(event) {
this.trigger('success', { detail: event.detail }); this.trigger('success', { detail: event.detail });
...@@ -145,7 +142,6 @@ var Promise = function() { ...@@ -145,7 +142,6 @@ var Promise = function() {
}, this); }, this);
}; };
var noop = function() {}; var noop = function() {};
var invokeCallback = function(type, promise, callback, event) { var invokeCallback = function(type, promise, callback, event) {
...@@ -181,13 +177,13 @@ Promise.prototype = { ...@@ -181,13 +177,13 @@ Promise.prototype = {
var thenPromise = new Promise(); var thenPromise = new Promise();
if (this.isResolved) { if (this.isResolved) {
async(function() { RSVP.async(function() {
invokeCallback('resolve', thenPromise, done, { detail: this.resolvedValue }); invokeCallback('resolve', thenPromise, done, { detail: this.resolvedValue });
}, this); }, this);
} }
if (this.isRejected) { if (this.isRejected) {
async(function() { RSVP.async(function() {
invokeCallback('reject', thenPromise, fail, { detail: this.rejectedValue }); invokeCallback('reject', thenPromise, fail, { detail: this.rejectedValue });
}, this); }, this);
} }
...@@ -219,7 +215,7 @@ Promise.prototype = { ...@@ -219,7 +215,7 @@ Promise.prototype = {
}; };
function resolve(promise, value) { function resolve(promise, value) {
async(function() { RSVP.async(function() {
promise.trigger('promise:resolved', { detail: value }); promise.trigger('promise:resolved', { detail: value });
promise.isResolved = true; promise.isResolved = true;
promise.resolvedValue = value; promise.resolvedValue = value;
...@@ -227,7 +223,7 @@ function resolve(promise, value) { ...@@ -227,7 +223,7 @@ function resolve(promise, value) {
} }
function reject(promise, value) { function reject(promise, value) {
async(function() { RSVP.async(function() {
promise.trigger('promise:failed', { detail: value }); promise.trigger('promise:failed', { detail: value });
promise.isRejected = true; promise.isRejected = true;
promise.rejectedValue = value; promise.rejectedValue = value;
...@@ -235,7 +231,6 @@ function reject(promise, value) { ...@@ -235,7 +231,6 @@ function reject(promise, value) {
} }
EventTarget.mixin(Promise.prototype); EventTarget.mixin(Promise.prototype);
exports.async = async;
exports.Event = Event; RSVP = { async: async, Promise: Promise, Event: Event, EventTarget: EventTarget };
exports.EventTarget = EventTarget; module.exports = RSVP;
exports.Promise = Promise;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment