Skip to content

Commit c7991fc

Browse files
authored
Merge pull request #13755 from rwjblue/remove-targetobject-computed
Remove usage of `targetObject` computed property.
2 parents b68dcc4 + 7d1a8d5 commit c7991fc

File tree

3 files changed

+42
-44
lines changed

3 files changed

+42
-44
lines changed

packages/ember-glimmer/lib/syntax/curly-component.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,15 @@ class CurlyComponentManager {
7474

7575
props.renderer = parentView.renderer;
7676
props[HAS_BLOCK] = hasBlock;
77+
// parentView.controller represents any parent components
78+
// dynamicScope.controller represents the outlet controller
79+
props._targetObject = parentView.controller || dynamicScope.controller;
7780

7881
let component = klass.create(props);
7982

8083
dynamicScope.view = component;
8184
parentView.appendChild(component);
8285

83-
if (parentView.controller) {
84-
dynamicScope.controller = parentView.controller;
85-
}
86-
87-
component._controller = dynamicScope.controller;
88-
89-
9086
component.trigger('didInitAttrs', { attrs });
9187
component.trigger('didReceiveAttrs', { newAttrs: attrs });
9288
component.trigger('willInsertElement');

packages/ember-runtime/lib/mixins/target_action_support.js

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,6 @@ export default Mixin.create({
2929
action: null,
3030
actionContext: null,
3131

32-
targetObject: computed('target', function() {
33-
if (this._targetObject) {
34-
return this._targetObject;
35-
}
36-
37-
let target = get(this, 'target');
38-
39-
if (typeof target === 'string') {
40-
let value = get(this, target);
41-
if (value === undefined) {
42-
value = get(context.lookup, target);
43-
}
44-
45-
return value;
46-
} else {
47-
return target;
48-
}
49-
}),
50-
5132
actionContextObject: computed('actionContext', function() {
5233
let actionContext = get(this, 'actionContext');
5334

@@ -115,7 +96,12 @@ export default Mixin.create({
11596
*/
11697
triggerAction(opts = {}) {
11798
let action = opts.action || get(this, 'action');
118-
let target = opts.target || get(this, 'targetObject');
99+
let target = opts.target;
100+
101+
if (!target) {
102+
target = getTarget(this);
103+
}
104+
119105
let actionContext = opts.actionContext;
120106

121107
function args(options, actionName) {
@@ -149,3 +135,36 @@ export default Mixin.create({
149135
}
150136
}
151137
});
138+
139+
function getTarget(instance) {
140+
// TODO: Deprecate specifying `targetObject`
141+
let target = get(instance, 'targetObject');
142+
143+
// if a `targetObject` CP was provided, use it
144+
if (target) { return target; }
145+
146+
// if _targetObject use it
147+
if (instance._targetObject) { return instance._targetObject; }
148+
149+
target = get(instance, 'target');
150+
if (target) {
151+
if (typeof target === 'string') {
152+
let value = get(instance, target);
153+
if (value === undefined) {
154+
value = get(context.lookup, target);
155+
}
156+
157+
return value;
158+
} else {
159+
return target;
160+
}
161+
}
162+
163+
if (instance._controller) { return instance._controller; }
164+
165+
// fallback to `parentView.controller`
166+
let parentViewController = get(instance, 'parentView.controller');
167+
if (parentViewController) { return parentViewController; }
168+
169+
return null;
170+
}

packages/ember-views/lib/mixins/action_support.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Mixin } from 'ember-metal/mixin';
2-
import { computed } from 'ember-metal/computed';
32
import { get } from 'ember-metal/property_get';
43
import isNone from 'ember-metal/is_none';
54
import { assert } from 'ember-metal/debug';
@@ -124,22 +123,6 @@ export default Mixin.create({
124123
}
125124
},
126125

127-
/**
128-
If the component is currently inserted into the DOM of a parent view, this
129-
property will point to the controller of the parent view.
130-
131-
@property targetObject
132-
@type Ember.Controller
133-
@default null
134-
@private
135-
*/
136-
targetObject: computed('controller', function(key) {
137-
if (this._targetObject) { return this._targetObject; }
138-
if (this._controller) { return this._controller; }
139-
let parentView = get(this, 'parentView');
140-
return parentView ? get(parentView, 'controller') : null;
141-
}),
142-
143126
send(actionName, ...args) {
144127
let target;
145128
let action = this.actions && this.actions[actionName];

0 commit comments

Comments
 (0)