mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-02-01 03:12:42 +01:00
Pad: Deprecate use of global variables
This commit is contained in:
parent
2b53c69749
commit
b325a145d6
1 changed files with 18 additions and 5 deletions
|
@ -486,11 +486,24 @@
|
||||||
window._postPluginUpdateForTestingDone = true;
|
window._postPluginUpdateForTestingDone = true;
|
||||||
$(() => hooks.aCallAll('documentReady'));
|
$(() => hooks.aCallAll('documentReady'));
|
||||||
|
|
||||||
// TODO: These globals shouldn't exist.
|
// TODO: Delete these global variables once plugins have been updated to not use them.
|
||||||
window.pad = require('ep_etherpad-lite/static/js/pad').pad;
|
const globals = {
|
||||||
window.chat = require('ep_etherpad-lite/static/js/chat').chat;
|
pad: require('ep_etherpad-lite/static/js/pad').pad,
|
||||||
window.padeditbar = require('ep_etherpad-lite/static/js/pad_editbar').padeditbar;
|
chat: require('ep_etherpad-lite/static/js/chat').chat,
|
||||||
window.padimpexp = require('ep_etherpad-lite/static/js/pad_impexp').padimpexp;
|
padeditbar: require('ep_etherpad-lite/static/js/pad_editbar').padeditbar,
|
||||||
|
padimpexp: require('ep_etherpad-lite/static/js/pad_impexp').padimpexp,
|
||||||
|
};
|
||||||
|
// Wrap each of the above globals in a Proxy object that triggers an unhandled Promise
|
||||||
|
// rejection if the global is used (but otherwise forwards the access so that everything
|
||||||
|
// continues to work, just with an ugly error popup).
|
||||||
|
const proxyOp = (op, ...args) => {
|
||||||
|
Promise.reject(new Error('deprecated global variable accessed'));
|
||||||
|
return op(...args);
|
||||||
|
};
|
||||||
|
const proxyHandler = Object.fromEntries(
|
||||||
|
['get', 'set'].map((opName) => [opName, proxyOp.bind(null, Reflect[opName])]));
|
||||||
|
Object.assign(window, Object.fromEntries(
|
||||||
|
Object.entries(globals).map(([k, v]) => [k, new Proxy(v, proxyHandler)])));
|
||||||
|
|
||||||
require('ep_etherpad-lite/static/js/skin_variants');
|
require('ep_etherpad-lite/static/js/skin_variants');
|
||||||
const pad = require('ep_etherpad-lite/static/js/pad');
|
const pad = require('ep_etherpad-lite/static/js/pad');
|
||||||
|
|
Loading…
Reference in a new issue