mediawiki-extensions-Popups/resources/ext.popups/renderChangeListener.js
Sam Smith eabb7011fb Don't always render after the API request resolves
If the user abandons the link after the API request delay (500 ms) but
before the it resolves (~10e3 ms), then the preview shouldn't be
rendered.

Changes:
* actions: Include the link in the FETCH_START, FETCH_FAILED, and
  FETCH_END actions.
* reducers: If the active link has changed, then FETCH_END is a NOOP.

Supporting changes:
* reducers: Signal that a preview should be rendered and shown with
  preview.shouldShow.

Change-Id: I3dd1c0c566ec63de515174c14845d7927583ce93
2016-11-25 12:42:02 +00:00

25 lines
576 B
JavaScript

( function ( mw ) {
/**
* Creates an instance of the render change listener.
*
* @return {ext.popups.ChangeListener}
*/
mw.popups.changeListeners.render = function () {
var preview;
return function ( prevState, state ) {
if ( state.preview.shouldShow && !preview ) {
preview = mw.popups.renderer.render( state.preview.fetchResponse );
preview.show( state.preview.activeEvent );
} else if ( !state.preview.shouldShow && preview ) {
preview.hide()
.done( function () {
preview = undefined;
} );
}
};
};
}( mediaWiki ) );