Skip to content
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

Get handlers lazily #187

Merged
merged 3 commits into from
Aug 8, 2016
Merged

Get handlers lazily #187

merged 3 commits into from
Aug 8, 2016

Conversation

trentmwillis
Copy link
Contributor

Currently, getHandler is called before constructing a HandlerInfo object. This
results in work being done upfront even if the handler property of the
HandlerInfo is never accessed. This change invokes getHandler only when the
value is actually needed.

This is particularly needed in the case of getHandler fetching lazily-loaded
routes. Previously lazy routes would be fetched even if the router was just
generating a URL; a task which can be done without the whole handler.

Note: This change relies on getters/setters which implies IE9+ support (which is in line with Ember's support policy, but I am unsure about this library itself).

@trentmwillis
Copy link
Contributor Author

Unsure why tests are failing. Everything passes in browser and builds fine. Investigating...

getHandler: function() {},

get handler() {
if (this.hasOwnProperty('_handler')) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the has own check here? Is there a scenario where we have inherited a _handler?

Would be easier/better?

if (this._handler) { return this._handler; }

Also, _handler needs to be initialized to undefined or null in the constructor to avoid shaping issues (which I think would make the hasOwnProperty check fail to work since it would have the property but it would be undefined).

Copy link
Contributor Author

@trentmwillis trentmwillis Aug 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used hasOwnProperty since it might be undefined, which makes checks tricky. Basically we want "this has been set, but the type of value is ambiguous".

Edit: maybe introduce another boolean to track if it's been set? Feels gross, but otherwise I don't see a clean way of maintaining the shape.

@trentmwillis
Copy link
Contributor Author

Tests were failing due to an old version of Phantom (1.9.2), bumping grunt-contrib-qunit fixes the issue.

@trentmwillis
Copy link
Contributor Author

@rwjblue updated this to fix the shaping.


getHandler: function() {},

_handler: DEFAULT_HANDLER,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be in the constructor itself. We want to shape the instance not the prototype...

@rwjblue
Copy link
Collaborator

rwjblue commented Aug 8, 2016

This is good once that last nit-pick is addressed.

trentmwillis and others added 2 commits August 8, 2016 14:20
Currently, getHandler is called before constructing a HandlerInfo object. This
results in work being done upfront even if the `handler` property of the
HandlerInfo is never accessed. This change invokes `getHandler` only when the
value is actually needed.

This is particularly needed in the case of `getHandler` fetching lazily-loaded
routes. Previously lazy routes would be fetched even if the router was just
generating a URL; a task which can be done without the whole handler.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants