es6-promise-rails 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f552362c7d9fbd5e259b6d65c1689c21e643303e
4
+ data.tar.gz: 0b78ca9f58532e81217c83b9ffadb2cc6ee1749b
5
+ SHA512:
6
+ metadata.gz: 639b5f4b325c20a35eb8991c334b444295288ff3194dac2c0565843d0260aba54cae29280677c000a5df5f78ec3bf92089c3065a4da6d809327f3f95aad276fb
7
+ data.tar.gz: 883ccd18fd918721eb1356b2e616c2c701a4b7cd8296eea01e0f3fbcdaa529006a3fe509ba64e447d1507841d778ffbc02e0cf8371eac2319da3b64297f95666
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in es6-promise-rails.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,48 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ es6-promise-rails (1.0.0)
5
+ railties (>= 3.1.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionpack (4.1.1)
11
+ actionview (= 4.1.1)
12
+ activesupport (= 4.1.1)
13
+ rack (~> 1.5.2)
14
+ rack-test (~> 0.6.2)
15
+ actionview (4.1.1)
16
+ activesupport (= 4.1.1)
17
+ builder (~> 3.1)
18
+ erubis (~> 2.7.0)
19
+ activesupport (4.1.1)
20
+ i18n (~> 0.6, >= 0.6.9)
21
+ json (~> 1.7, >= 1.7.7)
22
+ minitest (~> 5.1)
23
+ thread_safe (~> 0.1)
24
+ tzinfo (~> 1.1)
25
+ builder (3.2.2)
26
+ erubis (2.7.0)
27
+ i18n (0.6.9)
28
+ json (1.8.1)
29
+ minitest (5.3.3)
30
+ rack (1.5.2)
31
+ rack-test (0.6.2)
32
+ rack (>= 1.0)
33
+ railties (4.1.1)
34
+ actionpack (= 4.1.1)
35
+ activesupport (= 4.1.1)
36
+ rake (>= 0.8.7)
37
+ thor (>= 0.18.1, < 2.0)
38
+ rake (10.3.1)
39
+ thor (0.19.1)
40
+ thread_safe (0.3.3)
41
+ tzinfo (1.1.0)
42
+ thread_safe (~> 0.1)
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ es6-promise-rails!
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Leonid Beder
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # es6-promise-rails
2
+
3
+ This is a bundled version of the [es6-promise](https://github.com/jakearchibald/es6-promise) library.
4
+
5
+ ## Install
6
+
7
+ In your Gemfile, add:
8
+
9
+ ```ruby
10
+ gem 'es6-promise-rails'
11
+ ```
12
+ Add it to your JavaScript manifest file:
13
+
14
+ ``` js
15
+ //= require promise
16
+ ```
17
+
18
+ ## License
19
+
20
+ The MIT License (MIT)
21
+
22
+ Copyright (c) 2014
23
+
24
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
25
+ this software and associated documentation files (the "Software"), to deal in
26
+ the Software without restriction, including without limitation the rights to
27
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
28
+ the Software, and to permit persons to whom the Software is furnished to do so,
29
+ subject to the following conditions:
30
+
31
+ The above copyright notice and this permission notice shall be included in all
32
+ copies or substantial portions of the Software.
33
+
34
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
36
+ FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
37
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
38
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
39
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,20 @@
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+ require 'es6/promise/rails/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'es6-promise-rails'
6
+ s.version = E6::Promise::Rails::VERSION
7
+ s.authors = ['Leonid Beder']
8
+ s.email = ['leonid.beder@gmail.com']
9
+ s.license = 'MIT'
10
+ s.homepage = ''
11
+ s.summary = 'A polyfill for ES6-style Promises with integration for Rails'
12
+ s.description = 'A polyfill for ES6-style Promises with integration for Rails.'
13
+
14
+ s.files = `git ls-files`.split($/)
15
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ s.test_files = s.files.grep(%r{^(test|s|features)/})
17
+ s.require_paths = ['lib']
18
+
19
+ s.add_dependency 'railties', '>= 3.1.0'
20
+ end
@@ -0,0 +1,10 @@
1
+ require 'es6/promise/rails/version'
2
+
3
+ module ES6
4
+ module Promise
5
+ module Rails
6
+ class Engine < ::Rails::Engine
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module E6
2
+ module Promise
3
+ module Rails
4
+ VERSION = '1.0.0'.freeze
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,690 @@
1
+ /**
2
+ * https://github.com/jakearchibald/es6-promise
3
+ *
4
+ * version: 1.0.0
5
+ */
6
+
7
+ (function() {
8
+ var define, requireModule, require, requirejs;
9
+
10
+ (function() {
11
+ var registry = {}, seen = {};
12
+
13
+ define = function(name, deps, callback) {
14
+ registry[name] = { deps: deps, callback: callback };
15
+ };
16
+
17
+ requirejs = require = requireModule = function(name) {
18
+ requirejs._eak_seen = registry;
19
+
20
+ if (seen[name]) { return seen[name]; }
21
+ seen[name] = {};
22
+
23
+ if (!registry[name]) {
24
+ throw new Error("Could not find module " + name);
25
+ }
26
+
27
+ var mod = registry[name],
28
+ deps = mod.deps,
29
+ callback = mod.callback,
30
+ reified = [],
31
+ exports;
32
+
33
+ for (var i=0, l=deps.length; i<l; i++) {
34
+ if (deps[i] === 'exports') {
35
+ reified.push(exports = {});
36
+ } else {
37
+ reified.push(requireModule(resolve(deps[i])));
38
+ }
39
+ }
40
+
41
+ var value = callback.apply(this, reified);
42
+ return seen[name] = exports || value;
43
+
44
+ function resolve(child) {
45
+ if (child.charAt(0) !== '.') { return child; }
46
+ var parts = child.split("/");
47
+ var parentBase = name.split("/").slice(0, -1);
48
+
49
+ for (var i=0, l=parts.length; i<l; i++) {
50
+ var part = parts[i];
51
+
52
+ if (part === '..') { parentBase.pop(); }
53
+ else if (part === '.') { continue; }
54
+ else { parentBase.push(part); }
55
+ }
56
+
57
+ return parentBase.join("/");
58
+ }
59
+ };
60
+ })();
61
+
62
+ define("promise/all",
63
+ ["./utils","exports"],
64
+ function(__dependency1__, __exports__) {
65
+ "use strict";
66
+ /* global toString */
67
+
68
+ var isArray = __dependency1__.isArray;
69
+ var isFunction = __dependency1__.isFunction;
70
+
71
+ /**
72
+ Returns a promise that is fulfilled when all the given promises have been
73
+ fulfilled, or rejected if any of them become rejected. The return promise
74
+ is fulfilled with an array that gives all the values in the order they were
75
+ passed in the `promises` array argument.
76
+
77
+ Example:
78
+
79
+ ```javascript
80
+ var promise1 = RSVP.resolve(1);
81
+ var promise2 = RSVP.resolve(2);
82
+ var promise3 = RSVP.resolve(3);
83
+ var promises = [ promise1, promise2, promise3 ];
84
+
85
+ RSVP.all(promises).then(function(array){
86
+ // The array here would be [ 1, 2, 3 ];
87
+ });
88
+ ```
89
+
90
+ If any of the `promises` given to `RSVP.all` are rejected, the first promise
91
+ that is rejected will be given as an argument to the returned promises's
92
+ rejection handler. For example:
93
+
94
+ Example:
95
+
96
+ ```javascript
97
+ var promise1 = RSVP.resolve(1);
98
+ var promise2 = RSVP.reject(new Error("2"));
99
+ var promise3 = RSVP.reject(new Error("3"));
100
+ var promises = [ promise1, promise2, promise3 ];
101
+
102
+ RSVP.all(promises).then(function(array){
103
+ // Code here never runs because there are rejected promises!
104
+ }, function(error) {
105
+ // error.message === "2"
106
+ });
107
+ ```
108
+
109
+ @method all
110
+ @for RSVP
111
+ @param {Array} promises
112
+ @param {String} label
113
+ @return {Promise} promise that is fulfilled when all `promises` have been
114
+ fulfilled, or rejected if any of them become rejected.
115
+ */
116
+ function all(promises) {
117
+ /*jshint validthis:true */
118
+ var Promise = this;
119
+
120
+ if (!isArray(promises)) {
121
+ throw new TypeError('You must pass an array to all.');
122
+ }
123
+
124
+ return new Promise(function(resolve, reject) {
125
+ var results = [], remaining = promises.length,
126
+ promise;
127
+
128
+ if (remaining === 0) {
129
+ resolve([]);
130
+ }
131
+
132
+ function resolver(index) {
133
+ return function(value) {
134
+ resolveAll(index, value);
135
+ };
136
+ }
137
+
138
+ function resolveAll(index, value) {
139
+ results[index] = value;
140
+ if (--remaining === 0) {
141
+ resolve(results);
142
+ }
143
+ }
144
+
145
+ for (var i = 0; i < promises.length; i++) {
146
+ promise = promises[i];
147
+
148
+ if (promise && isFunction(promise.then)) {
149
+ promise.then(resolver(i), reject);
150
+ } else {
151
+ resolveAll(i, promise);
152
+ }
153
+ }
154
+ });
155
+ }
156
+
157
+ __exports__.all = all;
158
+ });
159
+ define("promise/asap",
160
+ ["exports"],
161
+ function(__exports__) {
162
+ "use strict";
163
+ var browserGlobal = (typeof window !== 'undefined') ? window : {};
164
+ var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
165
+ var local = (typeof global !== 'undefined') ? global : (this === undefined? window:this);
166
+
167
+ // node
168
+ function useNextTick() {
169
+ return function() {
170
+ process.nextTick(flush);
171
+ };
172
+ }
173
+
174
+ function useMutationObserver() {
175
+ var iterations = 0;
176
+ var observer = new BrowserMutationObserver(flush);
177
+ var node = document.createTextNode('');
178
+ observer.observe(node, { characterData: true });
179
+
180
+ return function() {
181
+ node.data = (iterations = ++iterations % 2);
182
+ };
183
+ }
184
+
185
+ function useSetTimeout() {
186
+ return function() {
187
+ local.setTimeout(flush, 1);
188
+ };
189
+ }
190
+
191
+ var queue = [];
192
+ function flush() {
193
+ for (var i = 0; i < queue.length; i++) {
194
+ var tuple = queue[i];
195
+ var callback = tuple[0], arg = tuple[1];
196
+ callback(arg);
197
+ }
198
+ queue = [];
199
+ }
200
+
201
+ var scheduleFlush;
202
+
203
+ // Decide what async method to use to triggering processing of queued callbacks:
204
+ if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
205
+ scheduleFlush = useNextTick();
206
+ } else if (BrowserMutationObserver) {
207
+ scheduleFlush = useMutationObserver();
208
+ } else {
209
+ scheduleFlush = useSetTimeout();
210
+ }
211
+
212
+ function asap(callback, arg) {
213
+ var length = queue.push([callback, arg]);
214
+ if (length === 1) {
215
+ // If length is 1, that means that we need to schedule an async flush.
216
+ // If additional callbacks are queued before the queue is flushed, they
217
+ // will be processed by this flush that we are scheduling.
218
+ scheduleFlush();
219
+ }
220
+ }
221
+
222
+ __exports__.asap = asap;
223
+ });
224
+ define("promise/config",
225
+ ["exports"],
226
+ function(__exports__) {
227
+ "use strict";
228
+ var config = {
229
+ instrument: false
230
+ };
231
+
232
+ function configure(name, value) {
233
+ if (arguments.length === 2) {
234
+ config[name] = value;
235
+ } else {
236
+ return config[name];
237
+ }
238
+ }
239
+
240
+ __exports__.config = config;
241
+ __exports__.configure = configure;
242
+ });
243
+ define("promise/polyfill",
244
+ ["./promise","./utils","exports"],
245
+ function(__dependency1__, __dependency2__, __exports__) {
246
+ "use strict";
247
+ /*global self*/
248
+ var RSVPPromise = __dependency1__.Promise;
249
+ var isFunction = __dependency2__.isFunction;
250
+
251
+ function polyfill() {
252
+ var local;
253
+
254
+ if (typeof global !== 'undefined') {
255
+ local = global;
256
+ } else if (typeof window !== 'undefined' && window.document) {
257
+ local = window;
258
+ } else {
259
+ local = self;
260
+ }
261
+
262
+ var es6PromiseSupport =
263
+ "Promise" in local &&
264
+ // Some of these methods are missing from
265
+ // Firefox/Chrome experimental implementations
266
+ "resolve" in local.Promise &&
267
+ "reject" in local.Promise &&
268
+ "all" in local.Promise &&
269
+ "race" in local.Promise &&
270
+ // Older version of the spec had a resolver object
271
+ // as the arg rather than a function
272
+ (function() {
273
+ var resolve;
274
+ new local.Promise(function(r) { resolve = r; });
275
+ return isFunction(resolve);
276
+ }());
277
+
278
+ if (!es6PromiseSupport) {
279
+ local.Promise = RSVPPromise;
280
+ }
281
+ }
282
+
283
+ __exports__.polyfill = polyfill;
284
+ });
285
+ define("promise/promise",
286
+ ["./config","./utils","./all","./race","./resolve","./reject","./asap","exports"],
287
+ function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__, __dependency6__, __dependency7__, __exports__) {
288
+ "use strict";
289
+ var config = __dependency1__.config;
290
+ var configure = __dependency1__.configure;
291
+ var objectOrFunction = __dependency2__.objectOrFunction;
292
+ var isFunction = __dependency2__.isFunction;
293
+ var now = __dependency2__.now;
294
+ var all = __dependency3__.all;
295
+ var race = __dependency4__.race;
296
+ var staticResolve = __dependency5__.resolve;
297
+ var staticReject = __dependency6__.reject;
298
+ var asap = __dependency7__.asap;
299
+
300
+ var counter = 0;
301
+
302
+ config.async = asap; // default async is asap;
303
+
304
+ function Promise(resolver) {
305
+ if (!isFunction(resolver)) {
306
+ throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
307
+ }
308
+
309
+ if (!(this instanceof Promise)) {
310
+ throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
311
+ }
312
+
313
+ this._subscribers = [];
314
+
315
+ invokeResolver(resolver, this);
316
+ }
317
+
318
+ function invokeResolver(resolver, promise) {
319
+ function resolvePromise(value) {
320
+ resolve(promise, value);
321
+ }
322
+
323
+ function rejectPromise(reason) {
324
+ reject(promise, reason);
325
+ }
326
+
327
+ try {
328
+ resolver(resolvePromise, rejectPromise);
329
+ } catch(e) {
330
+ rejectPromise(e);
331
+ }
332
+ }
333
+
334
+ function invokeCallback(settled, promise, callback, detail) {
335
+ var hasCallback = isFunction(callback),
336
+ value, error, succeeded, failed;
337
+
338
+ if (hasCallback) {
339
+ try {
340
+ value = callback(detail);
341
+ succeeded = true;
342
+ } catch(e) {
343
+ failed = true;
344
+ error = e;
345
+ }
346
+ } else {
347
+ value = detail;
348
+ succeeded = true;
349
+ }
350
+
351
+ if (handleThenable(promise, value)) {
352
+ return;
353
+ } else if (hasCallback && succeeded) {
354
+ resolve(promise, value);
355
+ } else if (failed) {
356
+ reject(promise, error);
357
+ } else if (settled === FULFILLED) {
358
+ resolve(promise, value);
359
+ } else if (settled === REJECTED) {
360
+ reject(promise, value);
361
+ }
362
+ }
363
+
364
+ var PENDING = void 0;
365
+ var SEALED = 0;
366
+ var FULFILLED = 1;
367
+ var REJECTED = 2;
368
+
369
+ function subscribe(parent, child, onFulfillment, onRejection) {
370
+ var subscribers = parent._subscribers;
371
+ var length = subscribers.length;
372
+
373
+ subscribers[length] = child;
374
+ subscribers[length + FULFILLED] = onFulfillment;
375
+ subscribers[length + REJECTED] = onRejection;
376
+ }
377
+
378
+ function publish(promise, settled) {
379
+ var child, callback, subscribers = promise._subscribers, detail = promise._detail;
380
+
381
+ for (var i = 0; i < subscribers.length; i += 3) {
382
+ child = subscribers[i];
383
+ callback = subscribers[i + settled];
384
+
385
+ invokeCallback(settled, child, callback, detail);
386
+ }
387
+
388
+ promise._subscribers = null;
389
+ }
390
+
391
+ Promise.prototype = {
392
+ constructor: Promise,
393
+
394
+ _state: undefined,
395
+ _detail: undefined,
396
+ _subscribers: undefined,
397
+
398
+ then: function(onFulfillment, onRejection) {
399
+ var promise = this;
400
+
401
+ var thenPromise = new this.constructor(function() {});
402
+
403
+ if (this._state) {
404
+ var callbacks = arguments;
405
+ config.async(function invokePromiseCallback() {
406
+ invokeCallback(promise._state, thenPromise, callbacks[promise._state - 1], promise._detail);
407
+ });
408
+ } else {
409
+ subscribe(this, thenPromise, onFulfillment, onRejection);
410
+ }
411
+
412
+ return thenPromise;
413
+ },
414
+
415
+ 'catch': function(onRejection) {
416
+ return this.then(null, onRejection);
417
+ }
418
+ };
419
+
420
+ Promise.all = all;
421
+ Promise.race = race;
422
+ Promise.resolve = staticResolve;
423
+ Promise.reject = staticReject;
424
+
425
+ function handleThenable(promise, value) {
426
+ var then = null,
427
+ resolved;
428
+
429
+ try {
430
+ if (promise === value) {
431
+ throw new TypeError("A promises callback cannot return that same promise.");
432
+ }
433
+
434
+ if (objectOrFunction(value)) {
435
+ then = value.then;
436
+
437
+ if (isFunction(then)) {
438
+ then.call(value, function(val) {
439
+ if (resolved) { return true; }
440
+ resolved = true;
441
+
442
+ if (value !== val) {
443
+ resolve(promise, val);
444
+ } else {
445
+ fulfill(promise, val);
446
+ }
447
+ }, function(val) {
448
+ if (resolved) { return true; }
449
+ resolved = true;
450
+
451
+ reject(promise, val);
452
+ });
453
+
454
+ return true;
455
+ }
456
+ }
457
+ } catch (error) {
458
+ if (resolved) { return true; }
459
+ reject(promise, error);
460
+ return true;
461
+ }
462
+
463
+ return false;
464
+ }
465
+
466
+ function resolve(promise, value) {
467
+ if (promise === value) {
468
+ fulfill(promise, value);
469
+ } else if (!handleThenable(promise, value)) {
470
+ fulfill(promise, value);
471
+ }
472
+ }
473
+
474
+ function fulfill(promise, value) {
475
+ if (promise._state !== PENDING) { return; }
476
+ promise._state = SEALED;
477
+ promise._detail = value;
478
+
479
+ config.async(publishFulfillment, promise);
480
+ }
481
+
482
+ function reject(promise, reason) {
483
+ if (promise._state !== PENDING) { return; }
484
+ promise._state = SEALED;
485
+ promise._detail = reason;
486
+
487
+ config.async(publishRejection, promise);
488
+ }
489
+
490
+ function publishFulfillment(promise) {
491
+ publish(promise, promise._state = FULFILLED);
492
+ }
493
+
494
+ function publishRejection(promise) {
495
+ publish(promise, promise._state = REJECTED);
496
+ }
497
+
498
+ __exports__.Promise = Promise;
499
+ });
500
+ define("promise/race",
501
+ ["./utils","exports"],
502
+ function(__dependency1__, __exports__) {
503
+ "use strict";
504
+ /* global toString */
505
+ var isArray = __dependency1__.isArray;
506
+
507
+ /**
508
+ `RSVP.race` allows you to watch a series of promises and act as soon as the
509
+ first promise given to the `promises` argument fulfills or rejects.
510
+
511
+ Example:
512
+
513
+ ```javascript
514
+ var promise1 = new RSVP.Promise(function(resolve, reject){
515
+ setTimeout(function(){
516
+ resolve("promise 1");
517
+ }, 200);
518
+ });
519
+
520
+ var promise2 = new RSVP.Promise(function(resolve, reject){
521
+ setTimeout(function(){
522
+ resolve("promise 2");
523
+ }, 100);
524
+ });
525
+
526
+ RSVP.race([promise1, promise2]).then(function(result){
527
+ // result === "promise 2" because it was resolved before promise1
528
+ // was resolved.
529
+ });
530
+ ```
531
+
532
+ `RSVP.race` is deterministic in that only the state of the first completed
533
+ promise matters. For example, even if other promises given to the `promises`
534
+ array argument are resolved, but the first completed promise has become
535
+ rejected before the other promises became fulfilled, the returned promise
536
+ will become rejected:
537
+
538
+ ```javascript
539
+ var promise1 = new RSVP.Promise(function(resolve, reject){
540
+ setTimeout(function(){
541
+ resolve("promise 1");
542
+ }, 200);
543
+ });
544
+
545
+ var promise2 = new RSVP.Promise(function(resolve, reject){
546
+ setTimeout(function(){
547
+ reject(new Error("promise 2"));
548
+ }, 100);
549
+ });
550
+
551
+ RSVP.race([promise1, promise2]).then(function(result){
552
+ // Code here never runs because there are rejected promises!
553
+ }, function(reason){
554
+ // reason.message === "promise2" because promise 2 became rejected before
555
+ // promise 1 became fulfilled
556
+ });
557
+ ```
558
+
559
+ @method race
560
+ @for RSVP
561
+ @param {Array} promises array of promises to observe
562
+ @param {String} label optional string for describing the promise returned.
563
+ Useful for tooling.
564
+ @return {Promise} a promise that becomes fulfilled with the value the first
565
+ completed promises is resolved with if the first completed promise was
566
+ fulfilled, or rejected with the reason that the first completed promise
567
+ was rejected with.
568
+ */
569
+ function race(promises) {
570
+ /*jshint validthis:true */
571
+ var Promise = this;
572
+
573
+ if (!isArray(promises)) {
574
+ throw new TypeError('You must pass an array to race.');
575
+ }
576
+ return new Promise(function(resolve, reject) {
577
+ var results = [], promise;
578
+
579
+ for (var i = 0; i < promises.length; i++) {
580
+ promise = promises[i];
581
+
582
+ if (promise && typeof promise.then === 'function') {
583
+ promise.then(resolve, reject);
584
+ } else {
585
+ resolve(promise);
586
+ }
587
+ }
588
+ });
589
+ }
590
+
591
+ __exports__.race = race;
592
+ });
593
+ define("promise/reject",
594
+ ["exports"],
595
+ function(__exports__) {
596
+ "use strict";
597
+ /**
598
+ `RSVP.reject` returns a promise that will become rejected with the passed
599
+ `reason`. `RSVP.reject` is essentially shorthand for the following:
600
+
601
+ ```javascript
602
+ var promise = new RSVP.Promise(function(resolve, reject){
603
+ reject(new Error('WHOOPS'));
604
+ });
605
+
606
+ promise.then(function(value){
607
+ // Code here doesn't run because the promise is rejected!
608
+ }, function(reason){
609
+ // reason.message === 'WHOOPS'
610
+ });
611
+ ```
612
+
613
+ Instead of writing the above, your code now simply becomes the following:
614
+
615
+ ```javascript
616
+ var promise = RSVP.reject(new Error('WHOOPS'));
617
+
618
+ promise.then(function(value){
619
+ // Code here doesn't run because the promise is rejected!
620
+ }, function(reason){
621
+ // reason.message === 'WHOOPS'
622
+ });
623
+ ```
624
+
625
+ @method reject
626
+ @for RSVP
627
+ @param {Any} reason value that the returned promise will be rejected with.
628
+ @param {String} label optional string for identifying the returned promise.
629
+ Useful for tooling.
630
+ @return {Promise} a promise that will become rejected with the given
631
+ `reason`.
632
+ */
633
+ function reject(reason) {
634
+ /*jshint validthis:true */
635
+ var Promise = this;
636
+
637
+ return new Promise(function (resolve, reject) {
638
+ reject(reason);
639
+ });
640
+ }
641
+
642
+ __exports__.reject = reject;
643
+ });
644
+ define("promise/resolve",
645
+ ["exports"],
646
+ function(__exports__) {
647
+ "use strict";
648
+ function resolve(value) {
649
+ /*jshint validthis:true */
650
+ if (value && typeof value === 'object' && value.constructor === this) {
651
+ return value;
652
+ }
653
+
654
+ var Promise = this;
655
+
656
+ return new Promise(function(resolve) {
657
+ resolve(value);
658
+ });
659
+ }
660
+
661
+ __exports__.resolve = resolve;
662
+ });
663
+ define("promise/utils",
664
+ ["exports"],
665
+ function(__exports__) {
666
+ "use strict";
667
+ function objectOrFunction(x) {
668
+ return isFunction(x) || (typeof x === "object" && x !== null);
669
+ }
670
+
671
+ function isFunction(x) {
672
+ return typeof x === "function";
673
+ }
674
+
675
+ function isArray(x) {
676
+ return Object.prototype.toString.call(x) === "[object Array]";
677
+ }
678
+
679
+ // Date.now is not available in browsers < IE9
680
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now#Compatibility
681
+ var now = Date.now || function() { return new Date().getTime(); };
682
+
683
+
684
+ __exports__.objectOrFunction = objectOrFunction;
685
+ __exports__.isFunction = isFunction;
686
+ __exports__.isArray = isArray;
687
+ __exports__.now = now;
688
+ });
689
+ requireModule('promise/polyfill').polyfill();
690
+ }());
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: es6-promise-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Leonid Beder
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 3.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.1.0
27
+ description: A polyfill for ES6-style Promises with integration for Rails.
28
+ email:
29
+ - leonid.beder@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - .gitignore
35
+ - Gemfile
36
+ - Gemfile.lock
37
+ - LICENSE
38
+ - README.md
39
+ - Rakefile
40
+ - es6-promise-rails.gemspec
41
+ - lib/es6/promise/rails.rb
42
+ - lib/es6/promise/rails/version.rb
43
+ - vendor/assets/javascripts/promise.js
44
+ homepage: ''
45
+ licenses:
46
+ - MIT
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 2.2.2
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: A polyfill for ES6-style Promises with integration for Rails
68
+ test_files: []