ember-source 5.11.0-beta.2 → 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 +4 -7
  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,16 +1,17 @@
1
- import '../-internals/owner/index.js';
2
- import '../object/evented.js';
3
- import '../../shared-chunks/index-DTxy4Zgx.js';
1
+ import { getOwner } from '../-internals/owner/index.js';
2
+ import Evented from '../object/evented.js';
3
+ import '../debug/index.js';
4
4
  import '../-internals/meta/lib/meta.js';
5
- import '../../shared-chunks/mandatory-setter-1UQhiJOb.js';
6
- import '@embroider/macros';
5
+ import '../../shared-chunks/mandatory-setter-BiXq-dpN.js';
6
+ import { isDevelopingApp } from '@embroider/macros';
7
7
  import '../../@glimmer/destroyable/index.js';
8
- import '../../@glimmer/validator/index.js';
9
- import '../../shared-chunks/cache-gDE3bkXq.js';
8
+ import { consumeTag, tagFor } from '../../@glimmer/validator/index.js';
10
9
  import '../../@glimmer/manager/index.js';
10
+ import '../../shared-chunks/cache-BESCGvbE.js';
11
11
  import '../../shared-chunks/env-BJLX2Arx.js';
12
- import '../object/lib/computed/computed_macros.js';
13
- import '../../shared-chunks/index-PYiGj1jp.js';
12
+ import { readOnly } from '../object/lib/computed/computed_macros.js';
13
+ import '../object/index.js';
14
+ import '../object/core.js';
14
15
  import '../-internals/runtime/lib/mixins/registry_proxy.js';
15
16
  import '../-internals/runtime/lib/mixins/container_proxy.js';
16
17
  import '../-internals/runtime/lib/mixins/comparable.js';
@@ -19,6 +20,631 @@ import '../-internals/runtime/lib/mixins/-proxy.js';
19
20
  import '../enumerable/mutable.js';
20
21
  import '../-internals/runtime/lib/mixins/target_action_support.js';
21
22
  import '../-internals/runtime/lib/ext/rsvp.js';
22
- import '../service/index.js';
23
- export { J as ROUTER, l as default } from '../../shared-chunks/index-BXPoca1S.js';
24
- import '../../shared-chunks/core_view-Cxne2_wu.js';
23
+ import '../array/index.js';
24
+ import Service from '../service/index.js';
25
+ import EmberRouter from './router.js';
26
+ import { resemblesURL, extractRouteArgs, shallowEqual } from './lib/utils.js';
27
+ import { d as decorateFieldV2, i as initializeDeferredDecorator } from '../../shared-chunks/chunk-3SQBS3Y5-Cj4eryg1.js';
28
+ import { assert } from '../debug/lib/assert.js';
29
+
30
+ /**
31
+ * @module @ember/routing/router-service
32
+ */
33
+ const ROUTER = Symbol('ROUTER');
34
+ function cleanURL(url, rootURL) {
35
+ if (rootURL === '/') {
36
+ return url;
37
+ }
38
+ return url.substring(rootURL.length);
39
+ }
40
+
41
+ /**
42
+ The Router service is the public API that provides access to the router.
43
+
44
+ The immediate benefit of the Router service is that you can inject it into components,
45
+ giving them a friendly way to initiate transitions and ask questions about the current
46
+ global router state.
47
+
48
+ In this example, the Router service is injected into a component to initiate a transition
49
+ to a dedicated route:
50
+
51
+ ```app/components/example.js
52
+ import Component from '@glimmer/component';
53
+ import { action } from '@ember/object';
54
+ import { service } from '@ember/service';
55
+
56
+ export default class ExampleComponent extends Component {
57
+ @service router;
58
+
59
+ @action
60
+ next() {
61
+ this.router.transitionTo('other.route');
62
+ }
63
+ }
64
+ ```
65
+
66
+ Like any service, it can also be injected into helpers, routes, etc.
67
+
68
+ @public
69
+ @extends Service
70
+ @class RouterService
71
+ */
72
+
73
+ class RouterService extends Service.extend(Evented) {
74
+ [ROUTER];
75
+ get _router() {
76
+ let router = this[ROUTER];
77
+ if (router !== undefined) {
78
+ return router;
79
+ }
80
+ let owner = getOwner(this);
81
+ (isDevelopingApp() && !(owner) && assert('RouterService is unexpectedly missing an owner', owner));
82
+ let _router = owner.lookup('router:main');
83
+ (isDevelopingApp() && !(_router instanceof EmberRouter) && assert('ROUTER SERVICE BUG: Expected router to be an instance of EmberRouter', _router instanceof EmberRouter));
84
+ return this[ROUTER] = _router;
85
+ }
86
+ willDestroy() {
87
+ super.willDestroy();
88
+ this[ROUTER] = undefined;
89
+ }
90
+
91
+ /**
92
+ Transition the application into another route. The route may
93
+ be either a single route or route path:
94
+ Calling `transitionTo` from the Router service will cause default query parameter values to be included in the URL.
95
+ This behavior is different from calling `transitionTo` on a route or `transitionToRoute` on a controller.
96
+ See the [Router Service RFC](https://github.com/emberjs/rfcs/blob/master/text/0095-router-service.md#query-parameter-semantics) for more info.
97
+ In the following example we use the Router service to navigate to a route with a
98
+ specific model from a Component in the first action, and in the second we trigger
99
+ a query-params only transition.
100
+ ```app/components/example.js
101
+ import Component from '@glimmer/component';
102
+ import { action } from '@ember/object';
103
+ import { service } from '@ember/service';
104
+ export default class extends Component {
105
+ @service router;
106
+ @action
107
+ goToComments(post) {
108
+ this.router.transitionTo('comments', post);
109
+ }
110
+ @action
111
+ fetchMoreComments(latestComment) {
112
+ this.router.transitionTo({
113
+ queryParams: { commentsAfter: latestComment }
114
+ });
115
+ }
116
+ }
117
+ ```
118
+ @method transitionTo
119
+ @param {String} [routeNameOrUrl] the name of the route or a URL
120
+ @param {...Object} [models] the model(s) or identifier(s) to be used while
121
+ transitioning to the route.
122
+ @param {Object} [options] optional hash with a queryParams property
123
+ containing a mapping of query parameters. May be supplied as the only
124
+ parameter to trigger a query-parameter-only transition.
125
+ @return {Transition} the transition object associated with this
126
+ attempted transition
127
+ @public
128
+ */
129
+ transitionTo(...args) {
130
+ if (resemblesURL(args[0])) {
131
+ // NOTE: this `args[0] as string` cast is safe and TS correctly infers it
132
+ // in 3.6+, so it can be removed when TS is upgraded.
133
+ return this._router._doURLTransition('transitionTo', args[0]);
134
+ }
135
+ let {
136
+ routeName,
137
+ models,
138
+ queryParams
139
+ } = extractRouteArgs(args);
140
+ let transition = this._router._doTransition(routeName, models, queryParams, true);
141
+ return transition;
142
+ }
143
+
144
+ /**
145
+ Similar to `transitionTo`, but instead of adding the destination to the browser's URL history,
146
+ it replaces the entry for the current route.
147
+ When the user clicks the "back" button in the browser, there will be fewer steps.
148
+ This is most commonly used to manage redirects in a way that does not cause confusing additions
149
+ to the user's browsing history.
150
+ Calling `replaceWith` from the Router service will cause default query parameter values to be included in the URL.
151
+ This behavior is different from calling `replaceWith` on a route.
152
+ See the [Router Service RFC](https://github.com/emberjs/rfcs/blob/master/text/0095-router-service.md#query-parameter-semantics) for more info.
153
+ Usage example:
154
+ ```app/routes/application.js
155
+ import Route from '@ember/routing/route';
156
+ import { service } from '@ember/service';
157
+ export default class extends Route {
158
+ @service router;
159
+ beforeModel() {
160
+ if (!authorized()){
161
+ this.router.replaceWith('unauthorized');
162
+ }
163
+ }
164
+ });
165
+ ```
166
+ @method replaceWith
167
+ @param {String} routeNameOrUrl the name of the route or a URL of the desired destination
168
+ @param {...Object} models the model(s) or identifier(s) to be used while
169
+ transitioning to the route i.e. an object of params to pass to the destination route
170
+ @param {Object} [options] optional hash with a queryParams property
171
+ containing a mapping of query parameters
172
+ @return {Transition} the transition object associated with this
173
+ attempted transition
174
+ @public
175
+ */
176
+ replaceWith(...args) {
177
+ return this.transitionTo(...args).method('replace');
178
+ }
179
+
180
+ /**
181
+ Generate a URL based on the supplied route name and optionally a model. The
182
+ URL is returned as a string that can be used for any purpose.
183
+ In this example, the URL for the `author.books` route for a given author
184
+ is copied to the clipboard.
185
+ ```app/templates/application.hbs
186
+ <CopyLink @author={{hash id="tomster" name="Tomster"}} />
187
+ ```
188
+ ```app/components/copy-link.js
189
+ import Component from '@glimmer/component';
190
+ import { service } from '@ember/service';
191
+ import { action } from '@ember/object';
192
+ export default class CopyLinkComponent extends Component {
193
+ @service router;
194
+ @service clipboard;
195
+ @action
196
+ copyBooksURL() {
197
+ if (this.author) {
198
+ const url = this.router.urlFor('author.books', this.args.author);
199
+ this.clipboard.set(url);
200
+ // Clipboard now has /author/tomster/books
201
+ }
202
+ }
203
+ }
204
+ ```
205
+ Just like with `transitionTo` and `replaceWith`, `urlFor` can also handle
206
+ query parameters.
207
+ ```app/templates/application.hbs
208
+ <CopyLink @author={{hash id="tomster" name="Tomster"}} />
209
+ ```
210
+ ```app/components/copy-link.js
211
+ import Component from '@glimmer/component';
212
+ import { service } from '@ember/service';
213
+ import { action } from '@ember/object';
214
+ export default class CopyLinkComponent extends Component {
215
+ @service router;
216
+ @service clipboard;
217
+ @action
218
+ copyOnlyEmberBooksURL() {
219
+ if (this.author) {
220
+ const url = this.router.urlFor('author.books', this.author, {
221
+ queryParams: { filter: 'emberjs' }
222
+ });
223
+ this.clipboard.set(url);
224
+ // Clipboard now has /author/tomster/books?filter=emberjs
225
+ }
226
+ }
227
+ }
228
+ ```
229
+ @method urlFor
230
+ @param {String} routeName the name of the route
231
+ @param {...Object} models the model(s) for the route.
232
+ @param {Object} [options] optional hash with a queryParams property
233
+ containing a mapping of query parameters
234
+ @return {String} the string representing the generated URL
235
+ @public
236
+ */
237
+ urlFor(routeName, ...args) {
238
+ this._router.setupRouter();
239
+ return this._router.generate(routeName, ...args);
240
+ }
241
+
242
+ /**
243
+ Returns `true` if `routeName/models/queryParams` is the active route, where `models` and `queryParams` are optional.
244
+ See [model](api/ember/release/classes/Route/methods/model?anchor=model) and
245
+ [queryParams](/api/ember/3.7/classes/Route/properties/queryParams?anchor=queryParams) for more information about these arguments.
246
+ In the following example, `isActive` will return `true` if the current route is `/posts`.
247
+ ```app/components/posts.js
248
+ import Component from '@glimmer/component';
249
+ import { service } from '@ember/service';
250
+ export default class extends Component {
251
+ @service router;
252
+ displayComments() {
253
+ return this.router.isActive('posts');
254
+ }
255
+ });
256
+ ```
257
+ The next example includes a dynamic segment, and will return `true` if the current route is `/posts/1`,
258
+ assuming the post has an id of 1:
259
+ ```app/components/posts.js
260
+ import Component from '@glimmer/component';
261
+ import { service } from '@ember/service';
262
+ export default class extends Component {
263
+ @service router;
264
+ displayComments(post) {
265
+ return this.router.isActive('posts', post.id);
266
+ }
267
+ });
268
+ ```
269
+ Where `post.id` is the id of a specific post, which is represented in the route as /posts/[post.id].
270
+ If `post.id` is equal to 1, then isActive will return true if the current route is /posts/1, and false if the route is anything else.
271
+ @method isActive
272
+ @param {String} routeName the name of the route
273
+ @param {...Object} models the model(s) or identifier(s) to be used when determining the active route.
274
+ @param {Object} [options] optional hash with a queryParams property
275
+ containing a mapping of query parameters
276
+ @return {boolean} true if the provided routeName/models/queryParams are active
277
+ @public
278
+ */
279
+ isActive(...args) {
280
+ let {
281
+ routeName,
282
+ models,
283
+ queryParams
284
+ } = extractRouteArgs(args);
285
+ let routerMicrolib = this._router._routerMicrolib;
286
+
287
+ // When using isActive() in a getter, we want to entagle with the auto-tracking system
288
+ // for example,
289
+ // in
290
+ // get isBarActive() {
291
+ // return isActive('foo.bar');
292
+ // }
293
+ //
294
+ // you'd expect isBarActive to be dirtied when the route changes.
295
+ //
296
+ // https://github.com/emberjs/ember.js/issues/19004
297
+ consumeTag(tagFor(this._router, 'currentURL'));
298
+
299
+ // UNSAFE: casting `routeName as string` here encodes the existing
300
+ // assumption but may be wrong: `extractRouteArgs` correctly returns it as
301
+ // `string | undefined`. There may be bugs if `isActiveIntent` does
302
+ // not correctly account for `undefined` values for `routeName`. Spoilers:
303
+ // it *does not* account for this being `undefined`.
304
+ if (!routerMicrolib.isActiveIntent(routeName, models)) {
305
+ return false;
306
+ }
307
+ let hasQueryParams = Object.keys(queryParams).length > 0;
308
+ if (hasQueryParams) {
309
+ // UNSAFE: casting `routeName as string` here encodes the existing
310
+ // assumption but may be wrong: `extractRouteArgs` correctly returns it
311
+ // as `string | undefined`. There may be bugs if `_prepareQueryParams`
312
+ // does not correctly account for `undefined` values for `routeName`.
313
+ // Spoilers: under the hood this currently uses router.js APIs which
314
+ // *do not* account for this being `undefined`.
315
+ let targetRouteName = routeName;
316
+ queryParams = Object.assign({}, queryParams);
317
+ this._router._prepareQueryParams(targetRouteName, models, queryParams, true /* fromRouterService */);
318
+ let currentQueryParams = Object.assign({}, routerMicrolib.state.queryParams);
319
+ this._router._prepareQueryParams(targetRouteName, models, currentQueryParams, true /* fromRouterService */);
320
+ return shallowEqual(queryParams, currentQueryParams);
321
+ }
322
+ return true;
323
+ }
324
+
325
+ /**
326
+ Takes a string URL and returns a `RouteInfo` for the leafmost route represented
327
+ by the URL. Returns `null` if the URL is not recognized. This method expects to
328
+ receive the actual URL as seen by the browser including the app's `rootURL`.
329
+ See [RouteInfo](/ember/release/classes/RouteInfo) for more info.
330
+ In the following example `recognize` is used to verify if a path belongs to our
331
+ application before transitioning to it.
332
+ ```
333
+ import Component from '@ember/component';
334
+ import { service } from '@ember/service';
335
+ export default class extends Component {
336
+ @service router;
337
+ path = '/';
338
+ click() {
339
+ if (this.router.recognize(this.path)) {
340
+ this.router.transitionTo(this.path);
341
+ }
342
+ }
343
+ }
344
+ ```
345
+ @method recognize
346
+ @param {String} url
347
+ @return {RouteInfo | null}
348
+ @public
349
+ */
350
+ recognize(url) {
351
+ (isDevelopingApp() && !(url.indexOf(this.rootURL) === 0) && assert(`You must pass a url that begins with the application's rootURL "${this.rootURL}"`, url.indexOf(this.rootURL) === 0));
352
+ this._router.setupRouter();
353
+ let internalURL = cleanURL(url, this.rootURL);
354
+ return this._router._routerMicrolib.recognize(internalURL);
355
+ }
356
+
357
+ /**
358
+ Takes a string URL and returns a promise that resolves to a
359
+ `RouteInfoWithAttributes` for the leafmost route represented by the URL.
360
+ The promise rejects if the URL is not recognized or an unhandled exception
361
+ is encountered. This method expects to receive the actual URL as seen by
362
+ the browser including the app's `rootURL`.
363
+ @method recognizeAndLoad
364
+ @param {String} url
365
+ @return {RouteInfo}
366
+ @public
367
+ */
368
+ recognizeAndLoad(url) {
369
+ (isDevelopingApp() && !(url.indexOf(this.rootURL) === 0) && assert(`You must pass a url that begins with the application's rootURL "${this.rootURL}"`, url.indexOf(this.rootURL) === 0));
370
+ this._router.setupRouter();
371
+ let internalURL = cleanURL(url, this.rootURL);
372
+ return this._router._routerMicrolib.recognizeAndLoad(internalURL);
373
+ }
374
+
375
+ /**
376
+ You can register a listener for events emitted by this service with `.on()`:
377
+ ```app/routes/contact-form.js
378
+ import Route from '@ember/routing';
379
+ import { service } from '@ember/service';
380
+ export default class extends Route {
381
+ @service router;
382
+ activate() {
383
+ this.router.on('routeWillChange', (transition) => {
384
+ if (!transition.to.find(route => route.name === this.routeName)) {
385
+ alert("Please save or cancel your changes.");
386
+ transition.abort();
387
+ }
388
+ })
389
+ }
390
+ }
391
+ ```
392
+ @method on
393
+ @param {String} eventName
394
+ @param {Function} callback
395
+ @public
396
+ */
397
+
398
+ /**
399
+ You can unregister a listener for events emitted by this service with `.off()`:
400
+ ```app/routes/contact-form.js
401
+ import Route from '@ember/routing';
402
+ import { service } from '@ember/service';
403
+ export default class ContactFormRoute extends Route {
404
+ @service router;
405
+ callback = (transition) => {
406
+ if (!transition.to.find(route => route.name === this.routeName)) {
407
+ alert('Please save or cancel your changes.');
408
+ transition.abort();
409
+ }
410
+ };
411
+ activate() {
412
+ this.router.on('routeWillChange', this.callback);
413
+ }
414
+ deactivate() {
415
+ this.router.off('routeWillChange', this.callback);
416
+ }
417
+ }
418
+ ```
419
+ @method off
420
+ @param {String} eventName
421
+ @param {Function} callback
422
+ @public
423
+ */
424
+
425
+ /**
426
+ The `routeWillChange` event is fired at the beginning of any
427
+ attempted transition with a `Transition` object as the sole
428
+ argument. This action can be used for aborting, redirecting,
429
+ or decorating the transition from the currently active routes.
430
+ A good example is preventing navigation when a form is
431
+ half-filled out:
432
+ ```app/routes/contact-form.js
433
+ import Route from '@ember/routing';
434
+ import { service } from '@ember/service';
435
+ export default class extends Route {
436
+ @service router;
437
+ activate() {
438
+ this.router.on('routeWillChange', (transition) => {
439
+ if (!transition.to.find(route => route.name === this.routeName)) {
440
+ alert("Please save or cancel your changes.");
441
+ transition.abort();
442
+ }
443
+ })
444
+ }
445
+ }
446
+ ```
447
+ The `routeWillChange` event fires whenever a new route is chosen as the desired target of a transition. This includes `transitionTo`, `replaceWith`, all redirection for any reason including error handling, and abort. Aborting implies changing the desired target back to where you already were. Once a transition has completed, `routeDidChange` fires.
448
+ @event routeWillChange
449
+ @param {Transition} transition
450
+ @public
451
+ */
452
+
453
+ /**
454
+ The `routeDidChange` event only fires once a transition has settled.
455
+ This includes aborts and error substates. Like the `routeWillChange` event
456
+ it receives a Transition as the sole argument.
457
+ A good example is sending some analytics when the route has transitioned:
458
+ ```app/routes/contact-form.js
459
+ import Route from '@ember/routing';
460
+ import { service } from '@ember/service';
461
+ export default class extends Route {
462
+ @service router;
463
+ activate() {
464
+ this.router.on('routeDidChange', (transition) => {
465
+ ga.send('pageView', {
466
+ current: transition.to.name,
467
+ from: transition.from.name
468
+ });
469
+ })
470
+ }
471
+ }
472
+ ```
473
+ `routeDidChange` will be called after any `Route`'s
474
+ [didTransition](/ember/release/classes/Route/events/didTransition?anchor=didTransition)
475
+ action has been fired.
476
+ The updates of properties
477
+ [currentURL](/ember/release/classes/RouterService/properties/currentURL?anchor=currentURL),
478
+ [currentRouteName](/ember/release/classes/RouterService/properties/currentURL?anchor=currentRouteName)
479
+ and
480
+ [currentRoute](/ember/release/classes/RouterService/properties/currentURL?anchor=currentRoute)
481
+ are completed at the time `routeDidChange` is called.
482
+ @event routeDidChange
483
+ @param {Transition} transition
484
+ @public
485
+ */
486
+
487
+ /**
488
+ * Refreshes all currently active routes, doing a full transition.
489
+ * If a route name is provided and refers to a currently active route,
490
+ * it will refresh only that route and its descendents.
491
+ * Returns a promise that will be resolved once the refresh is complete.
492
+ * All resetController, beforeModel, model, afterModel, redirect, and setupController
493
+ * hooks will be called again. You will get new data from the model hook.
494
+ *
495
+ * @method refresh
496
+ * @param {String} [routeName] the route to refresh (along with all child routes)
497
+ * @return Transition
498
+ * @public
499
+ */
500
+ refresh(pivotRouteName) {
501
+ if (!pivotRouteName) {
502
+ return this._router._routerMicrolib.refresh();
503
+ }
504
+ (isDevelopingApp() && !(this._router.hasRoute(pivotRouteName)) && assert(`The route "${pivotRouteName}" was not found`, this._router.hasRoute(pivotRouteName)));
505
+ (isDevelopingApp() && !(this.isActive(pivotRouteName)) && assert(`The route "${pivotRouteName}" is currently not active`, this.isActive(pivotRouteName)));
506
+ let owner = getOwner(this);
507
+ (isDevelopingApp() && !(owner) && assert('RouterService is unexpectedly missing an owner', owner));
508
+ let pivotRoute = owner.lookup(`route:${pivotRouteName}`);
509
+ return this._router._routerMicrolib.refresh(pivotRoute);
510
+ }
511
+
512
+ /**
513
+ Name of the current route.
514
+ This property represents the logical name of the route,
515
+ which is dot separated.
516
+ For the following router:
517
+ ```app/router.js
518
+ Router.map(function() {
519
+ this.route('about');
520
+ this.route('blog', function () {
521
+ this.route('post', { path: ':post_id' });
522
+ });
523
+ });
524
+ ```
525
+ It will return:
526
+ * `index` when you visit `/`
527
+ * `about` when you visit `/about`
528
+ * `blog.index` when you visit `/blog`
529
+ * `blog.post` when you visit `/blog/some-post-id`
530
+ @property currentRouteName
531
+ @type {String | null}
532
+ @public
533
+ */
534
+ static {
535
+ decorateFieldV2(this.prototype, "currentRouteName", [readOnly('_router.currentRouteName')]);
536
+ }
537
+ #currentRouteName = (initializeDeferredDecorator(this, "currentRouteName"), void 0);
538
+ static {
539
+ decorateFieldV2(this.prototype, "currentURL", [readOnly('_router.currentURL')]);
540
+ }
541
+ #currentURL = (initializeDeferredDecorator(this, "currentURL"), void 0);
542
+ /**
543
+ Current URL for the application.
544
+ This property represents the URL path for this route.
545
+ For the following router:
546
+ ```app/router.js
547
+ Router.map(function() {
548
+ this.route('about');
549
+ this.route('blog', function () {
550
+ this.route('post', { path: ':post_id' });
551
+ });
552
+ });
553
+ ```
554
+ It will return:
555
+ * `/` when you visit `/`
556
+ * `/about` when you visit `/about`
557
+ * `/blog` when you visit `/blog`
558
+ * `/blog/some-post-id` when you visit `/blog/some-post-id`
559
+ @property currentURL
560
+ @type String
561
+ @public
562
+ */
563
+ static {
564
+ decorateFieldV2(this.prototype, "location", [readOnly('_router.location')]);
565
+ }
566
+ #location = (initializeDeferredDecorator(this, "location"), void 0);
567
+ /**
568
+ The `location` property returns what implementation of the `location` API
569
+ your application is using, which determines what type of URL is being used.
570
+ See [Location](/ember/release/classes/Location) for more information.
571
+ To force a particular `location` API implementation to be used in your
572
+ application you can set a location type on your `config/environment`.
573
+ For example, to set the `history` type:
574
+ ```config/environment.js
575
+ 'use strict';
576
+ module.exports = function(environment) {
577
+ let ENV = {
578
+ modulePrefix: 'router-service',
579
+ environment,
580
+ rootURL: '/',
581
+ locationType: 'history',
582
+ ...
583
+ }
584
+ }
585
+ ```
586
+ The following location types are available by default:
587
+ `hash`, `history`, `none`.
588
+ See [HashLocation](/ember/release/classes/HashLocation).
589
+ See [HistoryLocation](/ember/release/classes/HistoryLocation).
590
+ See [NoneLocation](/ember/release/classes/NoneLocation).
591
+ @property location
592
+ @default 'hash'
593
+ @see {Location}
594
+ @public
595
+ */
596
+ static {
597
+ decorateFieldV2(this.prototype, "rootURL", [readOnly('_router.rootURL')]);
598
+ }
599
+ #rootURL = (initializeDeferredDecorator(this, "rootURL"), void 0);
600
+ /**
601
+ The `rootURL` property represents the URL of the root of
602
+ the application, '/' by default.
603
+ This prefix is assumed on all routes defined on this app.
604
+ If you change the `rootURL` in your environment configuration
605
+ like so:
606
+ ```config/environment.js
607
+ 'use strict';
608
+ module.exports = function(environment) {
609
+ let ENV = {
610
+ modulePrefix: 'router-service',
611
+ environment,
612
+ rootURL: '/my-root',
613
+
614
+ }
615
+ ]
616
+ ```
617
+ This property will return `/my-root`.
618
+ @property rootURL
619
+ @default '/'
620
+ @public
621
+ */
622
+ static {
623
+ decorateFieldV2(this.prototype, "currentRoute", [readOnly('_router.currentRoute')]);
624
+ }
625
+ #currentRoute = (initializeDeferredDecorator(this, "currentRoute"), void 0);
626
+ /**
627
+ The `currentRoute` property contains metadata about the current leaf route.
628
+ It returns a `RouteInfo` object that has information like the route name,
629
+ params, query params and more.
630
+ See [RouteInfo](/ember/release/classes/RouteInfo) for more info.
631
+ This property is guaranteed to change whenever a route transition
632
+ happens (even when that transition only changes parameters
633
+ and doesn't change the active route).
634
+ Usage example:
635
+ ```app/components/header.js
636
+ import Component from '@glimmer/component';
637
+ import { service } from '@ember/service';
638
+ import { notEmpty } from '@ember/object/computed';
639
+ export default class extends Component {
640
+ @service router;
641
+ @notEmpty('router.currentRoute.child') isChildRoute;
642
+ });
643
+ ```
644
+ @property currentRoute
645
+ @type RouteInfo
646
+ @public
647
+ */
648
+ }
649
+
650
+ export { ROUTER, RouterService as default };