Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug with console.debug() #91

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ $ npm run watch

Open http://localhost:8080

# Enabling debugging
# Debugging

In the browser console:

```js
navigator.serviceWorker.controller.postMessage('toggleDebugging')
```
Enable console debug/verbose log level in your browser.
10 changes: 6 additions & 4 deletions src/browser/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import Pings from "./pings";
import User from "./user";

const pings = new Pings({
// TODO That any
workerUrl: assertNotNullable((window as any).app.pingWorkerUrl)
// TODO Avoid that any
workerUrl: (window as any).app.pingWorkerUrl
});

const user = new User();
Expand All @@ -36,12 +36,14 @@ import(/* webpackChunkName: "chart" */ "./chart").then(
import(/* webpackChunkName: "offline-support" */ "./offline-support").then(
({ default: OfflineSupport }) =>
new OfflineSupport({
// TODO That any
serviceWorkerUrl: assertNotNullable((window as any).app.serviceWorkerUrl),
// TODO Avoid that any
serviceWorkerUrl: (window as any).app.serviceWorkerUrl,
domElement: assertNotNullable(document.querySelector("#offline-support"))
})
);

// TODO Compose audio.ts and audio/controls.ts into a single importable

const whenAudioControls = import(
/* webpackChunkName: "audio-controls" */
"./audio/controls"
Expand Down
21 changes: 4 additions & 17 deletions src/browser/offline-support/service-worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ const worker = self as any;

import { timeout } from "../../../universal/util";

let isDebugEnabled = false;

const debug = (...args: any[]) => {
if (isDebugEnabled) console.log("[Service Worker]", ...args);
console.debug("[Service Worker]", ...args);
};

const isCacheableRequest = (request: Request) => {
Expand All @@ -20,13 +18,13 @@ const isCacheableRequest = (request: Request) => {
);
};

// TODO Find the right event type
// TODO Use the right event type
worker.addEventListener("install", (event: any) => {
debug("Installing...");
event.waitUntil(worker.skipWaiting().then(() => debug("Installed")));
});

// TODO Find the right event type
// TODO Use the right event type
worker.addEventListener("activate", (event: any) => {
debug("Activating...");
event.waitUntil(worker.clients.claim().then(() => debug("Activated")));
Expand All @@ -39,7 +37,7 @@ const MAX_ACCEPTABLE_RESPONSE_TIME = 1000; // ms

let nextFetchId = 1;

// TODO Find the right event type
// TODO Use the right event type
worker.addEventListener("fetch", (event: any) => {
const fetchId = (nextFetchId += 1);
const fetchDebug = (...args: any[]) => debug(`[Fetch #${fetchId}]`, ...args);
Expand Down Expand Up @@ -74,14 +72,3 @@ worker.addEventListener("fetch", (event: any) => {
})
);
});

// TODO Find the right event type
worker.addEventListener("message", (event: any) => {
switch (event.data) {
case "toggleDebugging":
isDebugEnabled = !isDebugEnabled;
break;
default:
throw new Error("Unknown message");
}
});
1 change: 1 addition & 0 deletions webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const configFactory: webpack.ConfigurationFactory = (_, args) => {
new CopyPlugin([{ from: "static" }]),
new webpack.DefinePlugin({ BUILD_ID: Date.now() }),
new webpack.BannerPlugin({
// TODO Submit fix for banner type not accepting functions
banner: (() => `Build date: ${getBuildDate()}`) as any
}),
new HtmlPlugin({
Expand Down