Refactor useToast hook into modules
The useToast hook was refactored into smaller, more manageable modules.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
|
||||
import * as React from "react"
|
||||
import { Toast, ToasterToast } from "./types"
|
||||
import { Toast, ToasterToast, State } from "./types"
|
||||
import { actionTypes } from "./types"
|
||||
import { listeners, memoryState } from "./store"
|
||||
import { genId, dispatch } from "./toastManager"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
import { TOAST_REMOVE_DELAY } from './constants'
|
||||
import { TOAST_REMOVE_DELAY, TOAST_LIMIT } from './constants'
|
||||
import { Action, State, actionTypes } from './types'
|
||||
import { dispatch } from './toastManager'
|
||||
|
||||
// 토스트 타임아웃 맵
|
||||
export const toastTimeouts = new Map<string, ReturnType<typeof setTimeout>>()
|
||||
|
||||
@@ -3,7 +3,6 @@ import { State } from './types'
|
||||
|
||||
// 전역 상태 및 리스너
|
||||
export const listeners: Array<(state: State) => void> = []
|
||||
export let memoryState: State = { toasts: [] }
|
||||
|
||||
// 마지막 액션 추적 (중복 방지용)
|
||||
export let lastAction: { type: string; id?: string; time: number } | null = null
|
||||
// memoryState와 lastAction은 toastManager.ts에서 관리
|
||||
export { memoryState } from './toastManager';
|
||||
|
||||
@@ -2,7 +2,11 @@
|
||||
import { Action, actionTypes } from './types'
|
||||
import { TOAST_LIMIT } from './constants'
|
||||
import { reducer } from './reducer'
|
||||
import { listeners, memoryState, lastAction } from './store'
|
||||
import { listeners } from './store'
|
||||
|
||||
// 전역 상태 관리
|
||||
let memoryState = { toasts: [] };
|
||||
let lastAction = null;
|
||||
|
||||
// ID 생성기
|
||||
let count = 0
|
||||
@@ -49,3 +53,5 @@ export function dispatch(action: Action) {
|
||||
listener(memoryState)
|
||||
})
|
||||
}
|
||||
|
||||
export { memoryState };
|
||||
|
||||
Reference in New Issue
Block a user