import { useContext, useCallback, } from 'react';
import { useStore } from '../use-store';
import { CommandScopeContext } from '../../providers';
export const useCommander = () => {
    const scope = useContext(CommandScopeContext);
    const store = useStore();
    const dispatch = useCallback((commandOrThunkFn) => {
        if (typeof commandOrThunkFn === 'function') {
            commandOrThunkFn(dispatch, (path) => store.get(path));
            return;
        }
        store.dispatch(Object.assign({ scope }, commandOrThunkFn));
    }, [scope, store]);
    return { dispatch };
};
