/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/** *Reduxstoreobjectwrappertotemporarilydisablethestoreupdatenotifications *whilethepanelishidden.TheReduxactionsarestilldispatchedandthereducers *willbeupdating,butthechangesarenotcommunicatedtoconnectedcomponents. *i.e.redux's`connect`methodwon'tbecalling`mapStateToProps`functionofallconnectedcomponents.
*/ function visibilityHandlerStore(store) { return { /** *Overridetopausecalling`listener`functionwhilethepanelishidden. *Thefunctionwillbecalledoncewhenthepanelisshown. * *@param{Function}listener *@param{object}options *@param{boolean}options.ignoreVisibility *Iftrue,bypassthishelpertolistentoallstoreupdates, *regarlessofpanelvisibility.Thisisusefulfortests.
*/
subscribe(listener, { ignoreVisibility = false } = {}) { // Test may pass a custom flag to ignore the visibility handler and listener // to all state changes regarless of panel's visibility. if (ignoreVisibility) { return store.subscribe(listener);
}
function onVisibilityChange() { if (document.visibilityState == "visible") { // Force an update to resume updates when the panel becomes visible again
listener();
}
}
document.addEventListener("visibilitychange", onVisibilityChange); const unsubscribe = store.subscribe(function () { // This is the key operation of this class, to prevent notification // when the panel is hidden. if (document.visibilityState == "visible") {
listener();
}
});
// Calling `subscribe` should return an unsubscribe function returnfunction () {
unsubscribe();
document.removeEventListener("visibilitychange", onVisibilityChange);
};
},
// Provide expected default store functions
getState() { return store.getState();
},
dispatch(action) { return store.dispatch(action);
},
};
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.