/* Types */ export type FocusState = { id: string | null; treeFocused: boolean }; /* Actions */ export function focus(id: string | null) { return { type: "FOCUS" as const, id }; } export function treeBlur() { return { type: "TREE_BLUR" } as const; } /* Reducer */ export function reducer( state: FocusState = { id: null, treeFocused: false }, action: ReturnType | ReturnType ) { if (action.type === "FOCUS") { return { ...state, id: action.id, treeFocused: true }; } else if (action.type === "TREE_BLUR") { return { ...state, treeFocused: false }; } else { return state; } }