-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: TypeScript Type Improvements #1056
Merged
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
15d709b
chunk1
Zhou-Ziheng d1fa63a
updated selectors with generic types
Zhou-Ziheng b0313c9
removed a few cast
Zhou-Ziheng c0b72a8
Merge remote-tracking branch 'origin/main' into type-improvements
Zhou-Ziheng a746253
type mismatch
Zhou-Ziheng 5f51b82
requeted changes
Zhou-Ziheng 77dd82f
removed formattingRule cast
Zhou-Ziheng 51ad5c5
made FOrmatterItem type better
Zhou-Ziheng 6e5f643
Merge remote-tracking branch 'origin/main' into type-improvements
Zhou-Ziheng 818a8ae
fake
Zhou-Ziheng b958c9d
removed fake
Zhou-Ziheng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
import { RootState, ServerConfigValues } from '@deephaven/redux'; | ||
import { RootState } from '@deephaven/redux'; | ||
import LayoutStorage from '../storage/LayoutStorage'; | ||
|
||
/** | ||
* Get the layout storage used by the app | ||
* @param store The redux store | ||
* @returns The layout storage instance | ||
*/ | ||
export const getLayoutStorage = (store: RootState): LayoutStorage => | ||
store.layoutStorage as LayoutStorage; | ||
export const getLayoutStorage = <State extends RootState = RootState>( | ||
store: State | ||
): LayoutStorage => store.layoutStorage as LayoutStorage; | ||
|
||
/** | ||
* Get the configuration values of the server | ||
* @param store The redux store | ||
* @returns The layout storage instance | ||
*/ | ||
export const getServerConfigValues = (store: RootState): ServerConfigValues => | ||
store.serverConfigValues; | ||
export const getServerConfigValues = <State extends RootState = RootState>( | ||
store: State | ||
): State['serverConfigValues'] => store.serverConfigValues; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,113 @@ | ||
import type { | ||
RootState, | ||
User, | ||
Storage, | ||
Workspace, | ||
WorkspaceSettings, | ||
} from './store'; | ||
import type { RootState, Storage, WorkspaceSettings } from './store'; | ||
|
||
const EMPTY_OBJECT = Object.freeze({}); | ||
|
||
const EMPTY_MAP: ReadonlyMap<unknown, unknown> = new Map(); | ||
|
||
type Selector<R> = (state: RootState) => R; | ||
|
||
export type Selector<State extends RootState, R> = (store: State) => R; | ||
// User | ||
export const getUser: Selector<User> = store => store.user; | ||
export const getUser = <State extends RootState = RootState>( | ||
store: State | ||
): State['user'] => store.user; | ||
|
||
export const getUserName: Selector<User['name']> = store => getUser(store).name; | ||
export const getUserName = <State extends RootState = RootState>( | ||
store: State | ||
): State['user']['name'] => getUser(store).name; | ||
|
||
export const getUserGroups: Selector<User['groups']> = store => | ||
getUser(store).groups; | ||
export const getUserGroups = <State extends RootState = RootState>( | ||
store: State | ||
): State['user']['groups'] => getUser(store).groups; | ||
|
||
// Storage | ||
export const getStorage: Selector<Storage> = store => store.storage; | ||
export const getStorage = <State extends RootState = RootState>( | ||
store: State | ||
): State['storage'] => store.storage; | ||
|
||
export const getCommandHistoryStorage: Selector< | ||
Storage['commandHistoryStorage'] | ||
> = store => getStorage(store).commandHistoryStorage; | ||
export const getCommandHistoryStorage = <State extends RootState = RootState>( | ||
store: State | ||
): State['storage']['commandHistoryStorage'] => | ||
getStorage(store).commandHistoryStorage; | ||
|
||
export const getFileStorage: Selector<Storage['fileStorage']> = store => | ||
getStorage(store).fileStorage; | ||
export const getFileStorage = <State extends RootState = RootState>( | ||
store: State | ||
): State['storage']['fileStorage'] => getStorage(store).fileStorage; | ||
|
||
export const getWorkspaceStorage: Selector< | ||
Storage['workspaceStorage'] | ||
> = store => getStorage(store).workspaceStorage; | ||
export const getWorkspaceStorage = <State extends RootState = RootState>( | ||
store: State | ||
): Storage['workspaceStorage'] => getStorage(store).workspaceStorage; | ||
|
||
// Workspace | ||
export const getWorkspace: Selector<Workspace> = store => store.workspace; | ||
export const getWorkspace = <State extends RootState = RootState>( | ||
store: State | ||
): RootState['workspace'] => store.workspace; | ||
|
||
// Settings | ||
export const getSettings: Selector<WorkspaceSettings> = store => | ||
export const getSettings = <State extends RootState = RootState>( | ||
store: State | ||
): RootState['workspace']['data']['settings'] => | ||
getWorkspace(store).data.settings; | ||
|
||
export const getDefaultDateTimeFormat: Selector< | ||
WorkspaceSettings['defaultDateTimeFormat'] | ||
> = store => getSettings(store).defaultDateTimeFormat; | ||
|
||
export const getDefaultDecimalFormatOptions: Selector< | ||
WorkspaceSettings['defaultDecimalFormatOptions'] | ||
> = store => getSettings(store).defaultDecimalFormatOptions ?? EMPTY_OBJECT; | ||
|
||
export const getDefaultIntegerFormatOptions: Selector< | ||
WorkspaceSettings['defaultIntegerFormatOptions'] | ||
> = store => getSettings(store).defaultIntegerFormatOptions ?? EMPTY_OBJECT; | ||
|
||
export const getFormatter: Selector<WorkspaceSettings['formatter']> = store => | ||
getSettings(store).formatter; | ||
|
||
export const getTimeZone: Selector<WorkspaceSettings['timeZone']> = store => | ||
getSettings(store).timeZone; | ||
|
||
export const getShowTimeZone: Selector< | ||
WorkspaceSettings['showTimeZone'] | ||
> = store => getSettings(store).showTimeZone; | ||
|
||
export const getShowTSeparator: Selector< | ||
WorkspaceSettings['showTSeparator'] | ||
> = store => getSettings(store).showTSeparator; | ||
|
||
export const getTruncateNumbersWithPound: Selector< | ||
WorkspaceSettings['truncateNumbersWithPound'] | ||
> = store => getSettings(store).truncateNumbersWithPound; | ||
|
||
export const getDisableMoveConfirmation: Selector< | ||
WorkspaceSettings['disableMoveConfirmation'] | ||
> = store => getSettings(store).disableMoveConfirmation || false; | ||
|
||
export const getShortcutOverrides: Selector< | ||
WorkspaceSettings['shortcutOverrides'] | ||
> = store => getSettings(store).shortcutOverrides; | ||
|
||
export const getDefaultNotebookSettings: Selector< | ||
WorkspaceSettings['defaultNotebookSettings'] | ||
> = store => getSettings(store).defaultNotebookSettings ?? EMPTY_OBJECT; | ||
|
||
export const getActiveTool: Selector<RootState['activeTool']> = store => | ||
store.activeTool; | ||
|
||
export const getPlugins: Selector<RootState['plugins']> = store => | ||
store.plugins ?? EMPTY_MAP; | ||
export const getDefaultDateTimeFormat = <State extends RootState = RootState>( | ||
store: State | ||
): WorkspaceSettings['defaultDateTimeFormat'] => | ||
getSettings(store).defaultDateTimeFormat; | ||
|
||
export const getDefaultDecimalFormatOptions = < | ||
State extends RootState = RootState | ||
>( | ||
store: State | ||
): WorkspaceSettings['defaultDecimalFormatOptions'] => | ||
getSettings(store).defaultDecimalFormatOptions ?? EMPTY_OBJECT; | ||
|
||
export const getDefaultIntegerFormatOptions = < | ||
State extends RootState = RootState | ||
>( | ||
store: State | ||
): WorkspaceSettings['defaultIntegerFormatOptions'] => | ||
getSettings(store).defaultIntegerFormatOptions ?? EMPTY_OBJECT; | ||
|
||
export const getFormatter = <State extends RootState = RootState>( | ||
store: State | ||
): WorkspaceSettings['formatter'] => getSettings(store).formatter; | ||
|
||
export const getTimeZone = <State extends RootState = RootState>( | ||
store: State | ||
): WorkspaceSettings['timeZone'] => getSettings(store).timeZone; | ||
|
||
export const getShowTimeZone = <State extends RootState = RootState>( | ||
store: State | ||
): WorkspaceSettings['showTimeZone'] => getSettings(store).showTimeZone; | ||
|
||
export const getShowTSeparator = <State extends RootState = RootState>( | ||
store: State | ||
): WorkspaceSettings['showTSeparator'] => getSettings(store).showTSeparator; | ||
|
||
export const getTruncateNumbersWithPound = < | ||
State extends RootState = RootState | ||
>( | ||
store: State | ||
): WorkspaceSettings['truncateNumbersWithPound'] => | ||
getSettings(store).truncateNumbersWithPound; | ||
|
||
export const getDisableMoveConfirmation = <State extends RootState = RootState>( | ||
store: State | ||
): WorkspaceSettings['disableMoveConfirmation'] => | ||
getSettings(store).disableMoveConfirmation || false; | ||
|
||
export const getShortcutOverrides = <State extends RootState = RootState>( | ||
store: State | ||
): WorkspaceSettings['shortcutOverrides'] => | ||
getSettings(store).shortcutOverrides; | ||
|
||
export const getDefaultNotebookSettings = <State extends RootState = RootState>( | ||
store: State | ||
): WorkspaceSettings['defaultNotebookSettings'] => | ||
getSettings(store).defaultNotebookSettings ?? EMPTY_OBJECT; | ||
|
||
export const getActiveTool = <State extends RootState = RootState>( | ||
store: State | ||
): RootState['activeTool'] => store.activeTool; | ||
|
||
export const getPlugins = <State extends RootState = RootState>( | ||
store: State | ||
): RootState['plugins'] => store.plugins ?? EMPTY_MAP; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think would be cleaner to do
Partial<TableColumnFormat>