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

Change callback context to deprecate test module properties #136

Merged
merged 1 commit into from
Dec 16, 2015

Conversation

trentmwillis
Copy link
Member

Addresses #133.

One note: in the case where a user-defined context property collides with a property on the test module, nothing special is done since the user-defined value isn't added to the context until after binding the callbacks.

for accessing properties that exist on the module.
*/
_buildDeprecatedContext: function(module, context) {
var deprecatedContext = Object.create(context);
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to avoid the Object.create(context) call when there are no keysForDeprecation, can you tweak this to be behind a guard?

Something like this slight reordering:

var keysForDeprecation = Object.keys(module);

if (keysForDeprecation.length === 0) {
  return this;
}

var deprecatedContext = Object.create(context);
// .... other stuff

Copy link
Member

Choose a reason for hiding this comment

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

Wait, sorry, I misread. This is only being called when needed (because _contextualizeCallback is called only when needed), but we can still cache the deprecated context (instead of building a new one for every function that is in options).

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, will adjust this to cache the deprecatedContext

@rwjblue
Copy link
Member

rwjblue commented Dec 16, 2015

This looks good, only one thing to tweak (caching the deprecatedContext across multiple callbacks)...

this.foo = 'bar';

equal(this.getFoo(), 'bar');
ok(!deprecations.length);
Copy link
Member

Choose a reason for hiding this comment

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

I am unsure why, but this assertion is failing on ember-1.13. I am rerunning in Travis in case it is a fluke.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's possible that 1.13 is throwing a deprecation unrelated to the changes here. Will investigate this before updating again.

@trentmwillis
Copy link
Member Author

@rwjblue updated to cache the deprecated context across callbacks and fixed the failure with 1.13. Turns out Ember.deprecate was getting called, but the test value was true, so it wasn't really throwing a deprecation.

rwjblue added a commit that referenced this pull request Dec 16, 2015
Change callback context to deprecate test module properties
@rwjblue rwjblue merged commit 9576ea7 into emberjs:master Dec 16, 2015
@rwjblue
Copy link
Member

rwjblue commented Dec 16, 2015

Thanks @trentmwillis!

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.

None yet

3 participants