Skip to content

Commit c47355c

Browse files
chore: added minimal version of the Logger to the browser
This is just a spread of the console object into the Logger constant.
1 parent b600cf8 commit c47355c

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

lib/core/browser/html.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const htmlDocument = function htmlDocument(args: SlydeHtmlDocumentHtmlPro
4141
${baseTailwind()}
4242
<title>${args.title}</title>
4343
<!-- TODO: wget this script and then inject it as a string instead. -->
44+
<script> const Logger = Object.freeze({ ...console, critical: console.error }); </script>
4445
<script src="https://cdn.tailwindcss.com"></script>
4546
<script id="tailwind-config-setup"> tailwind.config = ${JSON.stringify(tailwindConfig({ ...args }))}; </script>
4647
<script id="event-listening-setup" type="module">${setupScriptCode}</script>

lib/core/browser/page-logic.browser.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
/* eslint-disable no-console */
2-
// I will remove this later when the logger is also in the web console.
3-
41
import type { DeepReadonly } from '#lib/types';
2+
import { Logger } from '#lib/logger';
53

64
let hideTimeout: NodeJS.Timeout | undefined; // eslint-disable-line @typescript-eslint/init-declarations
75

@@ -78,7 +76,7 @@ export function getCurrentSlideUrlHash({
7876
export const goToNextSlide = function goToNextSlide(): void {
7977
const currentSlide = getCurrentSlideUrlHash();
8078
const nextSlide = currentSlide + 1;
81-
console.log(`Going to the next slide: ${nextSlide}`);
79+
Logger.info(`Going to the next slide: ${nextSlide}`);
8280
setCurrentSlideUrlHash(nextSlide);
8381
};
8482

@@ -88,11 +86,11 @@ export const goToPreviousSlide = function goToPreviousSlide(): void {
8886
const previousSlide = currentSlide - 1;
8987

9088
if (previousSlide < 1) {
91-
console.log(`At the start of the presentation, cannot go back further.`);
89+
Logger.warn(`At the start of the presentation, cannot go back further.`);
9290
return;
9391
}
9492

95-
console.log(`Going to the previous slide: ${previousSlide}`);
93+
Logger.info(`Going to the previous slide: ${previousSlide}`);
9694
setCurrentSlideUrlHash(previousSlide);
9795
};
9896

@@ -117,12 +115,12 @@ export const handleUrlHashChange = function handleUrlHashChange(
117115
if (!match?.groups) {
118116
let message = `The new URL hash: ${newURL.hash} does not have a hash of the right shape: ${regex}.`;
119117
message += `Resetting it to the old value of ${oldUrl.hash}`;
120-
console.warn(message);
118+
Logger.warn(message);
121119
history.replaceState(null, '', event.oldURL);
122120
return;
123121
}
124122

125-
console.log(`Moved to: ${event.newURL}`);
123+
Logger.info(`Moved to: ${event.newURL}`);
126124
};
127125

128126
/** Handles mouse presses on the document, and moves slides accordingly. */

0 commit comments

Comments
 (0)