mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-12-23 04:22:46 +00:00
20e7564bed
boot.js is renamed to index.js and popups is now bundled up inside popups.js To support qunit tests, the library is still exposed as mw.popups with a FIXME to remove later when it is no longer necessary Bug: T156333 Change-Id: Ieb6b4b0344af2701f99ef0fcc786d2378fd2fceb
39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
/**
|
|
* @typedef {Function} ext.popups.ChangeListener
|
|
* @param {Object} prevState The previous state
|
|
* @param {Object} state The current state
|
|
*/
|
|
|
|
/**
|
|
* Registers a change listener, which is bound to the
|
|
* [store](http://redux.js.org/docs/api/Store.html).
|
|
*
|
|
* A change listener is a function that is only invoked when the state in the
|
|
* [store](http://redux.js.org/docs/api/Store.html) changes. N.B. that there
|
|
* may not be a 1:1 correspondence with actions being dispatched to the store
|
|
* and the state in the store changing.
|
|
*
|
|
* See [Store#subscribe](http://redux.js.org/docs/api/Store.html#subscribe)
|
|
* for more information about what change listeners may and may not do.
|
|
*
|
|
* @param {Redux.Store} store
|
|
* @param {ext.popups.ChangeListener} callback
|
|
*/
|
|
module.exports = function ( store, callback ) {
|
|
// This function is based on the example in [the documentation for
|
|
// Store#subscribe](http://redux.js.org/docs/api/Store.html#subscribe),
|
|
// which was written by Dan Abramov.
|
|
|
|
var state;
|
|
|
|
store.subscribe( function () {
|
|
var prevState = state;
|
|
|
|
state = store.getState();
|
|
|
|
if ( prevState !== state ) {
|
|
callback( prevState, state );
|
|
}
|
|
} );
|
|
};
|