Skip to content

Commit

Permalink
replace common signal CHANGE_SIZE_END with a change size event. (ampp…
Browse files Browse the repository at this point in the history
  • Loading branch information
Enriqe committed Feb 8, 2019
1 parent 9895d70 commit 8b6c1cb
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/amp-events.js
Expand Up @@ -29,4 +29,5 @@ export const AmpEvents = {
LOAD_START: 'amp:load:start',
LOAD_END: 'amp:load:end',
ERROR: 'amp:error',
SIZE_CHANGED: 'amp:size-changed',
};
6 changes: 0 additions & 6 deletions src/common-signals.js
Expand Up @@ -50,10 +50,4 @@ export const CommonSignals = {
* The element has been unlaid out.
*/
UNLOAD: 'unload',

/**
* The changeSize function has been called on the element and it is now
* responsible for managing its own size.
*/
CHANGE_SIZE_END: 'change-size-end',
};
3 changes: 1 addition & 2 deletions src/custom-element.js
Expand Up @@ -726,7 +726,7 @@ function createBaseCustomElementClass(win) {
if (this.isAwaitingSize_()) {
this.sizeProvided_();
}
this.signals_.signal(CommonSignals.CHANGE_SIZE_END);
this.dispatchCustomEvent(AmpEvents.SIZE_CHANGED);
}

/**
Expand Down Expand Up @@ -1280,7 +1280,6 @@ function createBaseCustomElementClass(win) {
this.signals_.reset(CommonSignals.LOAD_START);
this.signals_.reset(CommonSignals.LOAD_END);
this.signals_.reset(CommonSignals.INI_LOAD);
this.signals_.reset(CommonSignals.CHANGE_SIZE_END);
}

/**
Expand Down
8 changes: 5 additions & 3 deletions test/unit/test-custom-element.js
Expand Up @@ -1226,11 +1226,13 @@ describes.realWin('CustomElement', {amp: true}, env => {
expect(element).not.to.have.class('i-amphtml-layout-awaiting-size');
});

it('should signal size-changed when size changed', () => {
it('should dispatch custom event size-changed when size changed', () => {
const element = new ElementClass();
const spyDispatchEvent = sandbox.spy(element, 'dispatchCustomEvent');

element.changeSize();
expect(element.signals().get(CommonSignals.CHANGE_SIZE_END)).to.be.ok;
return element.signals().whenSignal(CommonSignals.CHANGE_SIZE_END);

expect(spyDispatchEvent).to.be.calledWith(AmpEvents.SIZE_CHANGED);
});

describe('unlayoutCallback', () => {
Expand Down

0 comments on commit 8b6c1cb

Please sign in to comment.