From fa15fbcb0348e40d7a857cf781ba0b15a2cc5771 Mon Sep 17 00:00:00 2001 From: Dirk Holtwick Date: Thu, 7 Nov 2024 11:49:30 +0100 Subject: [PATCH 1/3] feat: context for Channel --- src/common/msg/channel.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/common/msg/channel.ts b/src/common/msg/channel.ts index 9990074..f08b284 100644 --- a/src/common/msg/channel.ts +++ b/src/common/msg/channel.ts @@ -14,7 +14,7 @@ export interface ChannelMessageEvent { * http://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel * https://deno.com/deploy/docs/runtime-broadcast-channel */ -export abstract class Channel extends Emitter<{ +export abstract class Channel> extends Emitter<{ message: (event: ChannelMessageEvent) => void messageerror: (event: ChannelMessageEvent) => void // optional connect: () => void // optional @@ -22,6 +22,10 @@ export abstract class Channel extends Emitter<{ close: () => void }> { id: string = uuid() + + // Put you own channel context here + context: ContextType = {} as ContextType + abstract isConnected?: boolean abstract postMessage(data: T): void From be92e92c40a3ac29d1de6126deef523c542dc21b Mon Sep 17 00:00:00 2001 From: Dirk Holtwick Date: Thu, 7 Nov 2024 15:54:05 +0100 Subject: [PATCH 2/3] fix: localStorage availability --- src/browser/log/log-browser-factory.ts | 4 +++- src/browser/log/log-context-browser.ts | 5 +++-- src/common/platform.ts | 9 +++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/browser/log/log-browser-factory.ts b/src/browser/log/log-browser-factory.ts index f9a9f9a..1fadf0e 100644 --- a/src/browser/log/log-browser-factory.ts +++ b/src/browser/log/log-browser-factory.ts @@ -3,6 +3,7 @@ import { LogLevelAll, LogLevelDebug, LogLevelError, LogLevelFatal, LogLevelInfo, import { browserSelectColorByName } from '../../common/log/log-colors' import { getGlobalConsole } from '../../common/log/log-console-original' import { parseLogLevel, useNamespaceFilter } from '../../common/log/log-filter' +import { getLocalStorage } from '../../common/platform' import { browserSupportsColors } from './log-colors' /** @@ -11,7 +12,8 @@ import { browserSupportsColors } from './log-colors' * loggers will not work any more. */ export function LoggerBrowserSetupDebugFactory(opt: LogHandlerOptions = {}) { - const filter = opt.filter ?? localStorage.zeed ?? localStorage.debug + const localStorage = getLocalStorage() + const filter = opt.filter ?? localStorage?.zeed ?? localStorage?.debug const styleFont = 'font-family: "JetBrains Mono", Menlo; font-size: 11px;' const styleDefault = `${styleFont}` const styleBold = `font-weight: 600; ${styleFont}` diff --git a/src/browser/log/log-context-browser.ts b/src/browser/log/log-context-browser.ts index 249aed8..68db309 100644 --- a/src/browser/log/log-context-browser.ts +++ b/src/browser/log/log-context-browser.ts @@ -3,13 +3,14 @@ import type { LogConfig } from '../../common/log/log-config' import { isEmpty } from '../../common/data/is' import { getGlobalLogger } from '../../common/log/log' import { _LoggerFromConfig } from '../../common/log/log-config' -import { isBrowser } from '../../common/platform' +import { getLocalStorage, isBrowser } from '../../common/platform' import { LoggerBrowserHandler } from './log-browser' import { LoggerBrowserSetupDebugFactory } from './log-browser-factory' export function Logger(name?: string, level?: LogLevelAliasType): LoggerInterface { return getGlobalLogger((context) => { - if (isBrowser() && !isEmpty(localStorage.getItem('zeed'))) { + const localStorage = getLocalStorage() + if (isBrowser() && !isEmpty(localStorage?.getItem('zeed'))) { context.setHandlers([LoggerBrowserHandler()]) // Fallback for previously registered Loggers context.setFactory(LoggerBrowserSetupDebugFactory({})) } diff --git a/src/common/platform.ts b/src/common/platform.ts index dfc8dc2..9caf460 100644 --- a/src/common/platform.ts +++ b/src/common/platform.ts @@ -1,6 +1,15 @@ /* eslint-disable no-restricted-globals */ /* eslint-disable node/prefer-global/process */ +/** + * Retrieves the global `localStorage` object. + * @returns The global `localStorage` object if available, otherwise `undefined`. + */ +export function getLocalStorage(): any | undefined { + if (typeof localStorage !== 'undefined') + return localStorage +} + /** * Retrieves the global `window` object. * @returns The global `window` object if available, otherwise `undefined`. From a4dafec7d5b50d85b1315c0723aa8d94fe4a7491 Mon Sep 17 00:00:00 2001 From: Dirk Holtwick Date: Thu, 7 Nov 2024 15:54:08 +0100 Subject: [PATCH 3/3] 0.25.8 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2b7f226..4ab61fc 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "zeed", "type": "module", - "version": "0.25.7", + "version": "0.25.8", "description": "🌱 Simple foundation library", "author": { "name": "Dirk Holtwick",