Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Adding back didUpdate hook to glimmer.js component-manager #204

Merged
merged 1 commit into from
Aug 13, 2019
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
10 changes: 9 additions & 1 deletion packages/@glimmer/component/src/component-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,15 @@ export default class ComponentManager

didUpdateLayout() {}

didUpdate() {}
didUpdate(bucket: ComponentStateBucket) {
if (DEBUG && bucket instanceof TemplateOnlyComponentDebugBucket) {
return;
}
if (!bucket) {
return;
}
bucket.component.didUpdate();
}

getDestructor(bucket: ComponentStateBucket): Destroyable {
if (DEBUG && bucket instanceof TemplateOnlyComponentDebugBucket) {
Expand Down
30 changes: 26 additions & 4 deletions packages/@glimmer/component/test/browser/lifecycle-hook-test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Component from '@glimmer/component';
import { buildApp } from '@glimmer/application-test-helpers';
import { buildApp, didRender } from '@glimmer/application-test-helpers';
import { tracked, setPropertyDidChange } from '@glimmer/tracking';

const { module, test } = QUnit;

Expand All @@ -9,6 +10,7 @@ test('Lifecycle hook ordering', async function(assert) {
assert.expect(1);

let invocations: [string, string][] = [];
let component1: Component1;

abstract class HookLoggerComponent extends Component {
args: {
Expand All @@ -23,19 +25,29 @@ test('Lifecycle hook ordering', async function(assert) {
didInsertElement() {
invocations.push([this.args.name, 'didInsertElement']);
}

didUpdate() {
invocations.push([this.args.name, 'didUpdate']);
}
}

class Component1 extends HookLoggerComponent {}
class Component1 extends HookLoggerComponent {
@tracked firstName = 'Chirag';
constructor(owner, args) {
super(owner, args);
component1 = this;
}
}
class Component2 extends HookLoggerComponent {}
class Component3 extends HookLoggerComponent {}
class Component4 extends HookLoggerComponent {}
class Component5 extends HookLoggerComponent {}

await buildApp()
const app = await buildApp()
.template('Main', '<div><ComponentOne @name="component1"/></div>')
.template(
'ComponentOne',
'<div><ComponentTwo @name="component2"/><ComponentThree @name="component3"/></div>'
'<div><ComponentTwo @name="component2" @firstName={{this.firstName}} /><ComponentThree @name="component3"/></div>'
)
.template(
'ComponentTwo',
Expand All @@ -51,6 +63,14 @@ test('Lifecycle hook ordering', async function(assert) {
.component('ComponentFive', Component5)
.boot();

setPropertyDidChange(() => {
app.scheduleRerender();
});

component1.firstName = 'Test';

await didRender(app);

assert.deepEqual(invocations, [
['component1', 'constructor'],
['component2', 'constructor'],
Expand All @@ -62,6 +82,8 @@ test('Lifecycle hook ordering', async function(assert) {
['component2', 'didInsertElement'],
['component3', 'didInsertElement'],
['component1', 'didInsertElement'],
['component2', 'didUpdate'],
['component1', 'didUpdate'],
]);
});

Expand Down