Skip to content

Commit

Permalink
refactor: logger -> debug
Browse files Browse the repository at this point in the history
  • Loading branch information
anonymousRecords committed Jan 8, 2025
1 parent 9d36320 commit 5a32221
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
7 changes: 2 additions & 5 deletions packages/shadergradient-v2/src/ShaderGradient/Mesh/Mesh.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import {
} from '@/shaders/a'
// import { vertexShader, fragmentShader } from '@/shaders/base'
import { dToRArr } from '@/utils'

declare const __DEV__: boolean;
import { debug } from '@/utils/debug'

export function Mesh({
animate,
Expand Down Expand Up @@ -58,9 +57,7 @@ export function Mesh({
vertexShader={type === 'sphere' ? vertexSphere : vertexShader}
fragmentShader={type === 'sphere' ? fragmentSphere : fragmentShader}
onInit={(material) => {
if (__DEV__) {
console.debug('material (onInit)', material);
}
debug.performance('material (onInit)', material);
}}
/>
</mesh>
Expand Down
46 changes: 46 additions & 0 deletions packages/shadergradient-v2/src/utils/debug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
type DebugCategory = 'performance' | 'render'

const debugState: { [key in DebugCategory]: boolean } = {
performance: true,
render: true
}

export const debug = {
enable: (category: DebugCategory) => {
debugState[category] = true
},
disable: (category: DebugCategory) => {
debugState[category] = false
},
enableAll: () => {
Object.keys(debugState).forEach(key => {
debugState[key as DebugCategory] = true
})
},
disableAll: () => {
Object.keys(debugState).forEach(key => {
debugState[key as DebugCategory] = false
})
},
performance: (...args: any[]) => {
if (debugState.performance) {
console.log('[Performance]', ...args)
}
},
render: (...args: any[]) => {
if (debugState.render) {
console.log('[Render]', ...args)
}
}
}

// Expose the 'debug' function to the global 'window' object for accessibility across the application
declare global {
interface Window {
debug: typeof debug
}
}

if (typeof window !== 'undefined') {
window.debug = debug
}

0 comments on commit 5a32221

Please sign in to comment.