summaryrefslogtreecommitdiff
path: root/extension
diff options
context:
space:
mode:
authorOmar Rizwan <omar@omar.website>2021-04-22 16:48:01 -0700
committerOmar Rizwan <omar@omar.website>2021-04-22 16:48:01 -0700
commite404d44985869544beceb4e9ea259f5cf3926a3a (patch)
treed9f05745035839a1eeb7509799746b9caf8b65a8 /extension
parent158ad14f97646099809484b3fb3c0c61dc7160e9 (diff)
downloadTabFS-e404d44985869544beceb4e9ea259f5cf3926a3a.tar.gz
TabFS-e404d44985869544beceb4e9ea259f5cf3926a3a.zip
extension: allow hot patching of Routes; keep backgroundJS alive
(across hot reloads)
Diffstat (limited to 'extension')
-rw-r--r--extension/background.js20
1 files changed, 11 insertions, 9 deletions
diff --git a/extension/background.js b/extension/background.js
index d58fbb2..c885d45 100644
--- a/extension/background.js
+++ b/extension/background.js
@@ -153,7 +153,8 @@ const routeWithContents = (function() {
return routeWithContents;
})();
-const Routes = {};
+// global so it can be hot-reloaded
+window.Routes = {};
Routes["/tabs/create"] = {
usage: 'echo "https://www.google.com" > $0',
@@ -572,16 +573,19 @@ Routes["/runtime/reload"] = {
};
(function() {
- let __backgroundJS;
+ // window.__backgroundJS needs to be a global because we want
+ // its value (the changed JS text) to survive even as this whole
+ // module gets re-evaluated.
+ window.__backgroundJS = window.__backgroundJS || false;
Object.defineProperty(window, 'backgroundJS', {
async get() {
- if (!__backgroundJS) {
- __backgroundJS = await window.fetch(chrome.runtime.getURL('background.js'))
+ if (!window.__backgroundJS) {
+ window.__backgroundJS = await window.fetch(chrome.runtime.getURL('background.js'))
.then(r => r.text());
}
- return __backgroundJS;
+ return window.__backgroundJS;
},
- set(js) { __backgroundJS = js; },
+ set(js) { window.__backgroundJS = js; },
configurable: true // so we can rerun this on hot reload
});
})();
@@ -594,9 +598,7 @@ Routes["/runtime/background.js"] = {
...routeWithContents(
async () => {
// `window.backgroundJS` is the source code of the file you're
- // reading right now! it needs to be a global because we want
- // its value (the changed JS text) to survive even as this whole
- // module gets re-evaluated.
+ // reading right now!
return window.backgroundJS;
},
async ({}, buf) => { window.backgroundJS = buf; }