Skip to content

Commit

Permalink
Merge pull request #17169 from pzuraq/bugfix/add-default-hooks-to-com…
Browse files Browse the repository at this point in the history
…ponent

[BUGFIX] Adds default implementations of Component lifecycle hooks
  • Loading branch information
rwjblue authored Nov 1, 2018
2 parents d5c54c0 + 50135f5 commit f8fd83e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
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

0 comments on commit f8fd83e

Please sign in to comment.