Skip to content

Commit

Permalink
Fixed generic selector types
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Apr 3, 2023
1 parent e22e68d commit bc48e7b
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions packages/redux/src/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RootState, Storage, WorkspaceSettings } from './store';
import type { RootState } from './store';

const EMPTY_OBJECT = Object.freeze({});

Expand Down Expand Up @@ -34,80 +34,82 @@ export const getFileStorage = <State extends RootState = RootState>(

export const getWorkspaceStorage = <State extends RootState = RootState>(
store: State
): Storage['workspaceStorage'] => getStorage(store).workspaceStorage;
): State['storage']['workspaceStorage'] => getStorage(store).workspaceStorage;

// Workspace
export const getWorkspace = <State extends RootState = RootState>(
store: State
): RootState['workspace'] => store.workspace;
): State['workspace'] => store.workspace;

// Settings
type Settings<
State extends RootState = RootState
> = State['workspace']['data']['settings'];

export const getSettings = <State extends RootState = RootState>(
store: State
): RootState['workspace']['data']['settings'] =>
getWorkspace(store).data.settings;
): Settings<State> => getWorkspace(store).data.settings;

export const getDefaultDateTimeFormat = <State extends RootState = RootState>(
store: State
): WorkspaceSettings['defaultDateTimeFormat'] =>
): Settings<State>['defaultDateTimeFormat'] =>
getSettings(store).defaultDateTimeFormat;

export const getDefaultDecimalFormatOptions = <
State extends RootState = RootState
>(
store: State
): WorkspaceSettings['defaultDecimalFormatOptions'] =>
): Settings<State>['defaultDecimalFormatOptions'] =>
getSettings(store).defaultDecimalFormatOptions ?? EMPTY_OBJECT;

export const getDefaultIntegerFormatOptions = <
State extends RootState = RootState
>(
store: State
): WorkspaceSettings['defaultIntegerFormatOptions'] =>
): Settings<State>['defaultIntegerFormatOptions'] =>
getSettings(store).defaultIntegerFormatOptions ?? EMPTY_OBJECT;

export const getFormatter = <State extends RootState = RootState>(
store: State
): WorkspaceSettings['formatter'] => getSettings(store).formatter;
): Settings<State>['formatter'] => getSettings(store).formatter;

export const getTimeZone = <State extends RootState = RootState>(
store: State
): WorkspaceSettings['timeZone'] => getSettings(store).timeZone;
): Settings<State>['timeZone'] => getSettings(store).timeZone;

export const getShowTimeZone = <State extends RootState = RootState>(
store: State
): WorkspaceSettings['showTimeZone'] => getSettings(store).showTimeZone;
): Settings<State>['showTimeZone'] => getSettings(store).showTimeZone;

export const getShowTSeparator = <State extends RootState = RootState>(
store: State
): WorkspaceSettings['showTSeparator'] => getSettings(store).showTSeparator;
): Settings<State>['showTSeparator'] => getSettings(store).showTSeparator;

export const getTruncateNumbersWithPound = <
State extends RootState = RootState
>(
store: State
): WorkspaceSettings['truncateNumbersWithPound'] =>
): Settings<State>['truncateNumbersWithPound'] =>
getSettings(store).truncateNumbersWithPound;

export const getDisableMoveConfirmation = <State extends RootState = RootState>(
store: State
): WorkspaceSettings['disableMoveConfirmation'] =>
): Settings<State>['disableMoveConfirmation'] =>
getSettings(store).disableMoveConfirmation || false;

export const getShortcutOverrides = <State extends RootState = RootState>(
store: State
): WorkspaceSettings['shortcutOverrides'] =>
getSettings(store).shortcutOverrides;
): Settings<State>['shortcutOverrides'] => getSettings(store).shortcutOverrides;

export const getDefaultNotebookSettings = <State extends RootState = RootState>(
store: State
): WorkspaceSettings['defaultNotebookSettings'] =>
): Settings<State>['defaultNotebookSettings'] =>
getSettings(store).defaultNotebookSettings ?? EMPTY_OBJECT;

export const getActiveTool = <State extends RootState = RootState>(
store: State
): RootState['activeTool'] => store.activeTool;
): State['activeTool'] => store.activeTool;

export const getPlugins = <State extends RootState = RootState>(
store: State
): RootState['plugins'] => store.plugins ?? EMPTY_MAP;
): State['plugins'] => store.plugins ?? EMPTY_MAP;

0 comments on commit bc48e7b

Please sign in to comment.