25 lines
633 B
TypeScript
25 lines
633 B
TypeScript
import { create } from 'zustand'
|
|
|
|
/**
|
|
* 轻量 auto-save 状态 store
|
|
*
|
|
* 解耦 useAutoSave hook 与状态栏组件——状态栏的 auto-save 项通过
|
|
* 本 store 读取状态,无需在 render 函数中重复调用 useAutoSave()。
|
|
* useAutoSave hook 负责写入本 store。
|
|
*/
|
|
|
|
interface AutoSaveState {
|
|
isAutoSaving: boolean
|
|
autoSaveEnabled: boolean
|
|
}
|
|
|
|
interface AutoSaveStore extends AutoSaveState {
|
|
setState: (partial: Partial<AutoSaveState>) => void
|
|
}
|
|
|
|
export const useAutoSaveStore = create<AutoSaveStore>((set) => ({
|
|
isAutoSaving: false,
|
|
autoSaveEnabled: true,
|
|
setState: (partial) => set(partial)
|
|
}))
|