Skip to content

Commit

Permalink
[Glimmer2] Late bound layouts
Browse files Browse the repository at this point in the history
This currently depends on glimmerjs/glimmer-vm#179.
  • Loading branch information
chadhietala committed Jun 2, 2016
1 parent 839336c commit ffa68e0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"express": "^4.5.0",
"finalhandler": "^0.4.0",
"github": "^0.2.3",
"glimmer-engine": "tildeio/glimmer#1d686bb",
"glimmer-engine": "tildeio/glimmer#525e75e",
"glob": "^5.0.13",
"htmlbars": "0.14.23",
"mocha": "^2.4.5",
Expand Down
13 changes: 10 additions & 3 deletions packages/ember-glimmer/lib/syntax/curly-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,22 @@ class CurlyComponentManager {
return bucket;
}

ensureCompilable(definition, bucket) {
ensureCompilable(definition, bucket, env) {
if (definition.template) {
return definition;
}

let { component } = bucket;
let template = component.layout;
let TemplateFactory = component.layout;
let template;
let owner = getOwner(component);
if (!template) {

// If the user has supplied their own layout property we must
// create an instance of the wrapper class with the env to go back into
// the runtime compiler phase :(
if (TemplateFactory) {
template = new TemplateFactory(env);
} else {
let layoutName = component.layoutName && get(component, 'layoutName');
if (layoutName) {
template = owner.lookup('template:' + layoutName);
Expand Down
12 changes: 10 additions & 2 deletions packages/ember-glimmer/lib/syntax/dynamic-component.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { ArgsSyntax, StatementSyntax } from 'glimmer-runtime';
import { ConstReference, isConst, UNDEFINED_REFERENCE } from 'glimmer-reference';
import { assert } from 'ember-metal/debug';

function dynamicComponentFor(vm) {
let env = vm.env;
let args = vm.getArgs();
let nameRef = args.positional.at(0);

if (isConst(nameRef)) {
return new ConstReference(env.getComponentDefinition([nameRef.value()]));
let name = nameRef.value();
let definition = env.getComponentDefinition([name]);

assert(`Glimmer error: Could not find component named "${name}" (no component or template with that name was found)`, definition);
return new ConstReference(definition);
} else {
return new DynamicComponentReference({ nameRef, env });
}
Expand Down Expand Up @@ -37,7 +42,10 @@ class DynamicComponentReference {

value() {
let { env, nameRef } = this;
return env.getComponentDefinition([nameRef.value()]);
let name = nameRef.value();
let definition = env.getComponentDefinition([name]);
assert(`Glimmer error: Could not find component named "${name}" (no component or template with that name was found)`, definition);
return definition;
}

get() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* globals EmberDev */
import isEnabled from 'ember-metal/features';
import { set } from 'ember-metal/property_set';
import { observer } from 'ember-metal/mixin';
import { Component, compile } from '../../utils/helpers';
Expand Down Expand Up @@ -2068,18 +2067,6 @@ moduleFor('Components test: curly components', class extends RenderingTest {

this.assertText('foo – bar');

if (isEnabled('mandatory-setter')) {
expectAssertion(() => {
component.foo = 'new foo';
}, /You must use Ember\.set\(\) to set the `foo` property \(of .+\) to `new foo`\./);

expectAssertion(() => {
component.bar = 'new bar';
}, /You must use Ember\.set\(\) to set the `bar` property \(of .+\) to `new bar`\./);

this.assertText('foo – bar');
}

throws(() => {
this.runTask(() => { component.set('foo', 'new foo'); });
}, 'Cannot set the `foo` property (on component foo-bar) to `new foo`. The `foo` property came from an immutable binding in the template, such as {{foo-bar foo="string"}} or {{foo-bar foo=(if theTruth "truth" "false")}}.');
Expand Down Expand Up @@ -2116,14 +2103,6 @@ moduleFor('Components test: curly components', class extends RenderingTest {

this.assertText('initial value - initial value');

if (isEnabled('mandatory-setter')) {
expectAssertion(() => {
component.bar = 'foo-bar';
}, /You must use Ember\.set\(\) to set the `bar` property \(of .+\) to `foo-bar`\./);

this.assertText('initial value - initial value');
}

this.runTask(() => { component.set('bar', 'updated value'); });

this.assertText('updated value - updated value');
Expand Down

0 comments on commit ffa68e0

Please sign in to comment.