Skip to content

Commit

Permalink
Merge branch 'release/v0.25.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
holtwick committed Nov 7, 2024
2 parents f4e1d47 + a4dafec commit 0e21f3b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "zeed",
"type": "module",
"version": "0.25.7",
"version": "0.25.8",
"description": "🌱 Simple foundation library",
"author": {
"name": "Dirk Holtwick",
Expand Down
4 changes: 3 additions & 1 deletion src/browser/log/log-browser-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

/**
Expand All @@ -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}`
Expand Down
5 changes: 3 additions & 2 deletions src/browser/log/log-context-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({}))
}
Expand Down
6 changes: 5 additions & 1 deletion src/common/msg/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ export interface ChannelMessageEvent<T = any> {
* http://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel
* https://deno.com/deploy/docs/runtime-broadcast-channel
*/
export abstract class Channel<T = any> extends Emitter<{
export abstract class Channel<T = any, ContextType = Record<string, any>> extends Emitter<{
message: (event: ChannelMessageEvent<T>) => void
messageerror: (event: ChannelMessageEvent<T>) => void // optional
connect: () => void // optional
disconnect: () => void // optional
close: () => void
}> {
id: string = uuid()

// Put you own channel context here
context: ContextType = {} as ContextType

abstract isConnected?: boolean
abstract postMessage(data: T): void

Expand Down
9 changes: 9 additions & 0 deletions src/common/platform.ts
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down

0 comments on commit 0e21f3b

Please sign in to comment.