Skip to content

Commit 86a1d49

Browse files
Joel Kangchadhietala
authored andcommitted
[Glimmer2] Add support for target actions and migrate tests
1 parent af590e3 commit 86a1d49

File tree

11 files changed

+767
-185
lines changed

11 files changed

+767
-185
lines changed

packages/ember-glimmer/lib/component.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import ViewStateSupport from 'ember-views/mixins/view_state_support';
55
import InstrumentationSupport from 'ember-views/mixins/instrumentation_support';
66
import AriaRoleSupport from 'ember-views/mixins/aria_role_support';
77
import ViewMixin from 'ember-views/mixins/view_support';
8+
import ActionSupport from 'ember-views/mixins/action_support';
9+
import TargetActionSupport from 'ember-runtime/mixins/target_action_support';
810
import EmberView from 'ember-views/views/view';
911
import symbol from 'ember-metal/symbol';
1012
import EmptyObject from 'ember-metal/empty_object';
@@ -36,17 +38,22 @@ const Component = CoreView.extend(
3638
ClassNamesSupport,
3739
InstrumentationSupport,
3840
AriaRoleSupport,
41+
TargetActionSupport,
42+
ActionSupport,
3943
ViewMixin, {
4044
isComponent: true,
4145
layoutName: null,
4246
layout: null,
47+
controller: null,
48+
_controller: null,
4349

4450
init() {
4551
this._super(...arguments);
4652
this._viewRegistry = this._viewRegistry || EmberView.views;
4753
this[DIRTY_TAG] = new DirtyableTag();
4854
this[ROOT_REF] = null;
4955
this[REFS] = new EmptyObject();
56+
this.controller = this;
5057

5158
// If a `defaultLayout` was specified move it to the `layout` prop.
5259
// `layout` is no longer a CP, so this just ensures that the `defaultLayout`

packages/ember-glimmer/lib/renderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class Renderer {
149149
appendTo(view, target) {
150150
let env = this._env;
151151
let self = new RootReference(view);
152-
let dynamicScope = new DynamicScope({ view });
152+
let dynamicScope = new DynamicScope({ view, controller: view.controller });
153153

154154
env.begin();
155155
let result = view.template.asEntryPoint().render(self, env, { appendTo: target, dynamicScope });

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import processArgs from '../utils/process-args';
66
import { getOwner } from 'container/owner';
77
import { privatize as P } from 'container/registry';
88
import get from 'ember-metal/property_get';
9+
import { ComponentDefinition } from 'glimmer-runtime';
10+
import Component from '../component';
911

1012
const DEFAULT_LAYOUT = P`template:components/-default`;
1113

@@ -78,6 +80,13 @@ class CurlyComponentManager {
7880
dynamicScope.view = component;
7981
parentView.appendChild(component);
8082

83+
if (parentView.controller) {
84+
dynamicScope.controller = parentView.controller;
85+
}
86+
87+
component._controller = dynamicScope.controller;
88+
89+
8190
component.trigger('didInitAttrs', { attrs });
8291
component.trigger('didReceiveAttrs', { newAttrs: attrs });
8392
component.trigger('willInsertElement');
@@ -226,9 +235,6 @@ class CurlyComponentManager {
226235

227236
const MANAGER = new CurlyComponentManager();
228237

229-
import { ComponentDefinition } from 'glimmer-runtime';
230-
import Component from '../component';
231-
232238
function tagName(vm) {
233239
let { tagName } = vm.dynamicScope().view;
234240

packages/ember-glimmer/lib/syntax/outlet.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,10 @@ const TOP_LEVEL_MANAGER = new TopLevelOutletComponentManager();
128128

129129
class OutletComponentManager extends AbstractOutletComponentManager {
130130
create(definition, args, dynamicScope) {
131-
let outletState = dynamicScope.outletState = dynamicScope.outletState.get(definition.outletName);
132-
return outletState.value();
131+
let outletStateReference = dynamicScope.outletState = dynamicScope.outletState.get(definition.outletName);
132+
let outletState = outletStateReference.value();
133+
dynamicScope.controller = outletState.render.controller;
134+
return outletState;
133135
}
134136
}
135137

packages/ember-glimmer/lib/utils/process-args.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { assert } from 'ember-metal/debug';
44
import EmptyObject from 'ember-metal/empty_object';
55
import { ARGS } from '../component';
66
import { UPDATE } from './references';
7+
import { MUTABLE_CELL } from 'ember-views/compat/attrs-proxy';
78

89
export default function processArgs(args, positionalParamsDefinition) {
910
if (!positionalParamsDefinition || positionalParamsDefinition.length === 0 || args.positional.length === 0) {
@@ -65,8 +66,6 @@ class SimpleArgs {
6566
}
6667
}
6768

68-
const MUTABLE_CELL = symbol('MUTABLE_CELL');
69-
7069
export function isCell(val) {
7170
return val && val[MUTABLE_CELL];
7271
}

packages/ember-glimmer/tests/integration/application/rendering-test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,29 @@ moduleFor('Application test: rendering', class extends ApplicationTest {
241241
});
242242
}
243243

244+
['@test it should have the right controller in scope for the route template']() {
245+
this.router.map(function() {
246+
this.route('a');
247+
this.route('b');
248+
});
249+
250+
this.registerController('a', Controller.extend({
251+
value: 'a'
252+
}));
253+
254+
this.registerController('b', Controller.extend({
255+
value: 'b'
256+
}));
257+
258+
this.registerTemplate('a', '{{value}}');
259+
this.registerTemplate('b', '{{value}}');
260+
261+
return this.visit('/a').then(() => {
262+
this.assertText('a');
263+
return this.visit('/b');
264+
}).then(() => this.assertText('b'));
265+
}
266+
244267
['@test it should update correctly when the controller changes'](assert) {
245268
this.router.map(function() {
246269
this.route('color', { path: '/colors/:color' });

packages/ember-glimmer/tests/integration/components/dynamic-components-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ moduleFor('Components test: dynamic components', class extends RenderingTest {
399399
this.assertText('foo-bar Caracas Caracas arepas!');
400400
}
401401

402-
['@htmlbars component helper with actions'](assert) {
402+
['@test component helper with actions'](assert) {
403403
this.registerComponent('inner-component', {
404404
template: 'inner-component {{yield}}',
405405
ComponentClass: Component.extend({

0 commit comments

Comments
 (0)