ember-source 4.3.0-alpha.4 → 4.3.0-beta.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 (31) hide show
  1. package/CHANGELOG.md +6 -2
  2. package/build-metadata.json +3 -3
  3. package/dist/dependencies/router_js.js +66 -31
  4. package/dist/ember-template-compiler.js +16 -13
  5. package/dist/ember-template-compiler.map +1 -1
  6. package/dist/ember-testing.js +1 -1
  7. package/dist/ember-testing.map +1 -1
  8. package/dist/ember.debug.js +669 -1204
  9. package/dist/ember.debug.map +1 -1
  10. package/dist/header/license.js +1 -1
  11. package/dist/packages/@ember/-internals/container/index.js +14 -10
  12. package/dist/packages/@ember/-internals/glimmer/index.js +60 -45
  13. package/dist/packages/@ember/-internals/meta/lib/meta.js +8 -9
  14. package/dist/packages/@ember/-internals/metal/index.js +44 -45
  15. package/dist/packages/@ember/-internals/routing/lib/ext/controller.js +10 -8
  16. package/dist/packages/@ember/-internals/routing/lib/services/router.js +153 -191
  17. package/dist/packages/@ember/-internals/routing/lib/system/route-info.js +2 -2
  18. package/dist/packages/@ember/-internals/routing/lib/system/route.js +95 -374
  19. package/dist/packages/@ember/-internals/routing/lib/system/router.js +60 -33
  20. package/dist/packages/@ember/-internals/routing/lib/utils.js +31 -20
  21. package/dist/packages/@ember/-internals/runtime/lib/mixins/action_handler.js +32 -32
  22. package/dist/packages/@ember/-internals/utils/index.js +2 -0
  23. package/dist/packages/@ember/-internals/views/lib/system/utils.js +1 -0
  24. package/dist/packages/@ember/canary-features/index.js +2 -2
  25. package/dist/packages/@ember/controller/index.js +3 -54
  26. package/dist/packages/@ember/instrumentation/index.js +9 -13
  27. package/dist/packages/@ember/routing/router-service.js +1 -0
  28. package/dist/packages/@ember/service/index.js +6 -73
  29. package/dist/packages/ember/version.js +1 -1
  30. package/docs/data.json +412 -344
  31. package/package.json +4 -4
@@ -131,16 +131,16 @@ ControllerMixin.reopen({
131
131
  aController.transitionToRoute({ queryParams: { sort: 'date' } });
132
132
  ```
133
133
  See also [replaceRoute](/ember/release/classes/Ember.ControllerMixin/methods/replaceRoute?anchor=replaceRoute).
134
- @param {String} name the name of the route or a URL
134
+ @for Ember.ControllerMixin
135
+ @method transitionToRoute
136
+ @deprecated Use transitionTo from the Router service instead.
137
+ @param {String} [name] the name of the route or a URL
135
138
  @param {...Object} models the model(s) or identifier(s) to be used
136
139
  while transitioning to the route.
137
140
  @param {Object} [options] optional hash with a queryParams property
138
141
  containing a mapping of query parameters
139
- @for Ember.ControllerMixin
140
- @method transitionToRoute
141
142
  @return {Transition} the transition object associated with this
142
143
  attempted transition
143
- @deprecated Use transitionTo from the Router service instead.
144
144
  @public
145
145
  */
146
146
  transitionToRoute(...args) {
@@ -195,14 +195,16 @@ ControllerMixin.reopen({
195
195
  aController.replaceRoute('/');
196
196
  aController.replaceRoute('/blog/post/1/comment/13');
197
197
  ```
198
- @param {String} name the name of the route or a URL
198
+ @for Ember.ControllerMixin
199
+ @method replaceRoute
200
+ @deprecated Use replaceWith from the Router service instead.
201
+ @param {String} [name] the name of the route or a URL
199
202
  @param {...Object} models the model(s) or identifier(s) to be used
200
203
  while transitioning to the route.
201
- @for Ember.ControllerMixin
202
- @method replaceRoute
204
+ @param {Object} [options] optional hash with a queryParams property
205
+ containing a mapping of query parameters
203
206
  @return {Transition} the transition object associated with this
204
207
  attempted transition
205
- @deprecated Use replaceWith from the Router service instead.
206
208
  @public
207
209
  */
208
210
  replaceRoute(...args) {
@@ -1,3 +1,11 @@
1
+ var __decorate = this && this.__decorate || function (decorators, target, key, desc) {
2
+ var c = arguments.length,
3
+ r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
4
+ d;
5
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+
1
9
  import { getOwner } from '@ember/-internals/owner';
2
10
  import { Evented } from '@ember/-internals/runtime';
3
11
  import { symbol } from '@ember/-internals/utils';
@@ -15,40 +23,106 @@ function cleanURL(url, rootURL) {
15
23
 
16
24
  return url.substr(rootURL.length, url.length);
17
25
  }
18
- /**
19
- The Router service is the public API that provides access to the router.
20
-
21
- The immediate benefit of the Router service is that you can inject it into components,
22
- giving them a friendly way to initiate transitions and ask questions about the current
23
- global router state.
24
-
25
- In this example, the Router service is injected into a component to initiate a transition
26
- to a dedicated route:
27
-
28
- ```app/components/example.js
29
- import Component from '@glimmer/component';
30
- import { action } from '@ember/object';
31
- import { service } from '@ember/service';
32
26
 
33
- export default class ExampleComponent extends Component {
34
- @service router;
27
+ class RouterService extends Service.extend(Evented) {
28
+ constructor() {
29
+ super(...arguments);
30
+ /**
31
+ The `routeWillChange` event is fired at the beginning of any
32
+ attempted transition with a `Transition` object as the sole
33
+ argument. This action can be used for aborting, redirecting,
34
+ or decorating the transition from the currently active routes.
35
+ A good example is preventing navigation when a form is
36
+ half-filled out:
37
+ ```app/routes/contact-form.js
38
+ import Route from '@ember/routing';
39
+ import { service } from '@ember/service';
40
+ export default class extends Route {
41
+ @service router;
42
+ constructor() {
43
+ super(...arguments);
44
+ this.router.on('routeWillChange', (transition) => {
45
+ if (!transition.to.find(route => route.name === this.routeName)) {
46
+ alert("Please save or cancel your changes.");
47
+ transition.abort();
48
+ }
49
+ })
50
+ }
51
+ }
52
+ ```
53
+ 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.
54
+ @event routeWillChange
55
+ @param {Transition} transition
56
+ @public
57
+ */
35
58
 
36
- @action
37
- next() {
38
- this.router.transitionTo('other.route');
39
- }
40
- }
41
- ```
59
+ /**
60
+ The `routeDidChange` event only fires once a transition has settled.
61
+ This includes aborts and error substates. Like the `routeWillChange` event
62
+ it receives a Transition as the sole argument.
63
+ A good example is sending some analytics when the route has transitioned:
64
+ ```app/routes/contact-form.js
65
+ import Route from '@ember/routing';
66
+ import { service } from '@ember/service';
67
+ export default class extends Route {
68
+ @service router;
69
+ constructor() {
70
+ super(...arguments);
71
+ this.router.on('routeDidChange', (transition) => {
72
+ ga.send('pageView', {
73
+ current: transition.to.name,
74
+ from: transition.from.name
75
+ });
76
+ })
77
+ }
78
+ }
79
+ ```
80
+ `routeDidChange` will be called after any `Route`'s
81
+ [didTransition](/ember/release/classes/Route/events/didTransition?anchor=didTransition)
82
+ action has been fired.
83
+ The updates of properties
84
+ [currentURL](/ember/release/classes/RouterService/properties/currentURL?anchor=currentURL),
85
+ [currentRouteName](/ember/release/classes/RouterService/properties/currentURL?anchor=currentRouteName)
86
+ and
87
+ [currentRoute](/ember/release/classes/RouterService/properties/currentURL?anchor=currentRoute)
88
+ are completed at the time `routeDidChange` is called.
89
+ @event routeDidChange
90
+ @param {Transition} transition
91
+ @public
92
+ */
93
+ // Canary features
42
94
 
43
- Like any service, it can also be injected into helpers, routes, etc.
95
+ /**
96
+ * Refreshes all currently active routes, doing a full transition.
97
+ * If a route name is provided and refers to a currently active route,
98
+ * it will refresh only that route and its descendents.
99
+ * Returns a promise that will be resolved once the refresh is complete.
100
+ * All resetController, beforeModel, model, afterModel, redirect, and setupController
101
+ * hooks will be called again. You will get new data from the model hook.
102
+ *
103
+ * @method refresh
104
+ * @param {String} [routeName] the route to refresh (along with all child routes)
105
+ * @return Transition
106
+ * @category EMBER_ROUTING_ROUTER_SERVICE_REFRESH
107
+ * @public
108
+ */
44
109
 
45
- @public
46
- @extends Service
47
- @class RouterService
48
- */
110
+ this.refresh = true
111
+ /* EMBER_ROUTING_ROUTER_SERVICE_REFRESH */
112
+ ? function (pivotRouteName) {
113
+ if (!pivotRouteName) {
114
+ return this._router._routerMicrolib.refresh();
115
+ }
49
116
 
117
+ assert(`The route "${pivotRouteName}" was not found`, this._router.hasRoute(pivotRouteName));
118
+ assert(`The route "${pivotRouteName}" is currently not active`, this.isActive(pivotRouteName));
119
+ let owner = getOwner(this);
120
+ assert('RouterService is unexpectedly missing an owner', owner);
121
+ let pivotRoute = owner.lookup(`route:${pivotRouteName}`);
122
+ return this._router._routerMicrolib.refresh(pivotRoute);
123
+ } : undefined;
124
+ }
50
125
 
51
- export default class RouterService extends Service {
52
126
  get _router() {
53
127
  let router = this[ROUTER];
54
128
 
@@ -63,9 +137,48 @@ export default class RouterService extends Service {
63
137
  }
64
138
 
65
139
  willDestroy() {
66
- super.willDestroy(...arguments);
140
+ super.willDestroy();
67
141
  this[ROUTER] = null;
68
142
  }
143
+ /**
144
+ Transition the application into another route. The route may
145
+ be either a single route or route path:
146
+ Calling `transitionTo` from the Router service will cause default query parameter values to be included in the URL.
147
+ This behavior is different from calling `transitionTo` on a route or `transitionToRoute` on a controller.
148
+ See the [Router Service RFC](https://github.com/emberjs/rfcs/blob/master/text/0095-router-service.md#query-parameter-semantics) for more info.
149
+ In the following example we use the Router service to navigate to a route with a
150
+ specific model from a Component in the first action, and in the second we trigger
151
+ a query-params only transition.
152
+ ```app/components/example.js
153
+ import Component from '@glimmer/component';
154
+ import { action } from '@ember/object';
155
+ import { service } from '@ember/service';
156
+ export default class extends Component {
157
+ @service router;
158
+ @action
159
+ goToComments(post) {
160
+ this.router.transitionTo('comments', post);
161
+ }
162
+ @action
163
+ fetchMoreComments(latestComment) {
164
+ this.router.transitionTo({
165
+ queryParams: { commentsAfter: latestComment }
166
+ });
167
+ }
168
+ }
169
+ ```
170
+ @method transitionTo
171
+ @param {String} [routeNameOrUrl] the name of the route or a URL
172
+ @param {...Object} [models] the model(s) or identifier(s) to be used while
173
+ transitioning to the route.
174
+ @param {Object} [options] optional hash with a queryParams property
175
+ containing a mapping of query parameters. May be supplied as the only
176
+ parameter to trigger a query-parameter-only transition.
177
+ @return {Transition} the transition object associated with this
178
+ attempted transition
179
+ @public
180
+ */
181
+
69
182
 
70
183
  transitionTo(...args) {
71
184
  if (resemblesURL(args[0])) {
@@ -91,7 +204,6 @@ export default class RouterService extends Service {
91
204
  When the user clicks the "back" button in the browser, there will be fewer steps.
92
205
  This is most commonly used to manage redirects in a way that does not cause confusing additions
93
206
  to the user's browsing history.
94
- See [replaceWith](/ember/release/classes/Route/methods/replaceWith?anchor=replaceWith) for more info.
95
207
  Calling `replaceWith` from the Router service will cause default query parameter values to be included in the URL.
96
208
  This behavior is different from calling `replaceWith` on a route.
97
209
  See the [Router Service RFC](https://github.com/emberjs/rfcs/blob/master/text/0095-router-service.md#query-parameter-semantics) for more info.
@@ -118,8 +230,8 @@ export default class RouterService extends Service {
118
230
  */
119
231
 
120
232
 
121
- replaceWith() {
122
- return this.transitionTo(...arguments).method('replace');
233
+ replaceWith(...args) {
234
+ return this.transitionTo(...args).method('replace');
123
235
  }
124
236
  /**
125
237
  Generate a URL based on the supplied route name and optionally a model. The
@@ -172,8 +284,7 @@ export default class RouterService extends Service {
172
284
  ```
173
285
  @method urlFor
174
286
  @param {String} routeName the name of the route
175
- @param {...Object} models the model(s) or identifier(s) to be used while
176
- transitioning to the route.
287
+ @param {...Object} models the model(s) for the route.
177
288
  @param {Object} [options] optional hash with a queryParams property
178
289
  containing a mapping of query parameters
179
290
  @return {String} the string representing the generated URL
@@ -294,6 +405,7 @@ export default class RouterService extends Service {
294
405
  ```
295
406
  @method recognize
296
407
  @param {String} url
408
+ @return {RouteInfo | null}
297
409
  @public
298
410
  */
299
411
 
@@ -314,6 +426,7 @@ export default class RouterService extends Service {
314
426
  the browser including the app's `rootURL`.
315
427
  @method recognizeAndLoad
316
428
  @param {String} url
429
+ @return {RouteInfo}
317
430
  @public
318
431
  */
319
432
 
@@ -329,165 +442,14 @@ export default class RouterService extends Service {
329
442
 
330
443
  }
331
444
 
332
- if (true
333
- /* EMBER_ROUTING_ROUTER_SERVICE_REFRESH */
334
- ) {
335
- RouterService.reopen({
336
- /**
337
- * Refreshes all currently active routes, doing a full transition.
338
- * If a route name is provided and refers to a currently active route,
339
- * it will refresh only that route and its descendents.
340
- * Returns a promise that will be resolved once the refresh is complete.
341
- * All resetController, beforeModel, model, afterModel, redirect, and setupController
342
- * hooks will be called again. You will get new data from the model hook.
343
- *
344
- * @method refresh
345
- * @param {String} [routeName] the route to refresh (along with all child routes)
346
- * @return Transition
347
- * @category EMBER_ROUTING_ROUTER_SERVICE_REFRESH
348
- * @public
349
- */
350
- refresh(pivotRouteName) {
351
- if (!pivotRouteName) {
352
- return this._router._routerMicrolib.refresh();
353
- }
354
-
355
- assert(`The route "${pivotRouteName}" was not found`, this._router.hasRoute(pivotRouteName));
356
- assert(`The route "${pivotRouteName}" is currently not active`, this.isActive(pivotRouteName));
357
- let owner = getOwner(this);
358
- assert('RouterService is unexpectedly missing an owner', owner);
359
- let pivotRoute = owner.lookup(`route:${pivotRouteName}`);
360
- return this._router._routerMicrolib.refresh(pivotRoute);
361
- }
362
-
363
- });
364
- }
445
+ __decorate([readOnly('_router.currentRouteName')], RouterService.prototype, "currentRouteName", void 0);
365
446
 
366
- RouterService.reopen(Evented, {
367
- /**
368
- Name of the current route.
369
- This property represents the logical name of the route,
370
- which is comma separated.
371
- For the following router:
372
- ```app/router.js
373
- Router.map(function() {
374
- this.route('about');
375
- this.route('blog', function () {
376
- this.route('post', { path: ':post_id' });
377
- });
378
- });
379
- ```
380
- It will return:
381
- * `index` when you visit `/`
382
- * `about` when you visit `/about`
383
- * `blog.index` when you visit `/blog`
384
- * `blog.post` when you visit `/blog/some-post-id`
385
- @property currentRouteName
386
- @type String
387
- @public
388
- */
389
- currentRouteName: readOnly('_router.currentRouteName'),
447
+ __decorate([readOnly('_router.currentURL')], RouterService.prototype, "currentURL", void 0);
390
448
 
391
- /**
392
- Current URL for the application.
393
- This property represents the URL path for this route.
394
- For the following router:
395
- ```app/router.js
396
- Router.map(function() {
397
- this.route('about');
398
- this.route('blog', function () {
399
- this.route('post', { path: ':post_id' });
400
- });
401
- });
402
- ```
403
- It will return:
404
- * `/` when you visit `/`
405
- * `/about` when you visit `/about`
406
- * `/blog` when you visit `/blog`
407
- * `/blog/some-post-id` when you visit `/blog/some-post-id`
408
- @property currentURL
409
- @type String
410
- @public
411
- */
412
- currentURL: readOnly('_router.currentURL'),
449
+ __decorate([readOnly('_router.location')], RouterService.prototype, "location", void 0);
413
450
 
414
- /**
415
- The `location` property returns what implementation of the `location` API
416
- your application is using, which determines what type of URL is being used.
417
- See [Location](/ember/release/classes/Location) for more information.
418
- To force a particular `location` API implementation to be used in your
419
- application you can set a location type on your `config/environment`.
420
- For example, to set the `history` type:
421
- ```config/environment.js
422
- 'use strict';
423
- module.exports = function(environment) {
424
- let ENV = {
425
- modulePrefix: 'router-service',
426
- environment,
427
- rootURL: '/',
428
- locationType: 'history',
429
- ...
430
- }
431
- }
432
- ```
433
- The following location types are available by default:
434
- `auto`, `hash`, `history`, `none`.
435
- See [HashLocation](/ember/release/classes/HashLocation).
436
- See [HistoryLocation](/ember/release/classes/HistoryLocation).
437
- See [NoneLocation](/ember/release/classes/NoneLocation).
438
- See [AutoLocation](/ember/release/classes/AutoLocation).
439
- @property location
440
- @default 'hash'
441
- @see {Location}
442
- @public
443
- */
444
- location: readOnly('_router.location'),
451
+ __decorate([readOnly('_router.rootURL')], RouterService.prototype, "rootURL", void 0);
445
452
 
446
- /**
447
- The `rootURL` property represents the URL of the root of
448
- the application, '/' by default.
449
- This prefix is assumed on all routes defined on this app.
450
- If you change the `rootURL` in your environment configuration
451
- like so:
452
- ```config/environment.js
453
- 'use strict';
454
- module.exports = function(environment) {
455
- let ENV = {
456
- modulePrefix: 'router-service',
457
- environment,
458
- rootURL: '/my-root',
459
-
460
- }
461
- ]
462
- ```
463
- This property will return `/my-root`.
464
- @property rootURL
465
- @default '/'
466
- @public
467
- */
468
- rootURL: readOnly('_router.rootURL'),
453
+ __decorate([readOnly('_router.currentRoute')], RouterService.prototype, "currentRoute", void 0);
469
454
 
470
- /**
471
- The `currentRoute` property contains metadata about the current leaf route.
472
- It returns a `RouteInfo` object that has information like the route name,
473
- params, query params and more.
474
- See [RouteInfo](/ember/release/classes/RouteInfo) for more info.
475
- This property is guaranteed to change whenever a route transition
476
- happens (even when that transition only changes parameters
477
- and doesn't change the active route).
478
- Usage example:
479
- ```app/components/header.js
480
- import Component from '@glimmer/component';
481
- import { service } from '@ember/service';
482
- import { notEmpty } from '@ember/object/computed';
483
- export default class extends Component {
484
- @service router;
485
- @notEmpty('router.currentRoute.child') isChildRoute;
486
- });
487
- ```
488
- @property currentRoute
489
- @type RouteInfo
490
- @public
491
- */
492
- currentRoute: readOnly('_router.currentRoute')
493
- });
455
+ export { RouterService as default };
@@ -1,4 +1,4 @@
1
- "use strict";
1
+ export {};
2
2
  /**
3
3
  A `RouteInfoWithAttributes` is an object that contains
4
4
  metadata, including the resolved value from the routes
@@ -55,7 +55,7 @@
55
55
  /**
56
56
  This is the resolved return value from the
57
57
  route's model hook.
58
- @property {Object|Array|String} attributes
58
+ @property {Object|Array|String|undefined} attributes
59
59
  @public
60
60
  */
61
61