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

fix: Create weakmap before returning weakmap #72

Merged
merged 5 commits into from
Aug 3, 2017

Conversation

knownasilya
Copy link
Contributor

Previously state: stateFor('some-state') would return undefined if used in a route, before the computed property was called. This change fixes that.

Previously `state: stateFor('som-state')` would return `undefined` if used in a route, before the computed property was called. This change fixes that.
@@ -24,8 +24,14 @@ let weakMaps = {};
* stateFor('state-name').get(this.get('property-name'));
*/
export default function stateFor(stateName, propertyName) {
if (!weakMaps[stateName]) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could restructure it so that in the more common scenario (when the weakmap exists) we only have one object property lookup:

let state = weakMaps[stateName];
if (state === undefined) {
  state = weakMaps[stateName] = new WeakMap();
}

@thoov
Copy link
Collaborator

thoov commented Aug 3, 2017

@knownasilya Looks good to me. I agree w/ @rwjblue about his comment. Also could you add a test case for this?

@knownasilya
Copy link
Contributor Author

All set @thoov @rwjblue

@thoov
Copy link
Collaborator

thoov commented Aug 3, 2017

Thanks @knownasilya!

@thoov thoov merged commit 708041a into stefanpenner:master Aug 3, 2017
@knownasilya knownasilya deleted the patch-1 branch August 3, 2017 22:32
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.

3 participants