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

[BUGFIX beta] Adds a deprecation message when using targetObject #14590

Merged
merged 1 commit into from
Nov 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions packages/ember-runtime/lib/mixins/target_action_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import { context } from 'ember-environment';
import {
get,
Mixin,
computed
computed,
descriptor
} from 'ember-metal';
import { assert } from 'ember-debug';
import { assert, deprecate } from 'ember-debug';
/**
`Ember.TargetActionSupport` is a mixin that can be included in a class
to add a `triggerAction` method with semantics similar to the Handlebars
Expand All @@ -24,6 +25,22 @@ doing more complex event handling in Components.
*/
export default Mixin.create({
target: null,
targetObject: descriptor({
configurable: true,
enumerable: false,
get() {
let message = `${this} Usage of \`targetObject\` is deprecated. Please use \`target\` instead.`;
let options = { id: 'ember-runtime.using-targetObject', until: '3.5.0' };
deprecate(message, false, options);
return this._targetObject;
},
set(value) {
let message = `${this} Usage of \`targetObject\` is deprecated. Please use \`target\` instead.`;
let options = { id: 'ember-runtime.using-targetObject', until: '3.5.0' };
deprecate(message, false, options);
this._targetObject = value;
}
}),
action: null,
actionContext: null,

Expand Down Expand Up @@ -121,16 +138,7 @@ export default Mixin.create({
});

function getTarget(instance) {
// TODO: Deprecate specifying `targetObject`
let target = get(instance, 'targetObject');

// if a `targetObject` CP was provided, use it
if (target) { return target; }

// if _targetObject use it
if (instance._targetObject) { return instance._targetObject; }

target = get(instance, 'target');
let target = get(instance, 'target');
if (target) {
if (typeof target === 'string') {
let value = get(instance, target);
Expand All @@ -144,5 +152,11 @@ function getTarget(instance) {
}
}

// if a `targetObject` CP was provided, use it
if (target) { return target; }

// if _targetObject use it
if (instance._targetObject) { return instance._targetObject; }

return null;
}
20 changes: 20 additions & 0 deletions packages/ember-runtime/tests/mixins/target_action_support_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,26 @@ QUnit.test('it should use an actionContext object specified as a property on the
ok(true === obj.triggerAction(), 'a valid target and action were specified');
});


QUnit.test('it should raise a deprecation warning when targetObject is specified and used', function() {
expect(4);
let obj;
expectDeprecation(() => {
obj = EmberObject.extend(TargetActionSupport).create({
action: 'anEvent',
actionContext: {},
targetObject: EmberObject.create({
anEvent(ctx) {
ok(obj.actionContext === ctx, 'anEvent method was called with the expected context');
}
})
});
}, /Usage of `targetObject` is deprecated. Please use `target` instead./);
ok(true === obj.triggerAction(), 'a valid targetObject and action were specified');
expectDeprecation(() => obj.get('targetObject'),
/Usage of `targetObject` is deprecated. Please use `target` instead./);
});

QUnit.test('it should find an actionContext specified as a property path', function() {
expect(2);

Expand Down