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

[BUGFIX] Adds default implementations of Component lifecycle hooks #17169

Merged
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
6 changes: 6 additions & 0 deletions packages/@ember/-internals/glimmer/lib/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,7 @@ const Component = CoreView.extend(
@public
@since 1.13.0
*/
didReceiveAttrs() {},

/**
Called when the attributes passed into the component have been updated.
Expand All @@ -769,6 +770,7 @@ const Component = CoreView.extend(
@public
@since 1.13.0
*/
didRender() {},

/**
Called after a component has been rendered, both on initial render and
Expand All @@ -785,6 +787,7 @@ const Component = CoreView.extend(
@public
@since 1.13.0
*/
willRender() {},

/**
Called before a component has been rendered, both on initial render and
Expand All @@ -801,6 +804,7 @@ const Component = CoreView.extend(
@public
@since 1.13.0
*/
didUpdateAttrs() {},

/**
Called when the attributes passed into the component have been changed.
Expand All @@ -817,6 +821,7 @@ const Component = CoreView.extend(
@public
@since 1.13.0
*/
willUpdate() {},

/**
Called when the component is about to update and rerender itself.
Expand All @@ -833,6 +838,7 @@ const Component = CoreView.extend(
@public
@since 1.13.0
*/
didUpdate() {},

/**
Called when the component has updated and rerendered itself.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,24 @@ moduleFor(
]
);
}

['@test lifecycle hooks exist on the base class'](assert) {
// Make sure we get the finalized component prototype
let prototype = Component.proto();

assert.equal(typeof prototype.didDestroyElement, 'function', 'didDestroyElement exists');
assert.equal(typeof prototype.didInsertElement, 'function', 'didInsertElement exists');
assert.equal(typeof prototype.didReceiveAttrs, 'function', 'didReceiveAttrs exists');
assert.equal(typeof prototype.didRender, 'function', 'didRender exists');
assert.equal(typeof prototype.didUpdate, 'function', 'didUpdate exists');
assert.equal(typeof prototype.didUpdateAttrs, 'function', 'didUpdateAttrs exists');
assert.equal(typeof prototype.willClearRender, 'function', 'willClearRender exists');
assert.equal(typeof prototype.willDestroy, 'function', 'willDestroy exists');
assert.equal(typeof prototype.willDestroyElement, 'function', 'willDestroyElement exists');
assert.equal(typeof prototype.willInsertElement, 'function', 'willInsertElement exists');
assert.equal(typeof prototype.willRender, 'function', 'willRender exists');
assert.equal(typeof prototype.willUpdate, 'function', 'willUpdate exists');
}
}
);

Expand Down
8 changes: 8 additions & 0 deletions packages/@ember/-internals/views/lib/mixins/view_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,14 @@ export default Mixin.create({
*/
willDestroyElement: K,

/**
Called after the element of the view is destroyed.

@event willDestroyElement
@public
*/
didDestroyElement: K,

/**
Called when the parentView property has changed.

Expand Down