Skip to content

Commit

Permalink
[BUGFIX beta] Adds deprecation for targetObject
Browse files Browse the repository at this point in the history
  • Loading branch information
sduquej committed Nov 5, 2017
1 parent 38e9c89 commit 24a32b1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 12 deletions.
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

0 comments on commit 24a32b1

Please sign in to comment.