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

Fix component hooks #304

Merged
merged 3 commits into from
Sep 7, 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
27 changes: 11 additions & 16 deletions packages/glimmer-runtime/lib/compiled/opcodes/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CompiledArgs, EvaluatedArgs } from '../../compiled/expressions/args';
import { Templates } from '../../syntax/core';
import { DynamicScope } from '../../environment';
import Bounds from '../../bounds';
import { CONSTANT_TAG, PathReference, ReferenceCache, Revision, combine, isConst } from 'glimmer-reference';
import { CONSTANT_TAG, PathReference, ReferenceCache, combine, isConst } from 'glimmer-reference';
import { FIXME } from 'glimmer-util';

export class PutDynamicComponentDefinitionOpcode extends Opcode {
Expand Down Expand Up @@ -69,7 +69,6 @@ export class OpenComponentOpcode extends Opcode {
vm.stack().pushSimpleBlock();
vm.pushRootScope(selfRef, layout.symbols);
vm.invokeLayout(args, layout, templates, callerScope, component, manager, shadow);
vm.env.didCreate(component, manager);

vm.updateWith(new UpdateComponentOpcode(definition.name, component, manager, args, dynamicScope));
}
Expand All @@ -78,8 +77,6 @@ export class OpenComponentOpcode extends Opcode {
export class UpdateComponentOpcode extends UpdatingOpcode {
public type = "update-component";

private lastUpdated: Revision;

constructor(
private name: string,
private component: Component,
Expand All @@ -89,26 +86,19 @@ export class UpdateComponentOpcode extends UpdatingOpcode {
) {
super();

let tag;
let componentTag = manager.getTag(component);

if (componentTag) {
tag = this.tag = combine([args.tag, componentTag]);
this.tag = combine([args.tag, componentTag]);
} else {
tag = this.tag = args.tag;
this.tag = args.tag;
}

this.lastUpdated = tag.value();
}

evaluate(vm: UpdatingVM) {
let { component, manager, tag, args, dynamicScope, lastUpdated } = this;
let { component, manager, args, dynamicScope } = this;

if (!tag.validate(lastUpdated)) {
manager.update(component, args, dynamicScope);
vm.env.didUpdate(component, manager);
this.lastUpdated = tag.value();
}
manager.update(component, args, dynamicScope);
}

toJSON(): OpcodeJSON {
Expand Down Expand Up @@ -175,6 +165,8 @@ export class DidRenderLayoutOpcode extends Opcode {

manager.didRenderLayout(component, bounds);

vm.env.didCreate(component, manager);

vm.updateWith(new DidUpdateLayoutOpcode(manager, component, bounds));
}
}
Expand All @@ -191,9 +183,12 @@ export class DidUpdateLayoutOpcode extends UpdatingOpcode {
super();
}

evaluate() {
evaluate(vm: UpdatingVM) {
let { manager, component, bounds } = this;

manager.didUpdateLayout(component, bounds);

vm.env.didUpdate(component, manager);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/glimmer-runtime/lib/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export abstract class Environment {
manager.didCreate(component);
}

for (let i=this.updatedComponents.length-1; i>=0; i--) {
for (let i=0; i<this.updatedComponents.length; i++) {
let component = this.updatedComponents[i];
let manager = this.updatedManagers[i];
manager.didUpdate(component);
Expand Down
4 changes: 2 additions & 2 deletions packages/glimmer-runtime/tests/ember-component-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1059,8 +1059,8 @@ QUnit.test('dynamic attribute bindings', assert => {
attributeBindings = ['style'];
style: string = null;

constructor() {
super();
constructor(attrs) {
super(attrs);
this.style = 'color: red;';
fooBarInstance = this;
}
Expand Down