-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[REFACTOR] Lazily reify router’s location #10483
Conversation
@@ -103,8 +105,12 @@ export default EmberObject.extend({ | |||
this.registry.register('-application-instance:main', this, { instantiate: false }); | |||
}, | |||
|
|||
router: computed(function() { | |||
return this.container.lookup('router:main'); | |||
}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
readOnly ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stefanpenner Done
although maybe out of scope, the pattern of overriting an attribute like this is crappy, can we move away from it? |
@stefanpenner What do you mean overwriting an attribute? |
The location property is rewritten from string to instance |
@stefanpenner Yes, this pattern is terrible. Unfortunately it is used in almost every Ember app. We should not introduce new APIs that use this pattern but I think we're shackled with it for the time being. |
when do people access |
Users can override a router’s location by specifying its `location` property as a string. For example, to change the router from the “auto” location to the “none” location, users can do the following: ```js // app/router.js export default Ember.Router.extend({ location: 'none' }); ``` Previously, the reification of the string value into a concrete Location implementation happened at router creation time. This immediate reification made it difficult to make changes to the router configuration, since it had to be done at creation time. In general, classes that require configuration to be set at creation time are unwieldy to use with the container, since the container itself manages creation. For example, in the case of the Application's `visit()` API, the application instance would like to override the router to use the `none` location. When reification was at creation time, the router was created with the wrong location. Before the default could be overridden, the router would try to set up things like listeners on the browser's address bar, which would cause an exception to be thrown in Node environments where there is no notion of a URL. In this commit, reifying and setting up the location are deferred until the last possible moment, when routing starts (either by calling `startRouting()`, which starts the app at the browser's current URL, or by calling `handleURL()`, which starts the app at a provided URL). This allows the application to detect if it is in autoboot mode or not, and override the router's location before routing begins.
[REFACTOR] Lazily reify router’s location
Users can override a router’s location by specifying its
location
property as a string. For example, to change the router from the “auto” location to the “none” location, users can do the following:Previously, the reification of the string value into a concrete Location implementation happened at router creation time.
This immediate reification made it difficult to make changes to the router configuration, since it had to be done at creation time. In general, classes that require configuration to be set at creation time are unwieldy to use with the container, since the container itself manages creation.
For example, in the case of the Application's
visit()
API, the application instance would like to override the router to use thenone
location.When reification was at creation time, the router was created with the wrong location. Before the default could be overridden, the router would try to set up things like listeners on the browser's address bar, which would cause an exception to be thrown in Node environments where there is no notion of a URL.
In this commit, reifying and setting up the location are deferred until the last possible moment, when routing starts (either by calling
startRouting()
, which starts the app at the browser's current URL, or by callinghandleURL()
, which starts the app at a provided URL). This allows the application to detect if it is in autoboot mode or not, and override the router's location before routing begins.