Skip to content

Commit

Permalink
remove boolean return from unmountCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
Dima Voytenko committed Mar 17, 2021
1 parent 7eda38c commit a51c8b3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
7 changes: 1 addition & 6 deletions src/base-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,13 +540,8 @@ export class BaseElement {

/**
* Unload heavy elements, remove global listeners, etc.
*
* @return {boolean} Return `true` if the element should be remounted
* the next time it's displayed.
*/
unmountCallback() {
return false;
}
unmountCallback() {}

/**
* Subclasses can override this method to opt-in into receiving additional
Expand Down
9 changes: 3 additions & 6 deletions src/custom-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -714,12 +714,9 @@ function createBaseCustomElementClass(win, elementConnectedCallback) {
const scheduler = getSchedulerForDoc(this.getAmpDoc());
scheduler.unschedule(this);

// Try to unmount. Not every element has been mounted, can be unmounted
// or has anything to unmount.
const reMount =
!this.mountPromise_ || !this.impl_ || this.impl_.unmountCallback();
if (!reMount) {
return;
// Try to unmount if the element has been built already.
if (this.isBuilt()) {
this.impl_.unmountCallback();
}

// Complete unmount and reset the state.
Expand Down
9 changes: 9 additions & 0 deletions testing/element-v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ const RULES = [
return !hasCallback;
},
},
{
name: 'Must not have resumeCallback',
test: (implClass) => {
const hasCallback =
implClass.prototype.resumeCallback !==
BaseElement.prototype.resumeCallback;
return !hasCallback;
},
},

{
name: 'If load==true, must also have ensureLoaded',
Expand Down

0 comments on commit a51c8b3

Please sign in to comment.