ember-source 5.11.0 → 5.11.1

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 (147) hide show
  1. package/build-metadata.json +3 -3
  2. package/dist/ember-template-compiler.js +48 -42
  3. package/dist/ember-testing.js +1 -1
  4. package/dist/ember.debug.js +23102 -23100
  5. package/dist/ember.prod.js +31562 -31563
  6. package/dist/packages/@ember/-internals/container/index.js +1 -1
  7. package/dist/packages/@ember/-internals/deprecations/index.js +2 -1
  8. package/dist/packages/@ember/-internals/glimmer/index.js +2 -1
  9. package/dist/packages/@ember/-internals/meta/lib/meta.js +4 -3
  10. package/dist/packages/@ember/-internals/metal/index.js +9 -8
  11. package/dist/packages/@ember/-internals/routing/index.js +6 -5
  12. package/dist/packages/@ember/-internals/runtime/lib/ext/rsvp.js +3 -2
  13. package/dist/packages/@ember/-internals/runtime/lib/mixins/-proxy.js +6 -5
  14. package/dist/packages/@ember/-internals/runtime/lib/mixins/action_handler.js +4 -3
  15. package/dist/packages/@ember/-internals/runtime/lib/mixins/container_proxy.js +1 -1
  16. package/dist/packages/@ember/-internals/runtime/lib/mixins/registry_proxy.js +2 -1
  17. package/dist/packages/@ember/-internals/runtime/lib/mixins/target_action_support.js +4 -3
  18. package/dist/packages/@ember/-internals/string/index.js +1 -1
  19. package/dist/packages/@ember/-internals/utils/index.js +4 -4
  20. package/dist/packages/@ember/-internals/views/index.js +1 -1
  21. package/dist/packages/@ember/-internals/views/lib/compat/fallback-view-registry.js +1 -1
  22. package/dist/packages/@ember/-internals/views/lib/component_lookup.js +1 -1
  23. package/dist/packages/@ember/-internals/views/lib/mixins/action_support.js +5 -3
  24. package/dist/packages/@ember/-internals/views/lib/mixins/child_views_support.js +3 -3
  25. package/dist/packages/@ember/-internals/views/lib/mixins/class_names_support.js +4 -3
  26. package/dist/packages/@ember/-internals/views/lib/mixins/view_support.js +4 -3
  27. package/dist/packages/@ember/-internals/views/lib/system/event_dispatcher.js +6 -12
  28. package/dist/packages/@ember/-internals/views/lib/system/utils.js +3 -2
  29. package/dist/packages/@ember/-internals/views/lib/views/core_view.js +76 -8
  30. package/dist/packages/@ember/-internals/views/lib/views/states.js +4 -3
  31. package/dist/packages/@ember/application/index.js +16 -7
  32. package/dist/packages/@ember/application/instance.js +13 -9
  33. package/dist/packages/@ember/application/namespace.js +7 -6
  34. package/dist/packages/@ember/array/index.js +617 -11
  35. package/dist/packages/@ember/array/make.js +1 -0
  36. package/dist/packages/@ember/array/mutable.js +1 -1
  37. package/dist/packages/@ember/array/proxy.js +8 -5
  38. package/dist/packages/@ember/component/helper.js +4 -4
  39. package/dist/packages/@ember/component/index.js +4 -4
  40. package/dist/packages/@ember/controller/index.js +6 -6
  41. package/dist/packages/@ember/debug/container-debug-adapter.js +5 -4
  42. package/dist/packages/@ember/debug/data-adapter.js +7 -4
  43. package/dist/packages/@ember/debug/index.js +213 -4
  44. package/dist/packages/@ember/debug/lib/assert.js +47 -0
  45. package/dist/packages/@ember/debug/lib/deprecate.js +194 -4
  46. package/dist/packages/@ember/debug/lib/inspect.js +120 -2
  47. package/dist/packages/@ember/debug/lib/warn.js +94 -3
  48. package/dist/packages/@ember/engine/index.js +440 -17
  49. package/dist/packages/@ember/engine/instance.js +175 -11
  50. package/dist/packages/@ember/engine/parent.js +1 -0
  51. package/dist/packages/@ember/helper/index.js +4 -4
  52. package/dist/packages/@ember/instrumentation/index.js +2 -1
  53. package/dist/packages/@ember/modifier/index.js +13 -5
  54. package/dist/packages/@ember/modifier/on.js +15 -0
  55. package/dist/packages/@ember/object/-internals.js +6 -5
  56. package/dist/packages/@ember/object/compat.js +4 -3
  57. package/dist/packages/@ember/object/computed.js +4 -4
  58. package/dist/packages/@ember/object/core.js +861 -14
  59. package/dist/packages/@ember/object/evented.js +4 -4
  60. package/dist/packages/@ember/object/events.js +3 -3
  61. package/dist/packages/@ember/object/index.js +260 -9
  62. package/dist/packages/@ember/object/internals.js +1 -1
  63. package/dist/packages/@ember/object/lib/computed/computed_macros.js +8 -6
  64. package/dist/packages/@ember/object/lib/computed/reduce_computed_macros.js +8 -4
  65. package/dist/packages/@ember/object/mixin.js +6 -5
  66. package/dist/packages/@ember/object/observable.js +103 -9
  67. package/dist/packages/@ember/object/observers.js +3 -3
  68. package/dist/packages/@ember/object/promise-proxy-mixin.js +5 -5
  69. package/dist/packages/@ember/renderer/index.js +4 -4
  70. package/dist/packages/@ember/routing/-internals.js +3 -1
  71. package/dist/packages/@ember/routing/hash-location.js +2 -2
  72. package/dist/packages/@ember/routing/history-location.js +3 -2
  73. package/dist/packages/@ember/routing/index.js +4 -4
  74. package/dist/packages/@ember/routing/lib/dsl.js +2 -1
  75. package/dist/packages/@ember/routing/lib/generate_controller.js +4 -3
  76. package/dist/packages/@ember/routing/lib/router_state.js +26 -1
  77. package/dist/packages/@ember/routing/lib/routing-service.js +107 -9
  78. package/dist/packages/@ember/routing/lib/utils.js +238 -7
  79. package/dist/packages/@ember/routing/none-location.js +3 -2
  80. package/dist/packages/@ember/routing/route.js +1618 -22
  81. package/dist/packages/@ember/routing/router-service.js +638 -12
  82. package/dist/packages/@ember/routing/router.js +1449 -14
  83. package/dist/packages/@ember/runloop/index.js +760 -6
  84. package/dist/packages/@ember/service/index.js +3 -3
  85. package/dist/packages/@ember/template/index.js +4 -4
  86. package/dist/packages/@ember/utils/index.js +2 -1
  87. package/dist/packages/@ember/utils/lib/compare.js +159 -4
  88. package/dist/packages/@ember/utils/lib/is_empty.js +4 -4
  89. package/dist/packages/@ember/utils/lib/type-of.js +110 -1
  90. package/dist/packages/@glimmer/tracking/index.js +3 -3
  91. package/dist/packages/@glimmer/tracking/primitives/cache.js +3 -3
  92. package/dist/packages/ember/barrel.js +28 -13
  93. package/dist/packages/ember/version.js +1 -1
  94. package/dist/packages/ember-testing/lib/adapters/adapter.js +1 -1
  95. package/dist/packages/ember-testing/lib/adapters/qunit.js +2 -1
  96. package/dist/packages/ember-testing/lib/ext/application.js +2 -1
  97. package/dist/packages/ember-testing/lib/ext/rsvp.js +1 -1
  98. package/dist/packages/ember-testing/lib/helpers/and_then.js +2 -1
  99. package/dist/packages/ember-testing/lib/helpers/current_path.js +8 -6
  100. package/dist/packages/ember-testing/lib/helpers/current_route_name.js +8 -6
  101. package/dist/packages/ember-testing/lib/helpers/current_url.js +6 -5
  102. package/dist/packages/ember-testing/lib/helpers/pause_test.js +2 -1
  103. package/dist/packages/ember-testing/lib/helpers/visit.js +4 -3
  104. package/dist/packages/ember-testing/lib/helpers/wait.js +4 -3
  105. package/dist/packages/ember-testing/lib/initializers.js +15 -8
  106. package/dist/packages/ember-testing/lib/setup_for_testing.js +1 -1
  107. package/dist/packages/ember-testing/lib/test/run.js +1 -1
  108. package/dist/packages/router_js/index.js +2 -1
  109. package/dist/packages/shared-chunks/{alias-By_2yu5c.js → alias-Dri0koi2.js} +5 -3
  110. package/dist/packages/shared-chunks/array-3xbmc_4J.js +119 -0
  111. package/dist/packages/shared-chunks/{cache-gDE3bkXq.js → cache-BESCGvbE.js} +667 -1529
  112. package/dist/packages/shared-chunks/{core_view-Cxne2_wu.js → chunk-3SQBS3Y5-Cj4eryg1.js} +1 -88
  113. package/dist/packages/shared-chunks/{index-BXPoca1S.js → index-Llq6dmgX.js} +40 -4660
  114. package/dist/packages/shared-chunks/{is_proxy-Dmis-70B.js → is_proxy-DjvCKvd5.js} +1 -1
  115. package/dist/packages/shared-chunks/{mandatory-setter-1UQhiJOb.js → mandatory-setter-BiXq-dpN.js} +2 -1
  116. package/dist/packages/shared-chunks/{name-z9D9Yibn.js → name-Dx2bGFVv.js} +1 -1
  117. package/dist/packages/shared-chunks/{namespace_search-CBgHTkDh.js → namespace_search-btMaPM-_.js} +2 -2
  118. package/dist/packages/shared-chunks/{property_set-CW4q-uo4.js → property_set-BapAkp3X.js} +5 -4
  119. package/dist/packages/shared-chunks/{registry-DzfcDwii.js → registry-B8WARvkP.js} +3 -2
  120. package/dist/packages/shared-chunks/{router-B-Q1aYBn.js → router-DrLZsJeE.js} +2 -482
  121. package/dist/packages/shared-chunks/{set_properties-DvalyQdu.js → set_properties-BScfxzvI.js} +2 -2
  122. package/dist/packages/shared-chunks/setup-registry-du4pSGZi.js +48 -0
  123. package/dist/packages/shared-chunks/{to-string-D8i3mjEU.js → to-string-B1BmwUkt.js} +1 -1
  124. package/dist/packages/shared-chunks/unrecognized-url-error-zpz-JEoG.js +484 -0
  125. package/docs/data.json +152 -142
  126. package/package.json +2 -2
  127. package/types/stable/@ember/-internals/metal/lib/array.d.ts +1 -2
  128. package/types/stable/@ember/-internals/metal/lib/object-at.d.ts +4 -0
  129. package/types/stable/@ember/-internals/metal/lib/observer.d.ts +2 -1
  130. package/types/stable/@ember/array/index.d.ts +1 -1
  131. package/types/stable/@ember/array/make.d.ts +3 -0
  132. package/types/stable/@ember/debug/index.d.ts +3 -7
  133. package/types/stable/@ember/debug/lib/assert.d.ts +8 -0
  134. package/types/stable/@ember/engine/index.d.ts +1 -1
  135. package/types/stable/@ember/engine/instance.d.ts +2 -2
  136. package/types/stable/@ember/engine/parent.d.ts +3 -0
  137. package/types/stable/@ember/modifier/index.d.ts +1 -3
  138. package/types/stable/@ember/modifier/on.d.ts +5 -0
  139. package/types/stable/@ember/routing/lib/routing-service.d.ts +1 -1
  140. package/types/stable/@ember/routing/route.d.ts +2 -3
  141. package/types/stable/@ember/routing/router-service.d.ts +1 -1
  142. package/types/stable/@ember/routing/router.d.ts +4 -4
  143. package/types/stable/ember/barrel.d.ts +1 -1
  144. package/types/stable/ember/index.d.ts +1 -1
  145. package/types/stable/index.d.ts +5 -0
  146. package/dist/packages/shared-chunks/index-DTxy4Zgx.js +0 -641
  147. package/dist/packages/shared-chunks/index-PYiGj1jp.js +0 -2071
@@ -1,11 +1,765 @@
1
- import '../../shared-chunks/index-DTxy4Zgx.js';
2
- import '../-internals/error-handling/index.js';
1
+ import '../debug/index.js';
2
+ import { onErrorTarget } from '../-internals/error-handling/index.js';
3
3
  import '../-internals/meta/lib/meta.js';
4
- import '../../shared-chunks/mandatory-setter-1UQhiJOb.js';
5
- import '@embroider/macros';
4
+ import '../../shared-chunks/mandatory-setter-BiXq-dpN.js';
5
+ import { isDevelopingApp } from '@embroider/macros';
6
6
  import '../../@glimmer/destroyable/index.js';
7
7
  import '../../@glimmer/validator/index.js';
8
- export { _ as _backburner, al as _cancelTimers, Z as _getCurrentRunLoop, $ as _hasScheduledTimers, ai as _queues, b as _rsvpErrorQueue, aj as begin, P as bind, ah as cancel, an as debounce, ak as end, j as join, am as later, X as next, N as once, O as run, s as schedule, ag as scheduleOnce, ao as throttle } from '../../shared-chunks/cache-gDE3bkXq.js';
9
8
  import '../../@glimmer/manager/index.js';
9
+ import { I as flushAsyncObservers } from '../../shared-chunks/cache-BESCGvbE.js';
10
10
  import '../../shared-chunks/env-BJLX2Arx.js';
11
- import '../../backburner.js/index.js';
11
+ import Backburner from '../../backburner.js/index.js';
12
+ import { assert } from '../debug/lib/assert.js';
13
+
14
+ let currentRunLoop = null;
15
+ function _getCurrentRunLoop() {
16
+ return currentRunLoop;
17
+ }
18
+ function onBegin(current) {
19
+ currentRunLoop = current;
20
+ }
21
+ function onEnd(_current, next) {
22
+ currentRunLoop = next;
23
+ flushAsyncObservers(schedule);
24
+ }
25
+ function flush(queueName, next) {
26
+ if (queueName === 'render' || queueName === _rsvpErrorQueue) {
27
+ flushAsyncObservers(schedule);
28
+ }
29
+ next();
30
+ }
31
+ const _rsvpErrorQueue = `${Math.random()}${Date.now()}`.replace('.', '');
32
+
33
+ /**
34
+ Array of named queues. This array determines the order in which queues
35
+ are flushed at the end of the RunLoop. You can define your own queues by
36
+ simply adding the queue name to this array. Normally you should not need
37
+ to inspect or modify this property.
38
+
39
+ @property queues
40
+ @type Array
41
+ @default ['actions', 'destroy']
42
+ @private
43
+ */
44
+ const _queues = ['actions',
45
+ // used in router transitions to prevent unnecessary loading state entry
46
+ // if all context promises resolve on the 'actions' queue first
47
+ 'routerTransitions', 'render', 'afterRender', 'destroy',
48
+ // used to re-throw unhandled RSVP rejection errors specifically in this
49
+ // position to avoid breaking anything rendered in the other sections
50
+ _rsvpErrorQueue];
51
+
52
+ /**
53
+ * @internal
54
+ * @private
55
+ */
56
+ const _backburner = new Backburner(_queues, {
57
+ defaultQueue: 'actions',
58
+ onBegin,
59
+ onEnd,
60
+ onErrorTarget,
61
+ onErrorMethod: 'onerror',
62
+ flush
63
+ });
64
+
65
+ /**
66
+ @module @ember/runloop
67
+ */
68
+ // ..........................................................
69
+ // run - this is ideally the only public API the dev sees
70
+ //
71
+
72
+ /**
73
+ Runs the passed target and method inside of a RunLoop, ensuring any
74
+ deferred actions including bindings and views updates are flushed at the
75
+ end.
76
+
77
+ Normally you should not need to invoke this method yourself. However if
78
+ you are implementing raw event handlers when interfacing with other
79
+ libraries or plugins, you should probably wrap all of your code inside this
80
+ call.
81
+
82
+ ```javascript
83
+ import { run } from '@ember/runloop';
84
+
85
+ run(function() {
86
+ // code to be executed within a RunLoop
87
+ });
88
+ ```
89
+ @method run
90
+ @for @ember/runloop
91
+ @static
92
+ @param {Object} [target] target of method to call
93
+ @param {Function|String} method Method to invoke.
94
+ May be a function or a string. If you pass a string
95
+ then it will be looked up on the passed target.
96
+ @param {Object} [args*] Any additional arguments you wish to pass to the method.
97
+ @return {Object} return value from invoking the passed function.
98
+ @public
99
+ */
100
+
101
+ function run(...args) {
102
+ // @ts-expect-error TS doesn't like our spread args
103
+ return _backburner.run(...args);
104
+ }
105
+
106
+ /**
107
+ If no run-loop is present, it creates a new one. If a run loop is
108
+ present it will queue itself to run on the existing run-loops action
109
+ queue.
110
+
111
+ Please note: This is not for normal usage, and should be used sparingly.
112
+
113
+ If invoked when not within a run loop:
114
+
115
+ ```javascript
116
+ import { join } from '@ember/runloop';
117
+
118
+ join(function() {
119
+ // creates a new run-loop
120
+ });
121
+ ```
122
+
123
+ Alternatively, if called within an existing run loop:
124
+
125
+ ```javascript
126
+ import { run, join } from '@ember/runloop';
127
+
128
+ run(function() {
129
+ // creates a new run-loop
130
+
131
+ join(function() {
132
+ // joins with the existing run-loop, and queues for invocation on
133
+ // the existing run-loops action queue.
134
+ });
135
+ });
136
+ ```
137
+
138
+ @method join
139
+ @static
140
+ @for @ember/runloop
141
+ @param {Object} [target] target of method to call
142
+ @param {Function|String} method Method to invoke.
143
+ May be a function or a string. If you pass a string
144
+ then it will be looked up on the passed target.
145
+ @param {Object} [args*] Any additional arguments you wish to pass to the method.
146
+ @return {Object} Return value from invoking the passed function. Please note,
147
+ when called within an existing loop, no return value is possible.
148
+ @public
149
+ */
150
+
151
+ function join(methodOrTarget, methodOrArg, ...additionalArgs) {
152
+ return _backburner.join(methodOrTarget, methodOrArg, ...additionalArgs);
153
+ }
154
+
155
+ /**
156
+ Allows you to specify which context to call the specified function in while
157
+ adding the execution of that function to the Ember run loop. This ability
158
+ makes this method a great way to asynchronously integrate third-party libraries
159
+ into your Ember application.
160
+
161
+ `bind` takes two main arguments, the desired context and the function to
162
+ invoke in that context. Any additional arguments will be supplied as arguments
163
+ to the function that is passed in.
164
+
165
+ Let's use the creation of a TinyMCE component as an example. Currently,
166
+ TinyMCE provides a setup configuration option we can use to do some processing
167
+ after the TinyMCE instance is initialized but before it is actually rendered.
168
+ We can use that setup option to do some additional setup for our component.
169
+ The component itself could look something like the following:
170
+
171
+ ```app/components/rich-text-editor.js
172
+ import Component from '@ember/component';
173
+ import { on } from '@ember/object/evented';
174
+ import { bind } from '@ember/runloop';
175
+
176
+ export default Component.extend({
177
+ initializeTinyMCE: on('didInsertElement', function() {
178
+ tinymce.init({
179
+ selector: '#' + this.$().prop('id'),
180
+ setup: bind(this, this.setupEditor)
181
+ });
182
+ }),
183
+
184
+ didInsertElement() {
185
+ tinymce.init({
186
+ selector: '#' + this.$().prop('id'),
187
+ setup: bind(this, this.setupEditor)
188
+ });
189
+ }
190
+
191
+ setupEditor(editor) {
192
+ this.set('editor', editor);
193
+
194
+ editor.on('change', function() {
195
+ console.log('content changed!');
196
+ });
197
+ }
198
+ });
199
+ ```
200
+
201
+ In this example, we use `bind` to bind the setupEditor method to the
202
+ context of the RichTextEditor component and to have the invocation of that
203
+ method be safely handled and executed by the Ember run loop.
204
+
205
+ @method bind
206
+ @static
207
+ @for @ember/runloop
208
+ @param {Object} [target] target of method to call
209
+ @param {Function|String} method Method to invoke.
210
+ May be a function or a string. If you pass a string
211
+ then it will be looked up on the passed target.
212
+ @param {Object} [args*] Any additional arguments you wish to pass to the method.
213
+ @return {Function} returns a new function that will always have a particular context
214
+ @since 1.4.0
215
+ @public
216
+ */
217
+
218
+ // This final fallback is the equivalent of the (quite unsafe!) type for `bind`
219
+ // from TS' defs for `Function.prototype.bind`. In general, it means we have a
220
+ // loss of safety if we do not
221
+
222
+ function bind(...curried) {
223
+ (isDevelopingApp() && !(function (methodOrTarget, methodOrArg) {
224
+ // Applies the same logic as backburner parseArgs for detecting if a method
225
+ // is actually being passed.
226
+ let length = arguments.length;
227
+ if (length === 0) {
228
+ return false;
229
+ } else if (length === 1) {
230
+ return typeof methodOrTarget === 'function';
231
+ } else {
232
+ return typeof methodOrArg === 'function' ||
233
+ // second argument is a function
234
+ methodOrTarget !== null && typeof methodOrArg === 'string' && methodOrArg in methodOrTarget ||
235
+ // second argument is the name of a method in first argument
236
+ typeof methodOrTarget === 'function' //first argument is a function
237
+ ;
238
+ }
239
+ // @ts-expect-error TS doesn't like our spread args
240
+ }(...curried)) && assert('could not find a suitable method to bind', function (methodOrTarget, methodOrArg) {
241
+ let length = arguments.length;
242
+ if (length === 0) {
243
+ return false;
244
+ } else if (length === 1) {
245
+ return typeof methodOrTarget === 'function';
246
+ } else {
247
+ return typeof methodOrArg === 'function' || methodOrTarget !== null && typeof methodOrArg === 'string' && methodOrArg in methodOrTarget || typeof methodOrTarget === 'function';
248
+ }
249
+ }(...curried))); // @ts-expect-error TS doesn't like our spread args
250
+ return (...args) => join(...curried.concat(args));
251
+ }
252
+
253
+ /**
254
+ Begins a new RunLoop. Any deferred actions invoked after the begin will
255
+ be buffered until you invoke a matching call to `end()`. This is
256
+ a lower-level way to use a RunLoop instead of using `run()`.
257
+
258
+ ```javascript
259
+ import { begin, end } from '@ember/runloop';
260
+
261
+ begin();
262
+ // code to be executed within a RunLoop
263
+ end();
264
+ ```
265
+
266
+ @method begin
267
+ @static
268
+ @for @ember/runloop
269
+ @return {void}
270
+ @public
271
+ */
272
+ function begin() {
273
+ _backburner.begin();
274
+ }
275
+
276
+ /**
277
+ Ends a RunLoop. This must be called sometime after you call
278
+ `begin()` to flush any deferred actions. This is a lower-level way
279
+ to use a RunLoop instead of using `run()`.
280
+
281
+ ```javascript
282
+ import { begin, end } from '@ember/runloop';
283
+
284
+ begin();
285
+ // code to be executed within a RunLoop
286
+ end();
287
+ ```
288
+
289
+ @method end
290
+ @static
291
+ @for @ember/runloop
292
+ @return {void}
293
+ @public
294
+ */
295
+ function end() {
296
+ _backburner.end();
297
+ }
298
+
299
+ /**
300
+ Adds the passed target/method and any optional arguments to the named
301
+ queue to be executed at the end of the RunLoop. If you have not already
302
+ started a RunLoop when calling this method one will be started for you
303
+ automatically.
304
+
305
+ At the end of a RunLoop, any methods scheduled in this way will be invoked.
306
+ Methods will be invoked in an order matching the named queues defined in
307
+ the `queues` property.
308
+
309
+ ```javascript
310
+ import { schedule } from '@ember/runloop';
311
+
312
+ schedule('afterRender', this, function() {
313
+ // this will be executed in the 'afterRender' queue
314
+ console.log('scheduled on afterRender queue');
315
+ });
316
+
317
+ schedule('actions', this, function() {
318
+ // this will be executed in the 'actions' queue
319
+ console.log('scheduled on actions queue');
320
+ });
321
+
322
+ // Note the functions will be run in order based on the run queues order.
323
+ // Output would be:
324
+ // scheduled on actions queue
325
+ // scheduled on afterRender queue
326
+ ```
327
+
328
+ @method schedule
329
+ @static
330
+ @for @ember/runloop
331
+ @param {String} queue The name of the queue to schedule against. Default queues is 'actions'
332
+ @param {Object} [target] target object to use as the context when invoking a method.
333
+ @param {String|Function} method The method to invoke. If you pass a string it
334
+ will be resolved on the target object at the time the scheduled item is
335
+ invoked allowing you to change the target function.
336
+ @param {Object} [arguments*] Optional arguments to be passed to the queued method.
337
+ @return {*} Timer information for use in canceling, see `cancel`.
338
+ @public
339
+ */
340
+
341
+ function schedule(...args) {
342
+ // @ts-expect-error TS doesn't like the rest args here
343
+ return _backburner.schedule(...args);
344
+ }
345
+
346
+ // Used by global test teardown
347
+ function _hasScheduledTimers() {
348
+ return _backburner.hasTimers();
349
+ }
350
+
351
+ // Used by global test teardown
352
+ function _cancelTimers() {
353
+ _backburner.cancelTimers();
354
+ }
355
+
356
+ /**
357
+ Invokes the passed target/method and optional arguments after a specified
358
+ period of time. The last parameter of this method must always be a number
359
+ of milliseconds.
360
+
361
+ You should use this method whenever you need to run some action after a
362
+ period of time instead of using `setTimeout()`. This method will ensure that
363
+ items that expire during the same script execution cycle all execute
364
+ together, which is often more efficient than using a real setTimeout.
365
+
366
+ ```javascript
367
+ import { later } from '@ember/runloop';
368
+
369
+ later(myContext, function() {
370
+ // code here will execute within a RunLoop in about 500ms with this == myContext
371
+ }, 500);
372
+ ```
373
+
374
+ @method later
375
+ @static
376
+ @for @ember/runloop
377
+ @param {Object} [target] target of method to invoke
378
+ @param {Function|String} method The method to invoke.
379
+ If you pass a string it will be resolved on the
380
+ target at the time the method is invoked.
381
+ @param {Object} [args*] Optional arguments to pass to the timeout.
382
+ @param {Number} wait Number of milliseconds to wait.
383
+ @return {*} Timer information for use in canceling, see `cancel`.
384
+ @public
385
+ */
386
+
387
+ function later(...args) {
388
+ return _backburner.later(...args);
389
+ }
390
+
391
+ /**
392
+ Schedule a function to run one time during the current RunLoop. This is equivalent
393
+ to calling `scheduleOnce` with the "actions" queue.
394
+
395
+ @method once
396
+ @static
397
+ @for @ember/runloop
398
+ @param {Object} [target] The target of the method to invoke.
399
+ @param {Function|String} method The method to invoke.
400
+ If you pass a string it will be resolved on the
401
+ target at the time the method is invoked.
402
+ @param {Object} [args*] Optional arguments to pass to the timeout.
403
+ @return {Object} Timer information for use in canceling, see `cancel`.
404
+ @public
405
+ */
406
+
407
+ function once(...args) {
408
+ // @ts-expect-error TS doesn't like the rest args here
409
+ return _backburner.scheduleOnce('actions', ...args);
410
+ }
411
+
412
+ /**
413
+ Schedules a function to run one time in a given queue of the current RunLoop.
414
+ Calling this method with the same queue/target/method combination will have
415
+ no effect (past the initial call).
416
+
417
+ Note that although you can pass optional arguments these will not be
418
+ considered when looking for duplicates. New arguments will replace previous
419
+ calls.
420
+
421
+ ```javascript
422
+ import { run, scheduleOnce } from '@ember/runloop';
423
+
424
+ function sayHi() {
425
+ console.log('hi');
426
+ }
427
+
428
+ run(function() {
429
+ scheduleOnce('afterRender', myContext, sayHi);
430
+ scheduleOnce('afterRender', myContext, sayHi);
431
+ // sayHi will only be executed once, in the afterRender queue of the RunLoop
432
+ });
433
+ ```
434
+
435
+ Also note that for `scheduleOnce` to prevent additional calls, you need to
436
+ pass the same function instance. The following case works as expected:
437
+
438
+ ```javascript
439
+ function log() {
440
+ console.log('Logging only once');
441
+ }
442
+
443
+ function scheduleIt() {
444
+ scheduleOnce('actions', myContext, log);
445
+ }
446
+
447
+ scheduleIt();
448
+ scheduleIt();
449
+ ```
450
+
451
+ But this other case will schedule the function multiple times:
452
+
453
+ ```javascript
454
+ import { scheduleOnce } from '@ember/runloop';
455
+
456
+ function scheduleIt() {
457
+ scheduleOnce('actions', myContext, function() {
458
+ console.log('Closure');
459
+ });
460
+ }
461
+
462
+ scheduleIt();
463
+ scheduleIt();
464
+
465
+ // "Closure" will print twice, even though we're using `scheduleOnce`,
466
+ // because the function we pass to it won't match the
467
+ // previously scheduled operation.
468
+ ```
469
+
470
+ Available queues, and their order, can be found at `queues`
471
+
472
+ @method scheduleOnce
473
+ @static
474
+ @for @ember/runloop
475
+ @param {String} [queue] The name of the queue to schedule against. Default queues is 'actions'.
476
+ @param {Object} [target] The target of the method to invoke.
477
+ @param {Function|String} method The method to invoke.
478
+ If you pass a string it will be resolved on the
479
+ target at the time the method is invoked.
480
+ @param {Object} [args*] Optional arguments to pass to the timeout.
481
+ @return {Object} Timer information for use in canceling, see `cancel`.
482
+ @public
483
+ */
484
+
485
+ function scheduleOnce(...args) {
486
+ // @ts-expect-error TS doesn't like the rest args here
487
+ return _backburner.scheduleOnce(...args);
488
+ }
489
+
490
+ /**
491
+ Schedules an item to run from within a separate run loop, after
492
+ control has been returned to the system. This is equivalent to calling
493
+ `later` with a wait time of 1ms.
494
+
495
+ ```javascript
496
+ import { next } from '@ember/runloop';
497
+
498
+ next(myContext, function() {
499
+ // code to be executed in the next run loop,
500
+ // which will be scheduled after the current one
501
+ });
502
+ ```
503
+
504
+ Multiple operations scheduled with `next` will coalesce
505
+ into the same later run loop, along with any other operations
506
+ scheduled by `later` that expire right around the same
507
+ time that `next` operations will fire.
508
+
509
+ Note that there are often alternatives to using `next`.
510
+ For instance, if you'd like to schedule an operation to happen
511
+ after all DOM element operations have completed within the current
512
+ run loop, you can make use of the `afterRender` run loop queue (added
513
+ by the `ember-views` package, along with the preceding `render` queue
514
+ where all the DOM element operations happen).
515
+
516
+ Example:
517
+
518
+ ```app/components/my-component.js
519
+ import Component from '@ember/component';
520
+ import { scheduleOnce } from '@ember/runloop';
521
+
522
+ export Component.extend({
523
+ didInsertElement() {
524
+ this._super(...arguments);
525
+ scheduleOnce('afterRender', this, 'processChildElements');
526
+ },
527
+
528
+ processChildElements() {
529
+ // ... do something with component's child component
530
+ // elements after they've finished rendering, which
531
+ // can't be done within this component's
532
+ // `didInsertElement` hook because that gets run
533
+ // before the child elements have been added to the DOM.
534
+ }
535
+ });
536
+ ```
537
+
538
+ One benefit of the above approach compared to using `next` is
539
+ that you will be able to perform DOM/CSS operations before unprocessed
540
+ elements are rendered to the screen, which may prevent flickering or
541
+ other artifacts caused by delaying processing until after rendering.
542
+
543
+ The other major benefit to the above approach is that `next`
544
+ introduces an element of non-determinism, which can make things much
545
+ harder to test, due to its reliance on `setTimeout`; it's much harder
546
+ to guarantee the order of scheduled operations when they are scheduled
547
+ outside of the current run loop, i.e. with `next`.
548
+
549
+ @method next
550
+ @static
551
+ @for @ember/runloop
552
+ @param {Object} [target] target of method to invoke
553
+ @param {Function|String} method The method to invoke.
554
+ If you pass a string it will be resolved on the
555
+ target at the time the method is invoked.
556
+ @param {Object} [args*] Optional arguments to pass to the timeout.
557
+ @return {Object} Timer information for use in canceling, see `cancel`.
558
+ @public
559
+ */
560
+
561
+ function next(...args) {
562
+ return _backburner.later(...args, 1);
563
+ }
564
+
565
+ /**
566
+ Cancels a scheduled item. Must be a value returned by `later()`,
567
+ `once()`, `scheduleOnce()`, `next()`, `debounce()`, or
568
+ `throttle()`.
569
+
570
+ ```javascript
571
+ import {
572
+ next,
573
+ cancel,
574
+ later,
575
+ scheduleOnce,
576
+ once,
577
+ throttle,
578
+ debounce
579
+ } from '@ember/runloop';
580
+
581
+ let runNext = next(myContext, function() {
582
+ // will not be executed
583
+ });
584
+
585
+ cancel(runNext);
586
+
587
+ let runLater = later(myContext, function() {
588
+ // will not be executed
589
+ }, 500);
590
+
591
+ cancel(runLater);
592
+
593
+ let runScheduleOnce = scheduleOnce('afterRender', myContext, function() {
594
+ // will not be executed
595
+ });
596
+
597
+ cancel(runScheduleOnce);
598
+
599
+ let runOnce = once(myContext, function() {
600
+ // will not be executed
601
+ });
602
+
603
+ cancel(runOnce);
604
+
605
+ let throttle = throttle(myContext, function() {
606
+ // will not be executed
607
+ }, 1, false);
608
+
609
+ cancel(throttle);
610
+
611
+ let debounce = debounce(myContext, function() {
612
+ // will not be executed
613
+ }, 1);
614
+
615
+ cancel(debounce);
616
+
617
+ let debounceImmediate = debounce(myContext, function() {
618
+ // will be executed since we passed in true (immediate)
619
+ }, 100, true);
620
+
621
+ // the 100ms delay until this method can be called again will be canceled
622
+ cancel(debounceImmediate);
623
+ ```
624
+
625
+ @method cancel
626
+ @static
627
+ @for @ember/runloop
628
+ @param {Object} [timer] Timer object to cancel
629
+ @return {Boolean} true if canceled or false/undefined if it wasn't found
630
+ @public
631
+ */
632
+ function cancel(timer) {
633
+ return _backburner.cancel(timer);
634
+ }
635
+
636
+ /**
637
+ Delay calling the target method until the debounce period has elapsed
638
+ with no additional debounce calls. If `debounce` is called again before
639
+ the specified time has elapsed, the timer is reset and the entire period
640
+ must pass again before the target method is called.
641
+
642
+ This method should be used when an event may be called multiple times
643
+ but the action should only be called once when the event is done firing.
644
+ A common example is for scroll events where you only want updates to
645
+ happen once scrolling has ceased.
646
+
647
+ ```javascript
648
+ import { debounce } from '@ember/runloop';
649
+
650
+ function whoRan() {
651
+ console.log(this.name + ' ran.');
652
+ }
653
+
654
+ let myContext = { name: 'debounce' };
655
+
656
+ debounce(myContext, whoRan, 150);
657
+
658
+ // less than 150ms passes
659
+ debounce(myContext, whoRan, 150);
660
+
661
+ // 150ms passes
662
+ // whoRan is invoked with context myContext
663
+ // console logs 'debounce ran.' one time.
664
+ ```
665
+
666
+ Immediate allows you to run the function immediately, but debounce
667
+ other calls for this function until the wait time has elapsed. If
668
+ `debounce` is called again before the specified time has elapsed,
669
+ the timer is reset and the entire period must pass again before
670
+ the method can be called again.
671
+
672
+ ```javascript
673
+ import { debounce } from '@ember/runloop';
674
+
675
+ function whoRan() {
676
+ console.log(this.name + ' ran.');
677
+ }
678
+
679
+ let myContext = { name: 'debounce' };
680
+
681
+ debounce(myContext, whoRan, 150, true);
682
+
683
+ // console logs 'debounce ran.' one time immediately.
684
+ // 100ms passes
685
+ debounce(myContext, whoRan, 150, true);
686
+
687
+ // 150ms passes and nothing else is logged to the console and
688
+ // the debouncee is no longer being watched
689
+ debounce(myContext, whoRan, 150, true);
690
+
691
+ // console logs 'debounce ran.' one time immediately.
692
+ // 150ms passes and nothing else is logged to the console and
693
+ // the debouncee is no longer being watched
694
+ ```
695
+
696
+ @method debounce
697
+ @static
698
+ @for @ember/runloop
699
+ @param {Object} [target] target of method to invoke
700
+ @param {Function|String} method The method to invoke.
701
+ May be a function or a string. If you pass a string
702
+ then it will be looked up on the passed target.
703
+ @param {Object} [args*] Optional arguments to pass to the timeout.
704
+ @param {Number} wait Number of milliseconds to wait.
705
+ @param {Boolean} immediate Trigger the function on the leading instead
706
+ of the trailing edge of the wait interval. Defaults to false.
707
+ @return {Array} Timer information for use in canceling, see `cancel`.
708
+ @public
709
+ */
710
+
711
+ function debounce(...args) {
712
+ // @ts-expect-error TS doesn't like the rest args here
713
+ return _backburner.debounce(...args);
714
+ }
715
+
716
+ /**
717
+ Ensure that the target method is never called more frequently than
718
+ the specified spacing period. The target method is called immediately.
719
+
720
+ ```javascript
721
+ import { throttle } from '@ember/runloop';
722
+
723
+ function whoRan() {
724
+ console.log(this.name + ' ran.');
725
+ }
726
+
727
+ let myContext = { name: 'throttle' };
728
+
729
+ throttle(myContext, whoRan, 150);
730
+ // whoRan is invoked with context myContext
731
+ // console logs 'throttle ran.'
732
+
733
+ // 50ms passes
734
+ throttle(myContext, whoRan, 150);
735
+
736
+ // 50ms passes
737
+ throttle(myContext, whoRan, 150);
738
+
739
+ // 150ms passes
740
+ throttle(myContext, whoRan, 150);
741
+ // whoRan is invoked with context myContext
742
+ // console logs 'throttle ran.'
743
+ ```
744
+
745
+ @method throttle
746
+ @static
747
+ @for @ember/runloop
748
+ @param {Object} [target] target of method to invoke
749
+ @param {Function|String} method The method to invoke.
750
+ May be a function or a string. If you pass a string
751
+ then it will be looked up on the passed target.
752
+ @param {Object} [args*] Optional arguments to pass to the timeout.
753
+ @param {Number} spacing Number of milliseconds to space out requests.
754
+ @param {Boolean} immediate Trigger the function on the leading instead
755
+ of the trailing edge of the wait interval. Defaults to true.
756
+ @return {Array} Timer information for use in canceling, see `cancel`.
757
+ @public
758
+ */
759
+
760
+ function throttle(...args) {
761
+ // @ts-expect-error TS doesn't like the rest args here
762
+ return _backburner.throttle(...args);
763
+ }
764
+
765
+ export { _backburner, _cancelTimers, _getCurrentRunLoop, _hasScheduledTimers, _queues, _rsvpErrorQueue, begin, bind, cancel, debounce, end, join, later, next, once, run, schedule, scheduleOnce, throttle };