-
Notifications
You must be signed in to change notification settings - Fork 8
[refactor] use contexts with no intermediate hooks, and move logic to providers #463
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
+179
−167
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6648af0
[refactor] use contexts with no intermediate hooks, and move logic to…
severo 26694f9
add a test about data frame methods
severo b2dfdb4
[refactor] rename DataContext to the ugly but explicit DataFrameMetho…
severo 88b8573
add a test to show that methods can be updated later
severo 7fd6a0b
fix mock function
severo 27a2a6e
don't hardcode the default row height
severo 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,47 +1,18 @@ | ||
| import { createContext, useContext } from 'react' | ||
| import { createContext } from 'react' | ||
|
|
||
| import type { ColumnDescriptor, DataFrame } from '../helpers/dataframe/types.js' | ||
|
|
||
| export type DataFrameMethods = Pick<DataFrame, 'getRowNumber' | 'getCell' | 'fetch'> | ||
| export type DataFrameWithoutMethods = Omit<DataFrame, 'getRowNumber' | 'getCell' | 'fetch'> | ||
|
|
||
| export const DataKeyContext = createContext<number>(0) | ||
| export const DataVersionContext = createContext<number>(0) | ||
| export const NumRowsContext = createContext<number>(0) | ||
| export const ColumnDescriptorsContext = createContext<Pick<ColumnDescriptor, 'name' | 'sortable'>[]>([]) | ||
| export const NumColumnsContext = createContext<number>(0) | ||
| export const ExclusiveSortContext = createContext<boolean>(false) | ||
| export const DataContext = createContext<DataFrameMethods | undefined>(undefined) | ||
|
|
||
| export const DataContext = createContext<DataFrameMethods>({ | ||
| getRowNumber: () => undefined, | ||
| getCell: () => undefined, | ||
| }) | ||
| // the data key is only used in tests | ||
| export function useDataKey() { | ||
| return useContext(DataKeyContext) | ||
| } | ||
|
|
||
| export function useDataVersion() { | ||
| return useContext(DataVersionContext) | ||
| } | ||
|
|
||
| export function useNumRows() { | ||
| return useContext(NumRowsContext) | ||
| } | ||
|
|
||
| export function useColumnDescriptors() { | ||
| return useContext(ColumnDescriptorsContext) | ||
| } | ||
|
|
||
| export function useNumColumns() { | ||
| return useContext(NumColumnsContext) | ||
| } | ||
|
|
||
| export function useExclusiveSort() { | ||
| return useContext(ExclusiveSortContext) | ||
| } | ||
|
|
||
| export function useData(): DataFrameMethods { | ||
| const data = useContext(DataContext) | ||
| if (data === undefined) { | ||
| throw new Error('useData must be used within a DataContext.Provider with a valid DataFrameMethods value') | ||
| } | ||
| return data | ||
| } | ||
| export const DataKeyContext = createContext<number>(0) | ||
This file contains hidden or 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,21 +1,10 @@ | ||
| import { createContext, useContext } from 'react' | ||
| import { createContext } from 'react' | ||
|
|
||
| import { rowHeight } from '../helpers/constants.js' | ||
|
|
||
| type SetTableCornerSizeContextType = (element: HTMLElement) => void | ||
|
|
||
| export const TableCornerHeightContext = createContext<number | undefined>(undefined) | ||
| export const defaultTableCornerHeight = rowHeight | ||
| export const TableCornerHeightContext = createContext<number>(defaultTableCornerHeight) | ||
| export const TableCornerWidthContext = createContext<number | undefined>(undefined) | ||
| export const SetTableCornerSizeContext = createContext<SetTableCornerSizeContextType | undefined>(undefined) | ||
|
|
||
| export function useTableCornerWidth() { | ||
| return useContext(TableCornerWidthContext) | ||
| } | ||
|
|
||
| export function useHeaderHeight() { | ||
| return useContext(TableCornerHeightContext) ?? rowHeight | ||
| } | ||
|
|
||
| export function useSetTableCornerSize() { | ||
| return useContext(SetTableCornerSizeContext) | ||
| } |
This file contains hidden or 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,19 +1,7 @@ | ||
| import { createContext, useContext } from 'react' | ||
| import { createContext } from 'react' | ||
|
|
||
| type SetViewportSizeContextType = (element: HTMLElement) => void | ||
|
|
||
| export const ViewportHeightContext = createContext<number | undefined>(undefined) | ||
| export const ViewportWidthContext = createContext<number | undefined>(undefined) | ||
| export const SetViewportSizeContext = createContext<SetViewportSizeContextType | undefined>(undefined) | ||
|
|
||
| export function useViewportWidth() { | ||
| return useContext(ViewportWidthContext) | ||
| } | ||
|
|
||
| export function useViewportHeight() { | ||
| return useContext(ViewportHeightContext) | ||
| } | ||
|
|
||
| export function useSetViewportSize() { | ||
| return useContext(SetViewportSizeContext) | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.