Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate with Glimmer reference interface #12901

Merged
merged 1 commit into from
Feb 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/ember-glimmer/lib/ember-metal-views/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { RootReference } from '../environment';

export class Renderer {
constructor(domHelper, { destinedForDOM, env } = {}) {
this._dom = domHelper;
Expand All @@ -6,9 +8,10 @@ export class Renderer {

appendTo(view, target) {
let env = this._env;
let self = new RootReference(view);

env.begin();
let result = view.template.render(view, env, { appendTo: target });
let result = view.template.render(self, env, { appendTo: target });
env.commit();

// FIXME: Store this somewhere else
Expand Down
61 changes: 61 additions & 0 deletions packages/ember-glimmer/lib/environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Environment } from 'glimmer-runtime';
import { get } from 'ember-metal/property_get';

// @implements PathReference
export class RootReference {
constructor(value) {
this._value = value;
}

value() {
return this._value;
}

isDirty() {
return true;
}

get(propertyKey) {
return new PropertyReference(this, propertyKey);
}

destroy() {
}
}

// @implements PathReference
class PropertyReference {
constructor(parentReference, propertyKey) {
this._parentReference = parentReference;
this._propertyKey = propertyKey;
}

value() {
return get(this._parentReference.value(), this._propertyKey);
}

isDirty() {
return true;
}

get(propertyKey) {
return new PropertyReference(this, propertyKey);
}

destroy() {
}
}

export default class extends Environment {
hasComponentDefinition() {
return false;
}

hasHelper() {
return false;
}

rootReferenceFor(value) {
return new RootReference(value);
}
}
1 change: 1 addition & 0 deletions packages/ember-glimmer/lib/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as Environment } from 'ember-glimmer/environment';
61 changes: 61 additions & 0 deletions packages/ember-glimmer/tests/integration/content-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { RenderingTest, moduleFor } from '../utils/test-case';
import { set } from 'ember-metal/property_set';
import { computed } from 'ember-metal/computed';
import EmberObject from 'ember-runtime/system/object';

moduleFor('Static content tests', class extends RenderingTest {

Expand Down Expand Up @@ -81,6 +83,65 @@ moduleFor('Dynamic content tests', class extends RenderingTest {
this.assertSameNode(text1, text4);
}

['@test it can render a dynamic text node with deeply nested paths']() {
this.render('{{a.b.c.d.e.f}}', {
a: { b: { c: { d: { e: { f: 'hello' } } } } }
});
let text1 = this.assertTextNode(this.firstChild, 'hello');

this.rerender();
let text2 = this.assertTextNode(this.firstChild, 'hello');

this.assertSameNode(text1, text2);

set(this.context, 'a.b.c.d.e.f', 'goodbye');

this.rerender();
let text3 = this.assertTextNode(this.firstChild, 'goodbye');

this.assertSameNode(text1, text3);

set(this.context, 'a.b.c.d.e.f', 'hello');

this.rerender();
let text4 = this.assertTextNode(this.firstChild, 'hello');

this.assertSameNode(text1, text4);
}

['@test it can render a dynamic text node where the value is a computed property']() {
let Formatter = EmberObject.extend({
formattedMessage: computed('message', function() {
return this.get('message').toUpperCase();
})
});

let m = Formatter.create({ message: 'hello' });

this.render('{{m.formattedMessage}}', { m });

let text1 = this.assertTextNode(this.firstChild, 'HELLO');

this.rerender();
let text2 = this.assertTextNode(this.firstChild, 'HELLO');

this.assertSameNode(text1, text2);

set(m, 'message', 'goodbye');

this.rerender();
let text3 = this.assertTextNode(this.firstChild, 'GOODBYE');

this.assertSameNode(text1, text3);

set(m, 'message', 'hello');

this.rerender();
let text4 = this.assertTextNode(this.firstChild, 'HELLO');

this.assertSameNode(text1, text4);
}

['@test it can render a dynamic element']() {
this.render('<p>{{message}}</p>', {
message: 'hello'
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-glimmer/tests/utils/environment.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { TestEnvironment as default } from 'glimmer-test-helpers';
export { Environment as default } from 'ember-glimmer';