Skip to content

Commit

Permalink
[BUGFIX beta] Adds a deprecation message when targetObject is set or …
Browse files Browse the repository at this point in the history
…used
  • Loading branch information
sduquej committed Nov 19, 2016
1 parent 56ac120 commit a2930ef
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
29 changes: 26 additions & 3 deletions packages/ember-runtime/lib/mixins/target_action_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
assert,
get,
Mixin,
computed
computed,
deprecate
} from 'ember-metal';

/**
Expand All @@ -24,6 +25,19 @@ doing more complex event handling in Components.
@private
*/
export default Mixin.create({
init() {
this._super(...arguments);
if (this.targetObject) {
deprecate(
'Setting `targetObject` is deprecated. Please use `target` instead.',
false,
{
id: 'ember-runtime.setting-targetObject',
until: '2.12.0'
}
);
}
},
target: null,
action: null,
actionContext: null,
Expand Down Expand Up @@ -136,11 +150,20 @@ 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 (target) {
deprecate(
'Using `targetObject` is deprecated. Please use `target` instead.',
false,
{
id: 'ember-runtime.using-targetObject',
until: '2.12.0'
}
);
return target;
}

// if _targetObject use it
if (instance._targetObject) { return instance._targetObject; }
Expand Down
19 changes: 19 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,25 @@ 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 a 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');
}
})
});
}, /Setting `targetObject` is deprecated. Please use `target` instead./);
expectDeprecation(() => {
ok(true === obj.triggerAction(), 'a valid targetObject and action were specified');
}, /Using `targetObject` is deprecated. Please use `target` instead./);
});

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

Expand Down

0 comments on commit a2930ef

Please sign in to comment.