debug-time-machine-react-client
Version:
๐ฐ๏ธ ์์ ์๋ํ๋ React ๋๋ฒ๊น ๋ผ์ด๋ธ๋ฌ๋ฆฌ - ์ค์นํ๊ณ ๋ฐ๋ก ์ฌ์ฉํ์ธ์!
178 lines (134 loc) โข 4.71 kB
Markdown
# debug-time-machine-react-client
React ์ฑ์์ Debug Time Machine์ ์ฝ๊ฒ ์ฌ์ฉํ ์ ์๋ React Hook ํจํค์ง์
๋๋ค.
## ์ค์น
```bash
npm install debug-time-machine-react-client
# ๋๋
yarn add debug-time-machine-react-client
# ๋๋
pnpm add debug-time-machine-react-client
```
## ์ฌ์ฉ๋ฒ
### ๊ธฐ๋ณธ ์ฌ์ฉ๋ฒ
```tsx
import { useDebugTimeMachine } from 'debug-time-machine-react-client';
function App() {
const { isConnected, clientId } = useDebugTimeMachine();
return (
<div>
{isConnected ? (
<p>โ
Time Machine connected! Client ID: {clientId}</p>
) : (
<p>๐ Connecting to Time Machine...</p>
)}
<YourAppContent />
</div>
);
}
```
### ๊ณ ๊ธ ์ค์
```tsx
import { useDebugTimeMachine } from 'debug-time-machine-react-client';
function App() {
const timeMachine = useDebugTimeMachine({
websocketUrl: 'ws://localhost:3001/ws',
debugMode: true,
captureUserActions: true,
captureErrors: true,
captureStateChanges: true,
maxReconnectAttempts: 5,
reconnectInterval: 3000,
developmentOnly: true,
});
// ์๋์ผ๋ก ์ํ ๋ณ๊ฒฝ ์บก์ฒ
const handleStateChange = () => {
timeMachine.captureStateChange(
'MyComponent',
{ count: 0 },
{ count: 1 },
{ userId: 123 }
);
};
// ์๋์ผ๋ก ์๋ฌ ์บก์ฒ
const handleError = () => {
try {
throw new Error('Something went wrong!');
} catch (error) {
timeMachine.captureError(error, { context: 'user action' });
}
};
return (
<div>
<h1>Debug Time Machine Demo</h1>
<div>
<p>์ฐ๊ฒฐ ์ํ: {timeMachine.isConnected ? 'โ
์ฐ๊ฒฐ๋จ' : 'โ ์ฐ๊ฒฐ ์๋จ'}</p>
<p>ํด๋ผ์ด์ธํธ ID: {timeMachine.clientId || 'N/A'}</p>
<p>์ฌ์ฐ๊ฒฐ ์๋: {timeMachine.connectionInfo.reconnectAttempts}</p>
{timeMachine.connectionInfo.lastError && (
<p>๋ง์ง๋ง ์๋ฌ: {timeMachine.connectionInfo.lastError}</p>
)}
</div>
<div>
<button onClick={handleStateChange}>์ํ ๋ณ๊ฒฝ ์บก์ฒ</button>
<button onClick={handleError}>์๋ฌ ์บก์ฒ</button>
<button onClick={timeMachine.reconnect}>์๋ ์ฌ์ฐ๊ฒฐ</button>
</div>
</div>
);
}
```
## API
### `useDebugTimeMachine(config?)`
Debug Time Machine ์๋ฒ์ ์ฐ๊ฒฐํ๊ณ ์ด๋ฒคํธ ์บก์ฒ๋ฅผ ์๋์ผ๋ก ์ค์ ํ๋ React Hook์
๋๋ค.
#### Parameters
- `config?`: `DebugTimeMachineConfig` - ์ต์
์ค์ ๊ฐ์ฒด
#### Returns
`DebugTimeMachineHookReturn` ๊ฐ์ฒด:
- `isConnected: boolean` - ์๋ฒ ์ฐ๊ฒฐ ์ํ
- `clientId: string | null` - ์๋ฒ์์ ํ ๋น๋ฐ์ ํด๋ผ์ด์ธํธ ID
- `reconnect: () => void` - ์๋ ์ฌ์ฐ๊ฒฐ ํจ์
- `sendMessage: (type: string, data: any) => boolean` - ์ปค์คํ
๋ฉ์์ง ์ ์ก
- `captureError: (error: Error, errorInfo?: any) => void` - ์๋ ์๋ฌ ์บก์ฒ
- `captureStateChange: (componentName: string, prevState: any, newState: any, props?: any) => void` - ์๋ ์ํ ๋ณ๊ฒฝ ์บก์ฒ
- `connectionInfo` - ์ฐ๊ฒฐ ์ ๋ณด ๊ฐ์ฒด
### Configuration
#### `DebugTimeMachineConfig`
```typescript
interface DebugTimeMachineConfig {
websocketUrl?: string; // ๊ธฐ๋ณธ๊ฐ: 'ws://localhost:3001/ws'
debugMode?: boolean; // ๊ธฐ๋ณธ๊ฐ: development ํ๊ฒฝ์์ true
captureUserActions?: boolean; // ๊ธฐ๋ณธ๊ฐ: true
captureErrors?: boolean; // ๊ธฐ๋ณธ๊ฐ: true
captureStateChanges?: boolean; // ๊ธฐ๋ณธ๊ฐ: true
maxReconnectAttempts?: number; // ๊ธฐ๋ณธ๊ฐ: 10
reconnectInterval?: number; // ๊ธฐ๋ณธ๊ฐ: 5000 (ms)
developmentOnly?: boolean; // ๊ธฐ๋ณธ๊ฐ: true
}
```
## ์๋ ์บก์ฒ ๊ธฐ๋ฅ
### ์ฌ์ฉ์ ์ํธ์์ฉ ์บก์ฒ
๋ค์ ์ด๋ฒคํธ๋ค์ด ์๋์ผ๋ก ์บก์ฒ๋ฉ๋๋ค:
- ํด๋ฆญ (`click`)
- ์
๋ ฅ (`input`, `change`)
- ํผ ์ ์ถ (`submit`)
- ํค๋ณด๋ ์
๋ ฅ (`keydown`)
- ํฌ์ปค์ค ๋ณ๊ฒฝ (`focus`, `blur`)
### ์๋ฌ ์บก์ฒ
๋ค์ ์๋ฌ๋ค์ด ์๋์ผ๋ก ์บก์ฒ๋ฉ๋๋ค:
- JavaScript ๋ฐํ์ ์๋ฌ
- Promise rejection
- Console.error ํธ์ถ
### ํ๊ฒฝ๋ณ ๋์
- **Development**: ๋ชจ๋ ๊ธฐ๋ฅ ํ์ฑํ, ์ฝ์ ๋ก๊ทธ ์ถ๋ ฅ
- **Production**: `developmentOnly: true`์ธ ๊ฒฝ์ฐ ์๋ ๋นํ์ฑํ
## ์๋ฒ ์ค์
Debug Time Machine ๋ฐฑ์๋ ์๋ฒ๊ฐ ์คํ๋์ด ์์ด์ผ ํฉ๋๋ค:
```bash
cd apps/backend
npm run dev
```
์๋ฒ๋ ๊ธฐ๋ณธ์ ์ผ๋ก `http://localhost:3001`์์ ์คํ๋๋ฉฐ, WebSocket์ `/ws` ๊ฒฝ๋ก์์ ์ฐ๊ฒฐ๋ฉ๋๋ค.
## TypeScript ์ง์
์ด ํจํค์ง๋ ์์ ํ TypeScript ์ง์์ ์ ๊ณตํฉ๋๋ค. ๋ชจ๋ ํ์
์ด ํฌํจ๋์ด ์์ด IDE์์ ์๋์์ฑ๊ณผ ํ์
๊ฒ์ฌ๋ฅผ ๋ฐ์ ์ ์์ต๋๋ค.
## ๋ผ์ด์ ์ค
MIT License