es6_promise_polyfill_rails 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +22 -0
- data/LICENSE +21 -0
- data/README.md +38 -0
- data/Rakefile +10 -0
- data/app/assets/javascripts/es6_promise_polyfill_rails.js +230 -0
- data/es6_promise_polyfill_rails.gemspec +23 -0
- data/lib/es6_promise_polyfill_rails.rb +5 -0
- data/lib/es6_promise_polyfill_rails/engine.rb +5 -0
- data/lib/es6_promise_polyfill_rails/version.rb +3 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d8e87e653f1cf427d1a1b7939ea7a1b31ed828b7
|
4
|
+
data.tar.gz: 6cb8a938f752182228eccd12d9e7ecaffa87b745
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 321d82ef803140309730c790be3e2281931febb64ef39f3ecc648a3d5ab24fdbfdb5429f58f45573c5ee7721e11985345ea29a961a5a06d2f9c55a0d6fb6fb75
|
7
|
+
data.tar.gz: b44de0750060847c9ae71511837eee79ff70819c0aa9f0199994f71d55200ccec98c1db8a32f5698ec52f1a1dbe29ac51c84aa57f47719b17e288e4d412d3f21
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
es6_promise_polyfill_rails (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
minitest (5.8.4)
|
10
|
+
rake (10.5.0)
|
11
|
+
|
12
|
+
PLATFORMS
|
13
|
+
ruby
|
14
|
+
|
15
|
+
DEPENDENCIES
|
16
|
+
bundler (~> 1.11)
|
17
|
+
minitest (~> 5.0)
|
18
|
+
rake (~> 10.0)
|
19
|
+
es6_promise_polyfill_rails!
|
20
|
+
|
21
|
+
BUNDLED WITH
|
22
|
+
1.11.2
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Robert Greene
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Es6PromisePolyfillRails - Es6 Promise Polyfill Rails Javascript packaged for the Rails asset pipeline
|
2
|
+
|
3
|
+
An es6 promise polyfill js gem packaged for the rails asset pipeline. The js was created by the awesome developer, [Taylor Hakes](https://github.com/taylorhakes). You can take a look at the original repo hosted here [https://github.com/taylorhakes/promise-polyfill](https://github.com/taylorhakes/promise-polyfill).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'es6_promise_polyfill_rails'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install es6_promise_polyfill_rails
|
20
|
+
|
21
|
+
Add it to your Javascript manifest file
|
22
|
+
|
23
|
+
//= require es6_promise_polyfill_rails
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Check out this repo [https://github.com/taylorhakes/promise-polyfill](https://github.com/taylorhakes/promise-polyfill).
|
28
|
+
|
29
|
+
## Development
|
30
|
+
|
31
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
32
|
+
|
33
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rardoz/es6_promise_polyfill_rails.
|
38
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,230 @@
|
|
1
|
+
(function (root) {
|
2
|
+
if(typeof Promise == 'function'){ return }
|
3
|
+
// Store setTimeout reference so promise-polyfill will be unaffected by
|
4
|
+
// other code modifying setTimeout (like sinon.useFakeTimers())
|
5
|
+
var setTimeoutFunc = setTimeout;
|
6
|
+
|
7
|
+
function noop() {
|
8
|
+
}
|
9
|
+
|
10
|
+
// Use polyfill for setImmediate for performance gains
|
11
|
+
var asap = (typeof setImmediate === 'function' && setImmediate) ||
|
12
|
+
function (fn) {
|
13
|
+
setTimeoutFunc(fn, 1);
|
14
|
+
};
|
15
|
+
|
16
|
+
var onUnhandledRejection = function onUnhandledRejection(err) {
|
17
|
+
console.warn('Possible Unhandled Promise Rejection:', err); // eslint-disable-line no-console
|
18
|
+
};
|
19
|
+
|
20
|
+
// Polyfill for Function.prototype.bind
|
21
|
+
function bind(fn, thisArg) {
|
22
|
+
return function () {
|
23
|
+
fn.apply(thisArg, arguments);
|
24
|
+
};
|
25
|
+
}
|
26
|
+
|
27
|
+
var isArray = Array.isArray || function (value) {
|
28
|
+
return Object.prototype.toString.call(value) === '[object Array]';
|
29
|
+
};
|
30
|
+
|
31
|
+
function Promise(fn) {
|
32
|
+
if (typeof this !== 'object') throw new TypeError('Promises must be constructed via new');
|
33
|
+
if (typeof fn !== 'function') throw new TypeError('not a function');
|
34
|
+
this._state = 0;
|
35
|
+
this._handled = false;
|
36
|
+
this._value = undefined;
|
37
|
+
this._deferreds = [];
|
38
|
+
|
39
|
+
doResolve(fn, this);
|
40
|
+
}
|
41
|
+
|
42
|
+
function handle(self, deferred) {
|
43
|
+
while (self._state === 3) {
|
44
|
+
self = self._value;
|
45
|
+
}
|
46
|
+
if (self._state === 0) {
|
47
|
+
self._deferreds.push(deferred);
|
48
|
+
return;
|
49
|
+
}
|
50
|
+
self._handled = true;
|
51
|
+
asap(function () {
|
52
|
+
var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected;
|
53
|
+
if (cb === null) {
|
54
|
+
(self._state === 1 ? resolve : reject)(deferred.promise, self._value);
|
55
|
+
return;
|
56
|
+
}
|
57
|
+
var ret;
|
58
|
+
try {
|
59
|
+
ret = cb(self._value);
|
60
|
+
} catch (e) {
|
61
|
+
reject(deferred.promise, e);
|
62
|
+
return;
|
63
|
+
}
|
64
|
+
resolve(deferred.promise, ret);
|
65
|
+
});
|
66
|
+
}
|
67
|
+
|
68
|
+
function resolve(self, newValue) {
|
69
|
+
try {
|
70
|
+
// Promise Resolution Procedure: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure
|
71
|
+
if (newValue === self) throw new TypeError('A promise cannot be resolved with itself.');
|
72
|
+
if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
|
73
|
+
var then = newValue.then;
|
74
|
+
if (newValue instanceof Promise) {
|
75
|
+
self._state = 3;
|
76
|
+
self._value = newValue;
|
77
|
+
finale(self);
|
78
|
+
return;
|
79
|
+
} else if (typeof then === 'function') {
|
80
|
+
doResolve(bind(then, newValue), self);
|
81
|
+
return;
|
82
|
+
}
|
83
|
+
}
|
84
|
+
self._state = 1;
|
85
|
+
self._value = newValue;
|
86
|
+
finale(self);
|
87
|
+
} catch (e) {
|
88
|
+
reject(self, e);
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
92
|
+
function reject(self, newValue) {
|
93
|
+
self._state = 2;
|
94
|
+
self._value = newValue;
|
95
|
+
finale(self);
|
96
|
+
}
|
97
|
+
|
98
|
+
function finale(self) {
|
99
|
+
if (self._state === 2 && self._deferreds.length === 0) {
|
100
|
+
setTimeout(function() {
|
101
|
+
if (!self._handled) {
|
102
|
+
onUnhandledRejection(self._value);
|
103
|
+
}
|
104
|
+
}, 1);
|
105
|
+
}
|
106
|
+
|
107
|
+
for (var i = 0, len = self._deferreds.length; i < len; i++) {
|
108
|
+
handle(self, self._deferreds[i]);
|
109
|
+
}
|
110
|
+
self._deferreds = null;
|
111
|
+
}
|
112
|
+
|
113
|
+
function Handler(onFulfilled, onRejected, promise) {
|
114
|
+
this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
|
115
|
+
this.onRejected = typeof onRejected === 'function' ? onRejected : null;
|
116
|
+
this.promise = promise;
|
117
|
+
}
|
118
|
+
|
119
|
+
/**
|
120
|
+
* Take a potentially misbehaving resolver function and make sure
|
121
|
+
* onFulfilled and onRejected are only called once.
|
122
|
+
*
|
123
|
+
* Makes no guarantees about asynchrony.
|
124
|
+
*/
|
125
|
+
function doResolve(fn, self) {
|
126
|
+
var done = false;
|
127
|
+
try {
|
128
|
+
fn(function (value) {
|
129
|
+
if (done) return;
|
130
|
+
done = true;
|
131
|
+
resolve(self, value);
|
132
|
+
}, function (reason) {
|
133
|
+
if (done) return;
|
134
|
+
done = true;
|
135
|
+
reject(self, reason);
|
136
|
+
});
|
137
|
+
} catch (ex) {
|
138
|
+
if (done) return;
|
139
|
+
done = true;
|
140
|
+
reject(self, ex);
|
141
|
+
}
|
142
|
+
}
|
143
|
+
|
144
|
+
Promise.prototype['catch'] = function (onRejected) {
|
145
|
+
return this.then(null, onRejected);
|
146
|
+
};
|
147
|
+
|
148
|
+
Promise.prototype.then = function (onFulfilled, onRejected) {
|
149
|
+
var prom = new Promise(noop);
|
150
|
+
handle(this, new Handler(onFulfilled, onRejected, prom));
|
151
|
+
return prom;
|
152
|
+
};
|
153
|
+
|
154
|
+
Promise.all = function () {
|
155
|
+
var args = Array.prototype.slice.call(arguments.length === 1 && isArray(arguments[0]) ? arguments[0] : arguments);
|
156
|
+
|
157
|
+
return new Promise(function (resolve, reject) {
|
158
|
+
if (args.length === 0) return resolve([]);
|
159
|
+
var remaining = args.length;
|
160
|
+
|
161
|
+
function res(i, val) {
|
162
|
+
try {
|
163
|
+
if (val && (typeof val === 'object' || typeof val === 'function')) {
|
164
|
+
var then = val.then;
|
165
|
+
if (typeof then === 'function') {
|
166
|
+
then.call(val, function (val) {
|
167
|
+
res(i, val);
|
168
|
+
}, reject);
|
169
|
+
return;
|
170
|
+
}
|
171
|
+
}
|
172
|
+
args[i] = val;
|
173
|
+
if (--remaining === 0) {
|
174
|
+
resolve(args);
|
175
|
+
}
|
176
|
+
} catch (ex) {
|
177
|
+
reject(ex);
|
178
|
+
}
|
179
|
+
}
|
180
|
+
|
181
|
+
for (var i = 0; i < args.length; i++) {
|
182
|
+
res(i, args[i]);
|
183
|
+
}
|
184
|
+
});
|
185
|
+
};
|
186
|
+
|
187
|
+
Promise.resolve = function (value) {
|
188
|
+
if (value && typeof value === 'object' && value.constructor === Promise) {
|
189
|
+
return value;
|
190
|
+
}
|
191
|
+
|
192
|
+
return new Promise(function (resolve) {
|
193
|
+
resolve(value);
|
194
|
+
});
|
195
|
+
};
|
196
|
+
|
197
|
+
Promise.reject = function (value) {
|
198
|
+
return new Promise(function (resolve, reject) {
|
199
|
+
reject(value);
|
200
|
+
});
|
201
|
+
};
|
202
|
+
|
203
|
+
Promise.race = function (values) {
|
204
|
+
return new Promise(function (resolve, reject) {
|
205
|
+
for (var i = 0, len = values.length; i < len; i++) {
|
206
|
+
values[i].then(resolve, reject);
|
207
|
+
}
|
208
|
+
});
|
209
|
+
};
|
210
|
+
|
211
|
+
/**
|
212
|
+
* Set the immediate function to execute callbacks
|
213
|
+
* @param fn {function} Function to execute
|
214
|
+
* @private
|
215
|
+
*/
|
216
|
+
Promise._setImmediateFn = function _setImmediateFn(fn) {
|
217
|
+
asap = fn;
|
218
|
+
};
|
219
|
+
|
220
|
+
Promise._setUnhandledRejectionFn = function _setUnhandledRejectionFn(fn) {
|
221
|
+
onUnhandledRejection = fn;
|
222
|
+
};
|
223
|
+
|
224
|
+
if (typeof module !== 'undefined' && module.exports) {
|
225
|
+
module.exports = Promise;
|
226
|
+
} else if (!root.Promise) {
|
227
|
+
root.Promise = Promise;
|
228
|
+
}
|
229
|
+
|
230
|
+
})(this);
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'es6_promise_polyfill_rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "es6_promise_polyfill_rails"
|
8
|
+
spec.version = Es6PromisePolyfillRails::VERSION
|
9
|
+
spec.authors = ["Robert Greene"]
|
10
|
+
spec.email = ["rgreene@avvo.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Es6 Promise Polyfill Rails Javascript packaged for the Rails asset pipeline}
|
13
|
+
spec.description = %q{Es6 Promise Polyfill Rails Javascript packaged for the Rails asset pipeline}
|
14
|
+
spec.homepage = "http://www.github.com/rardoz"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
spec.license = "MIT"
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: es6_promise_polyfill_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert Greene
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description: Es6 Promise Polyfill Rails Javascript packaged for the Rails asset pipeline
|
56
|
+
email:
|
57
|
+
- rgreene@avvo.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- Gemfile
|
63
|
+
- Gemfile.lock
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- app/assets/javascripts/es6_promise_polyfill_rails.js
|
68
|
+
- es6_promise_polyfill_rails.gemspec
|
69
|
+
- lib/es6_promise_polyfill_rails.rb
|
70
|
+
- lib/es6_promise_polyfill_rails/engine.rb
|
71
|
+
- lib/es6_promise_polyfill_rails/version.rb
|
72
|
+
homepage: http://www.github.com/rardoz
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.4.8
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Es6 Promise Polyfill Rails Javascript packaged for the Rails asset pipeline
|
96
|
+
test_files: []
|
97
|
+
has_rdoc:
|