Commit 257996c1 authored by Yehuda Katz's avatar Yehuda Katz

Create more modules

parent 24433fc4
......@@ -2,7 +2,7 @@ require "bundler/setup"
ENV['PATH'] = "#{Dir.pwd}/node_modules/.bin:#{ENV['PATH']}"
directory "browser"
directory "browser/rsvp"
directory "node_modules/rsvp"
def module_contents(file)
......@@ -10,10 +10,11 @@ def module_contents(file)
end
def amd_module(filename)
output = "browser/#{filename}.amd.js"
input = "lib/#{filename}.js"
out_name = filename.sub(/\.js$/, '.amd.js')
output = "browser/#{out_name}"
input = "lib/#{filename}"
file output => ["browser", input] do
file output => ["browser/rsvp", input] do
library = File.read(input)
open output, "w" do |file|
......@@ -24,8 +25,14 @@ def amd_module(filename)
output
end
def node_module(filename, output="node_modules/rsvp/#{filename}.js")
input = "lib/#{filename}.js"
def node_module(filename)
if filename == "rsvp.js"
output = "main.js"
else
output = "node_modules/#{filename}"
end
input = "lib/#{filename}"
file output => ["browser", input] do
library = File.read(input)
......@@ -42,29 +49,45 @@ def read(file)
File.read(file)
end
def name(filename, name)
def named_module(name, filename)
name = name.sub(/\.js$/, '')
body = read(filename)
body.sub(/define\(/, "define(#{name.inspect},")
end
# Collect the modules
modules = Dir.chdir "lib" do
Dir["**/*.js"] - ["loader.js"]
end
# Build the AMD modules
amd_async = amd_module "async"
amd_events = amd_module "events"
amd_rsvp = amd_module "rsvp"
amd_modules = modules.reduce({}) do |hash, mod|
hash.merge mod => amd_module(mod)
end
# Build the node modules
node_async = node_module "async"
node_events = node_module "events"
node_main = node_module "rsvp", "main.js"
node_modules = modules.reduce({}) do |hash, mod|
hash.merge mod => node_module(mod)
end
node_main = "main.js"
# Build a browser build based on the AMD modules
file "browser/rsvp.js" => ["browser", amd_async, amd_events, amd_rsvp] do
browser_dependencies = ["browser/rsvp"] + amd_modules.values
file "browser/rsvp.js" => browser_dependencies do
output = []
output << %|(function() {|
output.concat [read("lib/loader.js"), name(amd_async, "rsvp/async"), name(amd_events, "rsvp/events"), name(amd_rsvp, "rsvp")]
output << read("lib/loader.js")
amd_modules.each do |name, filename|
output << named_module(name, filename)
end
output << %|window.RSVP = requireModule('rsvp');|
output << %|})();|
......@@ -75,7 +98,7 @@ end
# Entry point for node build
file node_main => ["node_modules/rsvp", node_async, node_events]
file :node => ["node_modules/rsvp"] + node_modules.values
# Minified build
......@@ -101,7 +124,7 @@ end
# Build everything
task :dist => [:install_transpiler, :install_uglify, amd_async, amd_events, amd_rsvp, "browser/rsvp.js", "browser/rsvp.min.js", node_main]
task :dist => [:install_transpiler, :install_uglify, "browser/rsvp.js", "browser/rsvp.min.js", :node]
# Testing
......@@ -143,7 +166,7 @@ task :update_tests => "promises-tests" do
end
desc "Run the tests using Node"
task :test => [:install_transpiler, :update_tests, node_main] do
task :test => [:install_transpiler, :update_tests, :node] do
cd "promises-tests" do
sh "node ./lib/cli.js ../tests/test-adapter.js"
end
......
define(
["rsvp/async","rsvp/events","exports"],
function(__dependency1__, __dependency2__, __exports__) {
["rsvp/events","rsvp/promise","rsvp/node","rsvp/all","rsvp/defer","rsvp/config","exports"],
function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__, __dependency6__, __exports__) {
"use strict";
var async = __dependency1__.async;
var EventTarget = __dependency2__.EventTarget;
var config = {};
config.async = async;
var noop = function() {};
var Promise = function(resolver) {
var promise = this;
if (typeof resolver !== 'function') {
throw new TypeError('You must pass a resolver function as the sole argument to the promise constructor');
}
if (!(promise instanceof Promise)) {
return new Promise(resolver);
}
var resolvePromise = function(value) {
resolve(promise, value);
resolvePromise = noop;
rejectPromise = noop;
};
var rejectPromise = function(value) {
reject(promise, value);
resolvePromise = noop;
rejectPromise = noop;
};
this.on('promise:resolved', function(event) {
this.trigger('success', { detail: event.detail });
}, this);
this.on('promise:failed', function(event) {
this.trigger('error', { detail: event.detail });
}, this);
resolver(resolvePromise, rejectPromise);
};
var invokeCallback = function(type, promise, callback, event) {
var hasCallback = typeof callback === 'function',
value, error, succeeded, failed;
if (hasCallback) {
try {
value = callback(event.detail);
succeeded = true;
} catch(e) {
failed = true;
error = e;
}
} else {
value = event.detail;
succeeded = true;
}
if (value && typeof value.then === 'function') {
value.then(function(value) {
resolve(promise, value);
}, function(error) {
reject(promise, error);
});
} else if (hasCallback && succeeded) {
resolve(promise, value);
} else if (failed) {
reject(promise, error);
} else if (type === 'resolve') {
resolve(promise, value);
} else if (type === 'reject') {
reject(promise, value);
}
};
Promise.prototype = {
constructor: Promise,
then: function(done, fail) {
var thenPromise = new Promise(function() {});
if (this.isFulfilled) {
config.async(function() {
invokeCallback('resolve', thenPromise, done, { detail: this.fulfillmentValue });
}, this);
}
if (this.isRejected) {
config.async(function() {
invokeCallback('reject', thenPromise, fail, { detail: this.rejectedReason });
}, this);
}
this.on('promise:resolved', function(event) {
invokeCallback('resolve', thenPromise, done, event);
});
this.on('promise:failed', function(event) {
invokeCallback('reject', thenPromise, fail, event);
});
return thenPromise;
}
};
function resolve(promise, value) {
if (value && typeof value.then === 'function') {
value.then(function(val) {
resolve(promise, val);
}, function(val) {
reject(promise, val);
});
} else {
fulfill(promise, value);
}
}
function fulfill(promise, value) {
config.async(function() {
promise.trigger('promise:resolved', { detail: value });
promise.isFulfilled = true;
promise.fulfillmentValue = value;
});
}
function reject(promise, value) {
config.async(function() {
promise.trigger('promise:failed', { detail: value });
promise.isRejected = true;
promise.rejectedReason = value;
});
}
function all(promises) {
var i, results = [];
var allPromise = new Promise(function() {});
var remaining = promises.length;
if (remaining === 0) {
resolve(allPromise, []);
}
var resolver = function(index) {
return function(value) {
resolveAll(index, value);
};
};
var resolveAll = function(index, value) {
results[index] = value;
if (--remaining === 0) {
resolve(allPromise, results);
}
};
var rejectAll = function(error) {
reject(allPromise, error);
};
for (i = 0; i < promises.length; i++) {
if (promises[i] && typeof promises[i].then === 'function') {
promises[i].then(resolver(i), rejectAll);
} else {
resolveAll(i, promises[i]);
}
}
return allPromise;
}
EventTarget.mixin(Promise.prototype);
var EventTarget = __dependency1__.EventTarget;
var Promise = __dependency2__.Promise;
var denodeify = __dependency3__.denodeify;
var all = __dependency4__.all;
var defer = __dependency5__.defer;
var config = __dependency6__.config;
function configure(name, value) {
config[name] = value;
}
function defer() {
var deferred = {};
var promise = new Promise(function(resolve, reject) {
deferred.resolve = resolve;
deferred.reject = reject;
});
deferred.promise = promise;
return deferred;
}
function makeNodeCallbackFor(promise) {
return function (error, value) {
if (error) {
reject(promise, error);
} else if (arguments.length > 2) {
resolve(promise, Array.prototype.slice.call(arguments, 1));
} else {
resolve(promise, value);
}
};
}
function denodeify(nodeFunc) {
return function() {
var nodeArgs = Array.prototype.slice.call(arguments);
var promise = new Promise(function() {});
all(nodeArgs).then(function(nodeArgs) {
nodeArgs.push(makeNodeCallbackFor(promise));
try {
nodeFunc.apply(this, nodeArgs);
} catch(e) {
reject(promise, e);
}
});
return promise;
};
}
__exports__.Promise = Promise;
__exports__.EventTarget = EventTarget;
__exports__.all = all;
__exports__.defer = defer;
__exports__.denodeify = denodeify;
......
......@@ -31,6 +31,56 @@ var define, requireModule;
};
})();
define("rsvp/all",
["rsvp/promise","exports"],
function(__dependency1__, __exports__) {
"use strict";
var Promise = __dependency1__.Promise;
function all(promises) {
var i, results = [], resolve, reject;
var allPromise = new Promise(function(allResolver, allRejecter) {
resolve = allResolver;
reject = allRejecter;
});
var remaining = promises.length;
if (remaining === 0) {
resolve([]);
}
var resolver = function(index) {
return function(value) {
resolveAll(index, value);
};
};
var resolveAll = function(index, value) {
results[index] = value;
if (--remaining === 0) {
resolve(results);
}
};
var rejectAll = function(error) {
reject(error);
};
for (i = 0; i < promises.length; i++) {
if (promises[i] && typeof promises[i].then === 'function') {
promises[i].then(resolver(i), rejectAll);
} else {
resolveAll(i, promises[i]);
}
}
return allPromise;
}
__exports__.all = all;
});
define("rsvp/async",
["exports"],
function(__exports__) {
......@@ -85,6 +135,39 @@ define("rsvp/async",
__exports__.async = async;
});
define("rsvp/config",
["rsvp/async","exports"],
function(__dependency1__, __exports__) {
"use strict";
var async = __dependency1__.async;
var config = {};
config.async = async;
__exports__.config = config;
});
define("rsvp/defer",
["rsvp/promise","exports"],
function(__dependency1__, __exports__) {
"use strict";
var Promise = __dependency1__.Promise;
function defer() {
var deferred = {};
var promise = new Promise(function(resolve, reject) {
deferred.resolve = resolve;
deferred.reject = reject;
});
deferred.promise = promise;
return deferred;
}
__exports__.defer = defer;
});
define("rsvp/events",
["exports"],
function(__exports__) {
......@@ -187,15 +270,57 @@ define("rsvp/events",
__exports__.EventTarget = EventTarget;
});
define("rsvp",
["rsvp/async","rsvp/events","exports"],
define("rsvp/node",
["rsvp/promise","rsvp/all","exports"],
function(__dependency1__, __dependency2__, __exports__) {
"use strict";
var async = __dependency1__.async;
var EventTarget = __dependency2__.EventTarget;
var Promise = __dependency1__.Promise;
var all = __dependency2__.all;
var config = {};
config.async = async;
function makeNodeCallbackFor(resolve, reject) {
return function (error, value) {
if (error) {
reject(error);
} else if (arguments.length > 2) {
resolve(Array.prototype.slice.call(arguments, 1));
} else {
resolve(value);
}
};
}
function denodeify(nodeFunc) {
return function() {
var nodeArgs = Array.prototype.slice.call(arguments), resolve, reject;
var promise = new Promise(function(nodeResolve, nodeReject) {
resolve = nodeResolve;
reject = nodeReject;
});
all(nodeArgs).then(function(nodeArgs) {
nodeArgs.push(makeNodeCallbackFor(resolve, reject));
try {
nodeFunc.apply(this, nodeArgs);
} catch(e) {
reject(e);
}
});
return promise;
};
}
__exports__.denodeify = denodeify;
});
define("rsvp/promise",
["rsvp/config","rsvp/events","exports"],
function(__dependency1__, __dependency2__, __exports__) {
"use strict";
var config = __dependency1__.config;
var EventTarget = __dependency2__.EventTarget;
var noop = function() {};
......@@ -297,6 +422,8 @@ define("rsvp",
}
};
EventTarget.mixin(Promise.prototype);
function resolve(promise, value) {
if (value && typeof value.then === 'function') {
value.then(function(val) {
......@@ -325,93 +452,26 @@ define("rsvp",
});
}
function all(promises) {
var i, results = [];
var allPromise = new Promise(function() {});
var remaining = promises.length;
if (remaining === 0) {
resolve(allPromise, []);
}
var resolver = function(index) {
return function(value) {
resolveAll(index, value);
};
};
var resolveAll = function(index, value) {
results[index] = value;
if (--remaining === 0) {
resolve(allPromise, results);
}
};
var rejectAll = function(error) {
reject(allPromise, error);
};
for (i = 0; i < promises.length; i++) {
if (promises[i] && typeof promises[i].then === 'function') {
promises[i].then(resolver(i), rejectAll);
} else {
resolveAll(i, promises[i]);
}
}
return allPromise;
}
__exports__.Promise = Promise;
});
EventTarget.mixin(Promise.prototype);
define("rsvp",
["rsvp/events","rsvp/promise","rsvp/node","rsvp/all","rsvp/defer","rsvp/config","exports"],
function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__, __dependency6__, __exports__) {
"use strict";
var EventTarget = __dependency1__.EventTarget;
var Promise = __dependency2__.Promise;
var denodeify = __dependency3__.denodeify;
var all = __dependency4__.all;
var defer = __dependency5__.defer;
var config = __dependency6__.config;
function configure(name, value) {
config[name] = value;
}
function defer() {
var deferred = {};
var promise = new Promise(function(resolve, reject) {
deferred.resolve = resolve;
deferred.reject = reject;
});
deferred.promise = promise;
return deferred;
}
function makeNodeCallbackFor(promise) {
return function (error, value) {
if (error) {
reject(promise, error);
} else if (arguments.length > 2) {
resolve(promise, Array.prototype.slice.call(arguments, 1));
} else {
resolve(promise, value);
}
};
}
function denodeify(nodeFunc) {
return function() {
var nodeArgs = Array.prototype.slice.call(arguments);
var promise = new Promise(function() {});
all(nodeArgs).then(function(nodeArgs) {
nodeArgs.push(makeNodeCallbackFor(promise));
try {
nodeFunc.apply(this, nodeArgs);
} catch(e) {
reject(promise, e);
}
});
return promise;
};
}
__exports__.Promise = Promise;
__exports__.EventTarget = EventTarget;
__exports__.all = all;
__exports__.defer = defer;
__exports__.denodeify = denodeify;
......
(function(){var t,e;(function(){var n={},i={};t=function(t,e,i){n[t]={deps:e,callback:i}};e=function(t){if(i[t]){return i[t]}i[t]={};var r=n[t],o=r.deps,s=r.callback,f=[],c;for(var u=0,a=o.length;u<a;u++){if(o[u]==="exports"){f.push(c={})}else{f.push(e(o[u]))}}var l=s.apply(this,f);return i[t]=c||l}})();t("rsvp/async",["exports"],function(t){"use strict";var e=typeof window!=="undefined"?window:{};var n=e.MutationObserver||e.WebKitMutationObserver;var i;if(typeof process!=="undefined"&&{}.toString.call(process)==="[object process]"){i=function(t,e){process.nextTick(function(){t.call(e)})}}else if(n){var r=[];var o=new n(function(){var t=r.slice();r=[];t.forEach(function(t){var e=t[0],n=t[1];e.call(n)})});var s=document.createElement("div");o.observe(s,{attributes:true});window.addEventListener("unload",function(){o.disconnect();o=null});i=function(t,e){r.push([t,e]);s.setAttribute("drainQueue","drainQueue")}}else{i=function(t,e){setTimeout(function(){t.call(e)},1)}}t.async=i});t("rsvp/events",["exports"],function(t){"use strict";var e=function(t,e){this.type=t;for(var n in e){if(!e.hasOwnProperty(n)){continue}this[n]=e[n]}};var n=function(t,e){for(var n=0,i=t.length;n<i;n++){if(t[n][0]===e){return n}}return-1};var i=function(t){var e=t._promiseCallbacks;if(!e){e=t._promiseCallbacks={}}return e};var r={mixin:function(t){t.on=this.on;t.off=this.off;t.trigger=this.trigger;return t},on:function(t,e,r){var o=i(this),s,f;t=t.split(/\s+/);r=r||this;while(f=t.shift()){s=o[f];if(!s){s=o[f]=[]}if(n(s,e)===-1){s.push([e,r])}}},off:function(t,e){var r=i(this),o,s,f;t=t.split(/\s+/);while(s=t.shift()){if(!e){r[s]=[];continue}o=r[s];f=n(o,e);if(f!==-1){o.splice(f,1)}}},trigger:function(t,n){var r=i(this),o,s,f,c,u;if(o=r[t]){for(var a=0;a<o.length;a++){s=o[a];f=s[0];c=s[1];if(typeof n!=="object"){n={detail:n}}u=new e(t,n);f.call(c,u)}}}};t.EventTarget=r});t("rsvp",["rsvp/async","rsvp/events","exports"],function(t,e,n){"use strict";var i=t.async;var r=e.EventTarget;var o={};o.async=i;var s=function(){};var f=function(t){var e=this;if(typeof t!=="function"){throw new TypeError("You must pass a resolver function as the sole argument to the promise constructor")}if(!(e instanceof f)){return new f(t)}var n=function(t){u(e,t);n=s;i=s};var i=function(t){l(e,t);n=s;i=s};this.on("promise:resolved",function(t){this.trigger("success",{detail:t.detail})},this);this.on("promise:failed",function(t){this.trigger("error",{detail:t.detail})},this);t(n,i)};var c=function(t,e,n,i){var r=typeof n==="function",o,s,f,c;if(r){try{o=n(i.detail);f=true}catch(a){c=true;s=a}}else{o=i.detail;f=true}if(o&&typeof o.then==="function"){o.then(function(t){u(e,t)},function(t){l(e,t)})}else if(r&&f){u(e,o)}else if(c){l(e,s)}else if(t==="resolve"){u(e,o)}else if(t==="reject"){l(e,o)}};f.prototype={constructor:f,then:function(t,e){var n=new f(function(){});if(this.isFulfilled){o.async(function(){c("resolve",n,t,{detail:this.fulfillmentValue})},this)}if(this.isRejected){o.async(function(){c("reject",n,e,{detail:this.rejectedReason})},this)}this.on("promise:resolved",function(e){c("resolve",n,t,e)});this.on("promise:failed",function(t){c("reject",n,e,t)});return n}};function u(t,e){if(e&&typeof e.then==="function"){e.then(function(e){u(t,e)},function(e){l(t,e)})}else{a(t,e)}}function a(t,e){o.async(function(){t.trigger("promise:resolved",{detail:e});t.isFulfilled=true;t.fulfillmentValue=e})}function l(t,e){o.async(function(){t.trigger("promise:failed",{detail:e});t.isRejected=true;t.rejectedReason=e})}function v(t){var e,n=[];var i=new f(function(){});var r=t.length;if(r===0){u(i,[])}var o=function(t){return function(e){s(t,e)}};var s=function(t,e){n[t]=e;if(--r===0){u(i,n)}};var c=function(t){l(i,t)};for(e=0;e<t.length;e++){if(t[e]&&typeof t[e].then==="function"){t[e].then(o(e),c)}else{s(e,t[e])}}return i}r.mixin(f.prototype);function p(t,e){o[t]=e}function h(){var t={};var e=new f(function(e,n){t.resolve=e;t.reject=n});t.promise=e;return t}function d(t){return function(e,n){if(e){l(t,e)}else if(arguments.length>2){u(t,Array.prototype.slice.call(arguments,1))}else{u(t,n)}}}function y(t){return function(){var e=Array.prototype.slice.call(arguments);var n=new f(function(){});v(e).then(function(e){e.push(d(n));try{t.apply(this,e)}catch(i){l(n,i)}});return n}}n.Promise=f;n.all=v;n.defer=h;n.denodeify=y;n.configure=p});window.RSVP=e("rsvp")})();
(function(){var e,t;(function(){var n={},r={};e=function(e,t,r){n[e]={deps:t,callback:r}};t=function(e){if(r[e]){return r[e]}r[e]={};var i=n[e],o=i.deps,s=i.callback,f=[],c;for(var u=0,a=o.length;u<a;u++){if(o[u]==="exports"){f.push(c={})}else{f.push(t(o[u]))}}var l=s.apply(this,f);return r[e]=c||l}})();e("rsvp/all",["rsvp/promise","exports"],function(e,t){"use strict";var n=e.Promise;function r(e){var t,r=[],i,o;var s=new n(function(e,t){i=e;o=t});var f=e.length;if(f===0){i([])}var c=function(e){return function(t){u(e,t)}};var u=function(e,t){r[e]=t;if(--f===0){i(r)}};var a=function(e){o(e)};for(t=0;t<e.length;t++){if(e[t]&&typeof e[t].then==="function"){e[t].then(c(t),a)}else{u(t,e[t])}}return s}t.all=r});e("rsvp/async",["exports"],function(e){"use strict";var t=typeof window!=="undefined"?window:{};var n=t.MutationObserver||t.WebKitMutationObserver;var r;if(typeof process!=="undefined"&&{}.toString.call(process)==="[object process]"){r=function(e,t){process.nextTick(function(){e.call(t)})}}else if(n){var i=[];var o=new n(function(){var e=i.slice();i=[];e.forEach(function(e){var t=e[0],n=e[1];t.call(n)})});var s=document.createElement("div");o.observe(s,{attributes:true});window.addEventListener("unload",function(){o.disconnect();o=null});r=function(e,t){i.push([e,t]);s.setAttribute("drainQueue","drainQueue")}}else{r=function(e,t){setTimeout(function(){e.call(t)},1)}}e.async=r});e("rsvp/config",["rsvp/async","exports"],function(e,t){"use strict";var n=e.async;var r={};r.async=n;t.config=r});e("rsvp/defer",["rsvp/promise","exports"],function(e,t){"use strict";var n=e.Promise;function r(){var e={};var t=new n(function(t,n){e.resolve=t;e.reject=n});e.promise=t;return e}t.defer=r});e("rsvp/events",["exports"],function(e){"use strict";var t=function(e,t){this.type=e;for(var n in t){if(!t.hasOwnProperty(n)){continue}this[n]=t[n]}};var n=function(e,t){for(var n=0,r=e.length;n<r;n++){if(e[n][0]===t){return n}}return-1};var r=function(e){var t=e._promiseCallbacks;if(!t){t=e._promiseCallbacks={}}return t};var i={mixin:function(e){e.on=this.on;e.off=this.off;e.trigger=this.trigger;return e},on:function(e,t,i){var o=r(this),s,f;e=e.split(/\s+/);i=i||this;while(f=e.shift()){s=o[f];if(!s){s=o[f]=[]}if(n(s,t)===-1){s.push([t,i])}}},off:function(e,t){var i=r(this),o,s,f;e=e.split(/\s+/);while(s=e.shift()){if(!t){i[s]=[];continue}o=i[s];f=n(o,t);if(f!==-1){o.splice(f,1)}}},trigger:function(e,n){var i=r(this),o,s,f,c,u;if(o=i[e]){for(var a=0;a<o.length;a++){s=o[a];f=s[0];c=s[1];if(typeof n!=="object"){n={detail:n}}u=new t(e,n);f.call(c,u)}}}};e.EventTarget=i});e("rsvp/node",["rsvp/promise","rsvp/all","exports"],function(e,t,n){"use strict";var r=e.Promise;var i=t.all;function o(e,t){return function(n,r){if(n){t(n)}else if(arguments.length>2){e(Array.prototype.slice.call(arguments,1))}else{e(r)}}}function s(e){return function(){var t=Array.prototype.slice.call(arguments),n,s;var f=new r(function(e,t){n=e;s=t});i(t).then(function(t){t.push(o(n,s));try{e.apply(this,t)}catch(r){s(r)}});return f}}n.denodeify=s});e("rsvp/promise",["rsvp/config","rsvp/events","exports"],function(e,t,n){"use strict";var r=e.config;var i=t.EventTarget;var o=function(){};var s=function(e){var t=this;if(typeof e!=="function"){throw new TypeError("You must pass a resolver function as the sole argument to the promise constructor")}if(!(t instanceof s)){return new s(e)}var n=function(e){c(t,e);n=o;r=o};var r=function(e){a(t,e);n=o;r=o};this.on("promise:resolved",function(e){this.trigger("success",{detail:e.detail})},this);this.on("promise:failed",function(e){this.trigger("error",{detail:e.detail})},this);e(n,r)};var f=function(e,t,n,r){var i=typeof n==="function",o,s,f,u;if(i){try{o=n(r.detail);f=true}catch(l){u=true;s=l}}else{o=r.detail;f=true}if(o&&typeof o.then==="function"){o.then(function(e){c(t,e)},function(e){a(t,e)})}else if(i&&f){c(t,o)}else if(u){a(t,s)}else if(e==="resolve"){c(t,o)}else if(e==="reject"){a(t,o)}};s.prototype={constructor:s,then:function(e,t){var n=new s(function(){});if(this.isFulfilled){r.async(function(){f("resolve",n,e,{detail:this.fulfillmentValue})},this)}if(this.isRejected){r.async(function(){f("reject",n,t,{detail:this.rejectedReason})},this)}this.on("promise:resolved",function(t){f("resolve",n,e,t)});this.on("promise:failed",function(e){f("reject",n,t,e)});return n}};i.mixin(s.prototype);function c(e,t){if(t&&typeof t.then==="function"){t.then(function(t){c(e,t)},function(t){a(e,t)})}else{u(e,t)}}function u(e,t){r.async(function(){e.trigger("promise:resolved",{detail:t});e.isFulfilled=true;e.fulfillmentValue=t})}function a(e,t){r.async(function(){e.trigger("promise:failed",{detail:t});e.isRejected=true;e.rejectedReason=t})}n.Promise=s});e("rsvp",["rsvp/events","rsvp/promise","rsvp/node","rsvp/all","rsvp/defer","rsvp/config","exports"],function(e,t,n,r,i,o,s){"use strict";var f=e.EventTarget;var c=t.Promise;var u=n.denodeify;var a=r.all;var l=i.defer;var v=o.config;function p(e,t){v[e]=t}s.Promise=c;s.EventTarget=f;s.all=a;s.defer=l;s.denodeify=u;s.configure=p});window.RSVP=t("rsvp")})();
define(
["rsvp/promise","exports"],
function(__dependency1__, __exports__) {
"use strict";
var Promise = __dependency1__.Promise;
function all(promises) {
var i, results = [], resolve, reject;
var allPromise = new Promise(function(allResolver, allRejecter) {
resolve = allResolver;
reject = allRejecter;
});
var remaining = promises.length;
if (remaining === 0) {
resolve([]);
}
var resolver = function(index) {
return function(value) {
resolveAll(index, value);
};
};
var resolveAll = function(index, value) {
results[index] = value;
if (--remaining === 0) {
resolve(results);
}
};
var rejectAll = function(error) {
reject(error);
};
for (i = 0; i < promises.length; i++) {
if (promises[i] && typeof promises[i].then === 'function') {
promises[i].then(resolver(i), rejectAll);
} else {
resolveAll(i, promises[i]);
}
}
return allPromise;
}
__exports__.all = all;
});
define(
["rsvp/async","exports"],
function(__dependency1__, __exports__) {
"use strict";
var async = __dependency1__.async;
var config = {};
config.async = async;
__exports__.config = config;
});
define(
["rsvp/promise","exports"],
function(__dependency1__, __exports__) {
"use strict";
var Promise = __dependency1__.Promise;
function defer() {
var deferred = {};
var promise = new Promise(function(resolve, reject) {
deferred.resolve = resolve;
deferred.reject = reject;
});
deferred.promise = promise;
return deferred;
}
__exports__.defer = defer;
});
define(
["rsvp/promise","rsvp/all","exports"],
function(__dependency1__, __dependency2__, __exports__) {
"use strict";
var Promise = __dependency1__.Promise;
var all = __dependency2__.all;
function makeNodeCallbackFor(resolve, reject) {
return function (error, value) {
if (error) {
reject(error);
} else if (arguments.length > 2) {
resolve(Array.prototype.slice.call(arguments, 1));
} else {
resolve(value);
}
};
}
function denodeify(nodeFunc) {
return function() {
var nodeArgs = Array.prototype.slice.call(arguments), resolve, reject;
var promise = new Promise(function(nodeResolve, nodeReject) {
resolve = nodeResolve;
reject = nodeReject;
});
all(nodeArgs).then(function(nodeArgs) {
nodeArgs.push(makeNodeCallbackFor(resolve, reject));
try {
nodeFunc.apply(this, nodeArgs);
} catch(e) {
reject(e);
}
});
return promise;
};
}
__exports__.denodeify = denodeify;
});
define(
["rsvp/config","rsvp/events","exports"],
function(__dependency1__, __dependency2__, __exports__) {
"use strict";
var config = __dependency1__.config;
var EventTarget = __dependency2__.EventTarget;
var noop = function() {};
var Promise = function(resolver) {
var promise = this;
if (typeof resolver !== 'function') {
throw new TypeError('You must pass a resolver function as the sole argument to the promise constructor');
}
if (!(promise instanceof Promise)) {
return new Promise(resolver);
}
var resolvePromise = function(value) {
resolve(promise, value);
resolvePromise = noop;
rejectPromise = noop;
};
var rejectPromise = function(value) {
reject(promise, value);
resolvePromise = noop;
rejectPromise = noop;
};
this.on('promise:resolved', function(event) {
this.trigger('success', { detail: event.detail });
}, this);
this.on('promise:failed', function(event) {
this.trigger('error', { detail: event.detail });
}, this);
resolver(resolvePromise, rejectPromise);
};
var invokeCallback = function(type, promise, callback, event) {
var hasCallback = typeof callback === 'function',
value, error, succeeded, failed;
if (hasCallback) {
try {
value = callback(event.detail);
succeeded = true;
} catch(e) {
failed = true;
error = e;
}
} else {
value = event.detail;
succeeded = true;
}
if (value && typeof value.then === 'function') {
value.then(function(value) {
resolve(promise, value);
}, function(error) {
reject(promise, error);
});
} else if (hasCallback && succeeded) {
resolve(promise, value);
} else if (failed) {
reject(promise, error);
} else if (type === 'resolve') {
resolve(promise, value);
} else if (type === 'reject') {
reject(promise, value);
}
};
Promise.prototype = {
constructor: Promise,
then: function(done, fail) {
var thenPromise = new Promise(function() {});
if (this.isFulfilled) {
config.async(function() {
invokeCallback('resolve', thenPromise, done, { detail: this.fulfillmentValue });
}, this);
}
if (this.isRejected) {
config.async(function() {
invokeCallback('reject', thenPromise, fail, { detail: this.rejectedReason });
}, this);
}
this.on('promise:resolved', function(event) {
invokeCallback('resolve', thenPromise, done, event);
});
this.on('promise:failed', function(event) {
invokeCallback('reject', thenPromise, fail, event);
});
return thenPromise;
}
};
EventTarget.mixin(Promise.prototype);
function resolve(promise, value) {
if (value && typeof value.then === 'function') {
value.then(function(val) {
resolve(promise, val);
}, function(val) {
reject(promise, val);
});
} else {
fulfill(promise, value);
}
}
function fulfill(promise, value) {
config.async(function() {
promise.trigger('promise:resolved', { detail: value });
promise.isFulfilled = true;
promise.fulfillmentValue = value;
});
}
function reject(promise, value) {
config.async(function() {
promise.trigger('promise:failed', { detail: value });
promise.isRejected = true;
promise.rejectedReason = value;
});
}
__exports__.Promise = Promise;
});
import { async } from "rsvp/async";
import { EventTarget } from "rsvp/events";
var config = {};
config.async = async;
var noop = function() {};
var Promise = function(resolver) {
var promise = this;
if (typeof resolver !== 'function') {
throw new TypeError('You must pass a resolver function as the sole argument to the promise constructor');
}
if (!(promise instanceof Promise)) {
return new Promise(resolver);
}
var resolvePromise = function(value) {
resolve(promise, value);
resolvePromise = noop;
rejectPromise = noop;
};
var rejectPromise = function(value) {
reject(promise, value);
resolvePromise = noop;
rejectPromise = noop;
};
this.on('promise:resolved', function(event) {
this.trigger('success', { detail: event.detail });
}, this);
this.on('promise:failed', function(event) {
this.trigger('error', { detail: event.detail });
}, this);
resolver(resolvePromise, rejectPromise);
};
var invokeCallback = function(type, promise, callback, event) {
var hasCallback = typeof callback === 'function',
value, error, succeeded, failed;
if (hasCallback) {
try {
value = callback(event.detail);
succeeded = true;
} catch(e) {
failed = true;
error = e;
}
} else {
value = event.detail;
succeeded = true;
}
if (value && typeof value.then === 'function') {
value.then(function(value) {
resolve(promise, value);
}, function(error) {
reject(promise, error);
});
} else if (hasCallback && succeeded) {
resolve(promise, value);
} else if (failed) {
reject(promise, error);
} else if (type === 'resolve') {
resolve(promise, value);
} else if (type === 'reject') {
reject(promise, value);
}
};
Promise.prototype = {
constructor: Promise,
then: function(done, fail) {
var thenPromise = new Promise(function() {});
if (this.isFulfilled) {
config.async(function() {
invokeCallback('resolve', thenPromise, done, { detail: this.fulfillmentValue });
}, this);
}
if (this.isRejected) {
config.async(function() {
invokeCallback('reject', thenPromise, fail, { detail: this.rejectedReason });
}, this);
}
this.on('promise:resolved', function(event) {
invokeCallback('resolve', thenPromise, done, event);
});
this.on('promise:failed', function(event) {
invokeCallback('reject', thenPromise, fail, event);
});
return thenPromise;
}
};
function resolve(promise, value) {
if (value && typeof value.then === 'function') {
value.then(function(val) {
resolve(promise, val);
}, function(val) {
reject(promise, val);
});
} else {
fulfill(promise, value);
}
}
function fulfill(promise, value) {
config.async(function() {
promise.trigger('promise:resolved', { detail: value });
promise.isFulfilled = true;
promise.fulfillmentValue = value;
});
}
function reject(promise, value) {
config.async(function() {
promise.trigger('promise:failed', { detail: value });
promise.isRejected = true;
promise.rejectedReason = value;
});
}
function all(promises) {
var i, results = [];
var allPromise = new Promise(function() {});
var remaining = promises.length;
if (remaining === 0) {
resolve(allPromise, []);
}
var resolver = function(index) {
return function(value) {
resolveAll(index, value);
};
};
var resolveAll = function(index, value) {
results[index] = value;
if (--remaining === 0) {
resolve(allPromise, results);
}
};
var rejectAll = function(error) {
reject(allPromise, error);
};
for (i = 0; i < promises.length; i++) {
if (promises[i] && typeof promises[i].then === 'function') {
promises[i].then(resolver(i), rejectAll);
} else {
resolveAll(i, promises[i]);
}
}
return allPromise;
}
EventTarget.mixin(Promise.prototype);
import { Promise } from "rsvp/promise";
import { denodeify } from "rsvp/node";
import { all } from "rsvp/all";
import { defer } from "rsvp/defer";
import { config } from "rsvp/config";
function configure(name, value) {
config[name] = value;
}
function defer() {
var deferred = {};
var promise = new Promise(function(resolve, reject) {
deferred.resolve = resolve;
deferred.reject = reject;
});
deferred.promise = promise;
return deferred;
}
function makeNodeCallbackFor(promise) {
return function (error, value) {
if (error) {
reject(promise, error);
} else if (arguments.length > 2) {
resolve(promise, Array.prototype.slice.call(arguments, 1));
} else {
resolve(promise, value);
}
};
}
function denodeify(nodeFunc) {
return function() {
var nodeArgs = Array.prototype.slice.call(arguments);
var promise = new Promise(function() {});
all(nodeArgs).then(function(nodeArgs) {
nodeArgs.push(makeNodeCallbackFor(promise));
try {
nodeFunc.apply(this, nodeArgs);
} catch(e) {
reject(promise, e);
}
});
return promise;
};
}
export { Promise, all, defer, denodeify, configure };
export { Promise, EventTarget, all, defer, denodeify, configure };
\ No newline at end of file
import { Promise } from "rsvp/promise";
function all(promises) {
var i, results = [], resolve, reject;
var allPromise = new Promise(function(allResolver, allRejecter) {
resolve = allResolver;
reject = allRejecter;
});
var remaining = promises.length;
if (remaining === 0) {
resolve([]);
}
var resolver = function(index) {
return function(value) {
resolveAll(index, value);
};
};
var resolveAll = function(index, value) {
results[index] = value;
if (--remaining === 0) {
resolve(results);
}
};
var rejectAll = function(error) {
reject(error);
};
for (i = 0; i < promises.length; i++) {
if (promises[i] && typeof promises[i].then === 'function') {
promises[i].then(resolver(i), rejectAll);
} else {
resolveAll(i, promises[i]);
}
}
return allPromise;
}
export { all };
\ No newline at end of file
import { async } from "rsvp/async";
var config = {};
config.async = async;
export { config };
\ No newline at end of file
import { Promise } from "rsvp/promise";
function defer() {
var deferred = {};
var promise = new Promise(function(resolve, reject) {
deferred.resolve = resolve;
deferred.reject = reject;
});
deferred.promise = promise;
return deferred;
}
export { defer };
\ No newline at end of file
import { Promise } from "rsvp/promise";
import { all } from "rsvp/all";
function makeNodeCallbackFor(resolve, reject) {
return function (error, value) {
if (error) {
reject(error);
} else if (arguments.length > 2) {
resolve(Array.prototype.slice.call(arguments, 1));
} else {
resolve(value);
}
};
}
function denodeify(nodeFunc) {
return function() {
var nodeArgs = Array.prototype.slice.call(arguments), resolve, reject;
var promise = new Promise(function(nodeResolve, nodeReject) {
resolve = nodeResolve;
reject = nodeReject;
});
all(nodeArgs).then(function(nodeArgs) {
nodeArgs.push(makeNodeCallbackFor(resolve, reject));
try {
nodeFunc.apply(this, nodeArgs);
} catch(e) {
reject(e);
}
});
return promise;
};
}
export { denodeify };
\ No newline at end of file
import { config } from "rsvp/config";
import { EventTarget } from "rsvp/events";
var noop = function() {};
var Promise = function(resolver) {
var promise = this;
if (typeof resolver !== 'function') {
throw new TypeError('You must pass a resolver function as the sole argument to the promise constructor');
}
if (!(promise instanceof Promise)) {
return new Promise(resolver);
}
var resolvePromise = function(value) {
resolve(promise, value);
resolvePromise = noop;
rejectPromise = noop;
};
var rejectPromise = function(value) {
reject(promise, value);
resolvePromise = noop;
rejectPromise = noop;
};
this.on('promise:resolved', function(event) {
this.trigger('success', { detail: event.detail });
}, this);
this.on('promise:failed', function(event) {
this.trigger('error', { detail: event.detail });
}, this);
resolver(resolvePromise, rejectPromise);
};
var invokeCallback = function(type, promise, callback, event) {
var hasCallback = typeof callback === 'function',
value, error, succeeded, failed;
if (hasCallback) {
try {
value = callback(event.detail);
succeeded = true;
} catch(e) {
failed = true;
error = e;
}
} else {
value = event.detail;
succeeded = true;
}
if (value && typeof value.then === 'function') {
value.then(function(value) {
resolve(promise, value);
}, function(error) {
reject(promise, error);
});
} else if (hasCallback && succeeded) {
resolve(promise, value);
} else if (failed) {
reject(promise, error);
} else if (type === 'resolve') {
resolve(promise, value);
} else if (type === 'reject') {
reject(promise, value);
}
};
Promise.prototype = {
constructor: Promise,
then: function(done, fail) {
var thenPromise = new Promise(function() {});
if (this.isFulfilled) {
config.async(function() {
invokeCallback('resolve', thenPromise, done, { detail: this.fulfillmentValue });
}, this);
}
if (this.isRejected) {
config.async(function() {
invokeCallback('reject', thenPromise, fail, { detail: this.rejectedReason });
}, this);
}
this.on('promise:resolved', function(event) {
invokeCallback('resolve', thenPromise, done, event);
});
this.on('promise:failed', function(event) {
invokeCallback('reject', thenPromise, fail, event);
});
return thenPromise;
}
};
EventTarget.mixin(Promise.prototype);
function resolve(promise, value) {
if (value && typeof value.then === 'function') {
value.then(function(val) {
resolve(promise, val);
}, function(val) {
reject(promise, val);
});
} else {
fulfill(promise, value);
}
}
function fulfill(promise, value) {
config.async(function() {
promise.trigger('promise:resolved', { detail: value });
promise.isFulfilled = true;
promise.fulfillmentValue = value;
});
}
function reject(promise, value) {
config.async(function() {
promise.trigger('promise:failed', { detail: value });
promise.isRejected = true;
promise.rejectedReason = value;
});
}
export { Promise };
\ No newline at end of file
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