Skip to content

Commit

Permalink
feat: ✨Krpano组件支持enableLogger参数
Browse files Browse the repository at this point in the history
✨支持通过Krpano组件的enableLogger参数开启或关闭调试信息的打印
  • Loading branch information
0xLLLLH committed Mar 3, 2021
1 parent 1c4b50b commit 158955f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/components/Krpano.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface KrpanoProps {
target?: string;
id?: string;
onReady?: (renderer: KrpanoActionProxy) => void;
enableLogger?: boolean;
}

export const Krpano: React.FC<KrpanoProps> = ({
Expand All @@ -24,13 +25,15 @@ export const Krpano: React.FC<KrpanoProps> = ({
xml,
onReady,
children,
enableLogger = false,
}) => {
const [renderer, setRenderer] = React.useState<KrpanoActionProxy | null>(null);
const onReadyCallback = React.useCallback(
(obj: NativeKrpanoRendererObject) => {
const renderer = new KrpanoActionProxy(obj);
(window as any)[renderer.name] = renderer;
setRenderer(renderer);
Logger.enabled = enableLogger;
Logger.log('Renderer ready.');

if (onReady) {
Expand Down
3 changes: 2 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ export const buildKrpanoTagSetterActions = (
.join('');

export const Logger = {
enabled: false,
log: (...args: any[]): void => {
/* istanbul ignore next */
if (process.env.NODE_ENV === 'development') {
if (Logger.enabled && process.env.NODE_ENV === 'development') {
console.log(...args);
}
},
Expand Down

0 comments on commit 158955f

Please sign in to comment.