@enact/core 3.4.9-experimental-3 → 3.4.9-experimental-7

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.
Files changed (113) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/{build/dispatcher → dispatcher}/dispatcher.d.ts +0 -0
  3. package/dispatcher/dispatcher.js +76 -57
  4. package/dispatcher/listeners.js +31 -19
  5. package/dispatcher/tests/dispatcher-specs.js +75 -100
  6. package/{build/handle → handle}/handle.d.ts +0 -0
  7. package/handle/handle.js +260 -212
  8. package/handle/tests/handle-specs.js +476 -601
  9. package/{build/hoc → hoc}/hoc.d.ts +0 -0
  10. package/hoc/hoc.js +47 -33
  11. package/hoc/tests/hoc-specs.js +85 -126
  12. package/{build/index.d.ts → index.d.ts} +0 -0
  13. package/index.js +1 -0
  14. package/{build/internal → internal}/ApiDecorator/ApiDecorator.d.ts +0 -0
  15. package/internal/ApiDecorator/ApiDecorator.js +107 -61
  16. package/internal/ApiDecorator/tests/ApiDecorator-specs.js +106 -97
  17. package/{build/internal → internal}/Registry/Registry.d.ts +0 -0
  18. package/internal/Registry/Registry.js +68 -51
  19. package/internal/Registry/tests/Registry-specs.js +201 -143
  20. package/{build/internal → internal}/deprecate/deprecate.d.ts +0 -0
  21. package/internal/deprecate/deprecate.js +85 -60
  22. package/{build/internal → internal}/prop-types/prop-types.d.ts +0 -0
  23. package/internal/prop-types/prop-types.js +68 -61
  24. package/{build/keymap → keymap}/index.d.ts +0 -0
  25. package/keymap/index.js +27 -15
  26. package/keymap/keymap.js +67 -52
  27. package/keymap/tests/keymap-specs.js +75 -104
  28. package/kind/computed.js +29 -16
  29. package/{build/kind → kind}/kind.d.ts +0 -0
  30. package/kind/kind.js +150 -114
  31. package/kind/styles.js +62 -47
  32. package/kind/tests/computed-specs.js +87 -86
  33. package/kind/tests/kind-specs.js +216 -214
  34. package/kind/tests/styles-specs.js +170 -223
  35. package/kind/util.js +15 -7
  36. package/package.json +1 -1
  37. package/{build/platform → platform}/platform.d.ts +0 -0
  38. package/platform/platform.js +263 -169
  39. package/platform/tests/platform-specs.js +92 -90
  40. package/{build/snapshot → snapshot}/snapshot.d.ts +0 -0
  41. package/snapshot/snapshot.js +34 -27
  42. package/useChainRefs/tests/useChainRefs-specs.js +46 -30
  43. package/{build/useChainRefs → useChainRefs}/useChainRefs.d.ts +0 -0
  44. package/useChainRefs/useChainRefs.js +49 -29
  45. package/useClass/tests/useClass-specs.js +51 -46
  46. package/{build/useClass → useClass}/useClass.d.ts +0 -0
  47. package/useClass/useClass.js +27 -9
  48. package/useHandlers/Handlers.js +55 -30
  49. package/useHandlers/tests/useHandlers-specs.js +79 -95
  50. package/{build/useHandlers → useHandlers}/useHandlers.d.ts +0 -0
  51. package/useHandlers/useHandlers.js +18 -11
  52. package/util/Job.js +203 -241
  53. package/util/tests/Job-specs.js +216 -204
  54. package/util/tests/util-specs.js +123 -146
  55. package/{build/util → util}/util.d.ts +0 -0
  56. package/util/util.js +146 -103
  57. package/build/CHANGELOG.md +0 -699
  58. package/build/README.md +0 -33
  59. package/build/dispatcher/dispatcher.js +0 -160
  60. package/build/dispatcher/listeners.js +0 -37
  61. package/build/dispatcher/package.json +0 -3
  62. package/build/dispatcher/tests/dispatcher-specs.js +0 -75
  63. package/build/handle/handle.js +0 -846
  64. package/build/handle/package.json +0 -3
  65. package/build/handle/tests/handle-specs.js +0 -476
  66. package/build/hoc/hoc.js +0 -102
  67. package/build/hoc/package.json +0 -3
  68. package/build/hoc/tests/hoc-specs.js +0 -90
  69. package/build/index.js +0 -2
  70. package/build/internal/ApiDecorator/ApiDecorator.js +0 -143
  71. package/build/internal/ApiDecorator/package.json +0 -3
  72. package/build/internal/ApiDecorator/tests/ApiDecorator-specs.js +0 -106
  73. package/build/internal/Registry/Registry.js +0 -76
  74. package/build/internal/Registry/package.json +0 -3
  75. package/build/internal/Registry/tests/Registry-specs.js +0 -201
  76. package/build/internal/deprecate/deprecate.js +0 -116
  77. package/build/internal/deprecate/package.json +0 -3
  78. package/build/internal/prop-types/package.json +0 -3
  79. package/build/internal/prop-types/prop-types.js +0 -90
  80. package/build/keymap/index.js +0 -54
  81. package/build/keymap/keymap.js +0 -201
  82. package/build/keymap/package.json +0 -3
  83. package/build/keymap/tests/keymap-specs.js +0 -75
  84. package/build/kind/computed.js +0 -60
  85. package/build/kind/kind.js +0 -266
  86. package/build/kind/package.json +0 -3
  87. package/build/kind/styles.js +0 -105
  88. package/build/kind/tests/computed-specs.js +0 -87
  89. package/build/kind/tests/kind-specs.js +0 -216
  90. package/build/kind/tests/styles-specs.js +0 -170
  91. package/build/kind/util.js +0 -17
  92. package/build/package-lock.json +0 -206
  93. package/build/package.json +0 -38
  94. package/build/platform/package.json +0 -3
  95. package/build/platform/platform.js +0 -306
  96. package/build/platform/tests/platform-specs.js +0 -92
  97. package/build/snapshot/package.json +0 -3
  98. package/build/snapshot/snapshot.js +0 -89
  99. package/build/useChainRefs/package.json +0 -3
  100. package/build/useChainRefs/tests/useChainRefs-specs.js +0 -57
  101. package/build/useChainRefs/useChainRefs.js +0 -78
  102. package/build/useClass/package.json +0 -3
  103. package/build/useClass/tests/useClass-specs.js +0 -51
  104. package/build/useClass/useClass.js +0 -59
  105. package/build/useHandlers/Handlers.js +0 -55
  106. package/build/useHandlers/package.json +0 -3
  107. package/build/useHandlers/tests/useHandlers-specs.js +0 -84
  108. package/build/useHandlers/useHandlers.js +0 -36
  109. package/build/util/Job.js +0 -211
  110. package/build/util/package.json +0 -3
  111. package/build/util/tests/Job-specs.js +0 -216
  112. package/build/util/tests/util-specs.js +0 -123
  113. package/build/util/util.js +0 -322
package/util/Job.js CHANGED
@@ -1,4 +1,19 @@
1
- import invariant from 'invariant';
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Job = exports["default"] = void 0;
7
+
8
+ var _invariant = _interopRequireDefault(require("invariant"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
+
12
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
13
+
14
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
15
+
16
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
2
17
 
3
18
  /**
4
19
  * Provides a convenient way to manage timed execution of functions.
@@ -7,243 +22,190 @@ import invariant from 'invariant';
7
22
  * @memberof core/util
8
23
  * @public
9
24
  */
10
- class Job {
11
- id = null;
12
- fn = null;
13
- timeout = null;
14
- type = null;
15
-
16
- /**
17
- * @constructor
18
- * @param {Function} fn Function to execute as the requested job.
19
- * @param {Number} timeout The number of milliseconds to wait before starting the job.
20
- *
21
- * @memberof core/util.Job.prototype
22
- */
23
- constructor (fn, timeout) {
24
- this.fn = fn;
25
- this.timeout = timeout;
26
- }
27
-
28
- run (args) {
29
- // don't want to inadvertently apply Job's context on `fn`
30
- return this.fn.apply(null, args);
31
- }
32
-
33
- /**
34
- * Starts the job.
35
- *
36
- * @method
37
- * @param {...*} [args] Any args passed are forwarded to the callback
38
- *
39
- * @returns {undefined}
40
- * @memberof core/util.Job.prototype
41
- * @public
42
- */
43
- start = (...args) => {
44
- this.startAfter(this.timeout, ...args);
45
- };
46
-
47
- /**
48
- * Starts the job in `timeout` milliseconds
49
- *
50
- * @method
51
- * @param {Number} timeout The number of milliseconds to wait before starting the job.
52
- * This supersedes the timeout set at construction.
53
- * @param {...*} [args] Any args passed are forwarded to the callback
54
- *
55
- * @returns {undefined}
56
- * @memberof core/util.Job.prototype
57
- * @public
58
- */
59
- startAfter = (timeout, ...args) => {
60
- this.stop();
61
- this.type = 'timeout';
62
- this.id = setTimeout(() => this.run(args), timeout);
63
- };
64
-
65
- /**
66
- * Stops the job.
67
- *
68
- * @method
69
- *
70
- * @returns {undefined}
71
- * @memberof core/util.Job.prototype
72
- * @public
73
- */
74
- stop = () => {
75
- if (this.id) {
76
- if (this.type === 'idle') {
77
- window.cancelIdleCallback(this.id);
78
- } else if (this.type === 'raf') {
79
- window.cancelAnimationFrame(this.id);
80
- } else if (this.type === 'timeout') {
81
- clearTimeout(this.id);
82
- }
83
- this.id = this.type = null;
84
- }
85
- };
86
-
87
- /**
88
- * Executes the job immediately, then prevents any other calls to `throttle()` from running
89
- * until the `timeout` configured at construction passes.
90
- *
91
- * @method
92
- * @param {...*} args Any args passed are forwarded to the callback
93
- *
94
- * @returns {undefined}
95
- * @memberof core/util.Job.prototype
96
- * @public
97
- */
98
- throttle = (...args) => {
99
- this.throttleUntil(this.timeout, ...args);
100
- };
101
-
102
- /**
103
- * Executes the job immediately, then prevents any other calls to `throttle()` from running for
104
- * `timeout` milliseconds.
105
- *
106
- * @method
107
- * @param {Number} timeout The number of milliseconds to wait before allowing the job to
108
- * be ran again. This supersedes the timeout set at construction.
109
- * @param {...*} [args] Any args passed are forwarded to the callback
110
- *
111
- * @returns {undefined}
112
- * @memberof core/util.Job.prototype
113
- * @public
114
- */
115
- throttleUntil = (timeout, ...args) => {
116
- if (!this.id) {
117
- this.type = 'timeout';
118
- this.run(args);
119
- this.id = setTimeout(this.stop, timeout);
120
- }
121
- };
122
-
123
- /**
124
- * Executes job when the CPU is idle.
125
- *
126
- * @method
127
- * @param {...*} [args] Any args passed are forwarded to the callback
128
- *
129
- * @returns {undefined}
130
- * @memberof core/util.Job.prototype
131
- * @public
132
- */
133
- idle = (...args) => {
134
- this.idleUntil(null, ...args);
135
- };
136
-
137
- /**
138
- * Executes job when the CPU is idle, or when the timeout is reached, whichever occurs first.
139
- *
140
- * @method
141
- * @param {Number} timeout The number of milliseconds to wait before executing the
142
- * job. This guarantees that the job is run, if a positive value
143
- * is specified.
144
- * @param {...*} [args] Any args passed are forwarded to the callback
145
- *
146
- * @returns {undefined}
147
- * @memberof core/util.Job.prototype
148
- * @public
149
- */
150
- idleUntil = (timeout, ...args) => {
151
- if (typeof window !== 'undefined' && window.requestIdleCallback) {
152
- this.stop();
153
- this.type = 'idle';
154
- this.id = window.requestIdleCallback(() => this.run(args), {timeout});
155
- } else {
156
- // since we can't request an idle callback, just pass to startAfter()
157
- this.startAfter(timeout, ...args);
158
- }
159
- };
160
-
161
- /**
162
- * Executes job before the next repaint.
163
- *
164
- * @method
165
- * @param {...*} [args] Any args passed are forwarded to the callback
166
- *
167
- * @returns {undefined}
168
- * @memberof core/util.Job.prototype
169
- * @public
170
- */
171
- startRaf = (...args) => {
172
- this.startRafAfter(this.timeout, ...args);
173
- };
174
-
175
- /**
176
- * Executes job before the next repaint after a given amount of timeout.
177
- *
178
- * @method
179
- * @param {Number} timeout The number of milliseconds to wait before running `requestAnimationFrame`.
180
- * @param {...*} [args] Any args passed are forwarded to the callback
181
- *
182
- * @returns {undefined}
183
- * @memberof core/util.Job.prototype
184
- * @public
185
- */
186
- startRafAfter = (timeout, ...args) => {
187
- this.type = 'raf';
188
- if (typeof window !== 'undefined') {
189
- let time = null;
190
- const callback = (timestamp) => {
191
- if (time === null) {
192
- time = timestamp;
193
- }
194
- if (timeout && timestamp - time < timeout) {
195
- this.id = window.requestAnimationFrame(callback);
196
- } else {
197
- time = null;
198
- this.run(args);
199
- window.cancelAnimationFrame(this.id);
200
- this.id = null;
201
- }
202
- };
203
- this.id = window.requestAnimationFrame(callback);
204
- } else {
205
- // If requestAnimationFrame is not supported just run the function immediately
206
- this.run(args);
207
- }
208
- };
209
-
210
- /**
211
- * Starts the job when `promise` resolves.
212
- *
213
- * The job execution is tied to the resolution of the last `Promise` passed. Like other methods
214
- * on `Job`, calling `promise()` again with a new `Promise` will block execution of the job
215
- * until that new `Promise` resolves. Any previous `Promise`s will still resolve normally but
216
- * will not trigger job execution.
217
- *
218
- * Unlike other methods on `Job`, `promise()` returns a `Promise` which is the result of calling
219
- * `then()` on the passed `promise`. That `Promise` resolves with either the result of job
220
- * execution or `undefined` if `Promise` was superseded by a subsequent `Promise` passed as
221
- * described above.
222
- *
223
- * @method
224
- * @param {Promise} promise The promise that must resolve before the job is executed
225
- *
226
- * @returns {Promise}
227
- * @memberof core/util.Job.prototype
228
- * @public
229
- */
230
- promise = (promise) => {
231
- invariant(
232
- promise && typeof promise.then === 'function',
233
- 'promise expects a thenable'
234
- );
235
-
236
- this.type = 'promise';
237
- this.id = promise;
238
-
239
- return promise.then(result => {
240
- if (this.id === promise) {
241
- this.stop();
242
- return this.run([result]);
243
- }
244
- });
245
- };
246
- }
247
-
248
- export default Job;
249
- export {Job};
25
+ var Job = /*#__PURE__*/function () {
26
+ /**
27
+ * @constructor
28
+ * @param {Function} fn Function to execute as the requested job.
29
+ * @param {Number} timeout The number of milliseconds to wait before starting the job.
30
+ *
31
+ * @memberof core/util.Job.prototype
32
+ */
33
+ function Job(fn, _timeout) {
34
+ var _this = this;
35
+
36
+ _classCallCheck(this, Job);
37
+
38
+ this.id = null;
39
+ this.fn = null;
40
+ this.timeout = null;
41
+ this.type = null;
42
+
43
+ this.start = function () {
44
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
45
+ args[_key] = arguments[_key];
46
+ }
47
+
48
+ _this.startAfter.apply(_this, [_this.timeout].concat(args));
49
+ };
50
+
51
+ this.startAfter = function (timeout) {
52
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
53
+ args[_key2 - 1] = arguments[_key2];
54
+ }
55
+
56
+ _this.stop();
57
+
58
+ _this.type = 'timeout';
59
+ _this.id = setTimeout(function () {
60
+ return _this.run(args);
61
+ }, timeout);
62
+ };
63
+
64
+ this.stop = function () {
65
+ if (_this.id) {
66
+ if (_this.type === 'idle') {
67
+ window.cancelIdleCallback(_this.id);
68
+ } else if (_this.type === 'raf') {
69
+ window.cancelAnimationFrame(_this.id);
70
+ } else if (_this.type === 'timeout') {
71
+ clearTimeout(_this.id);
72
+ }
73
+
74
+ _this.id = _this.type = null;
75
+ }
76
+ };
77
+
78
+ this.throttle = function () {
79
+ for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
80
+ args[_key3] = arguments[_key3];
81
+ }
82
+
83
+ _this.throttleUntil.apply(_this, [_this.timeout].concat(args));
84
+ };
85
+
86
+ this.throttleUntil = function (timeout) {
87
+ if (!_this.id) {
88
+ _this.type = 'timeout';
89
+
90
+ for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
91
+ args[_key4 - 1] = arguments[_key4];
92
+ }
93
+
94
+ _this.run(args);
95
+
96
+ _this.id = setTimeout(_this.stop, timeout);
97
+ }
98
+ };
99
+
100
+ this.idle = function () {
101
+ for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
102
+ args[_key5] = arguments[_key5];
103
+ }
104
+
105
+ _this.idleUntil.apply(_this, [null].concat(args));
106
+ };
107
+
108
+ this.idleUntil = function (timeout) {
109
+ for (var _len6 = arguments.length, args = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) {
110
+ args[_key6 - 1] = arguments[_key6];
111
+ }
112
+
113
+ if (typeof window !== 'undefined' && window.requestIdleCallback) {
114
+ _this.stop();
115
+
116
+ _this.type = 'idle';
117
+ _this.id = window.requestIdleCallback(function () {
118
+ return _this.run(args);
119
+ }, {
120
+ timeout: timeout
121
+ });
122
+ } else {
123
+ // since we can't request an idle callback, just pass to startAfter()
124
+ _this.startAfter.apply(_this, [timeout].concat(args));
125
+ }
126
+ };
127
+
128
+ this.startRaf = function () {
129
+ for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
130
+ args[_key7] = arguments[_key7];
131
+ }
132
+
133
+ _this.startRafAfter.apply(_this, [_this.timeout].concat(args));
134
+ };
135
+
136
+ this.startRafAfter = function (timeout) {
137
+ for (var _len8 = arguments.length, args = new Array(_len8 > 1 ? _len8 - 1 : 0), _key8 = 1; _key8 < _len8; _key8++) {
138
+ args[_key8 - 1] = arguments[_key8];
139
+ }
140
+
141
+ _this.type = 'raf';
142
+
143
+ if (typeof window !== 'undefined') {
144
+ var time = null;
145
+
146
+ var callback = function callback(timestamp) {
147
+ if (time === null) {
148
+ time = timestamp;
149
+ }
150
+
151
+ if (timeout && timestamp - time < timeout) {
152
+ _this.id = window.requestAnimationFrame(callback);
153
+ } else {
154
+ time = null;
155
+
156
+ _this.run(args);
157
+
158
+ window.cancelAnimationFrame(_this.id);
159
+ _this.id = null;
160
+ }
161
+ };
162
+
163
+ _this.id = window.requestAnimationFrame(callback);
164
+ } else {
165
+ // If requestAnimationFrame is not supported just run the function immediately
166
+ _this.run(args);
167
+ }
168
+ };
169
+
170
+ this.promise = function (promise) {
171
+ !(promise && typeof promise.then === 'function') ? process.env.NODE_ENV !== "production" ? (0, _invariant["default"])(false, 'promise expects a thenable') : invariant(false) : void 0;
172
+ _this.type = 'promise';
173
+ _this.id = promise;
174
+ return promise.then(function (result) {
175
+ if (_this.id === promise) {
176
+ _this.stop();
177
+
178
+ return _this.run([result]);
179
+ }
180
+ });
181
+ };
182
+
183
+ this.fn = fn;
184
+ this.timeout = _timeout;
185
+ }
186
+
187
+ _createClass(Job, [{
188
+ key: "run",
189
+ value: function run(args) {
190
+ // don't want to inadvertently apply Job's context on `fn`
191
+ return this.fn.apply(null, args);
192
+ }
193
+ /**
194
+ * Starts the job.
195
+ *
196
+ * @method
197
+ * @param {...*} [args] Any args passed are forwarded to the callback
198
+ *
199
+ * @returns {undefined}
200
+ * @memberof core/util.Job.prototype
201
+ * @public
202
+ */
203
+
204
+ }]);
205
+
206
+ return Job;
207
+ }();
208
+
209
+ exports.Job = Job;
210
+ var _default = Job;
211
+ exports["default"] = _default;