Better plugin order api

This commit is contained in:
Tanner Linsley
2020-02-15 20:00:42 -07:00
parent b161d6d47b
commit 917cfcc910
12 changed files with 36 additions and 44 deletions
+7 -7
View File
@@ -1,20 +1,20 @@
{
"dist/index.js": {
"bundled": 131178,
"minified": 61448,
"gzipped": 15699
"bundled": 130976,
"minified": 61378,
"gzipped": 15745
},
"dist/index.es.js": {
"bundled": 130236,
"minified": 60607,
"gzipped": 15525,
"bundled": 130034,
"minified": 60537,
"gzipped": 15571,
"treeshaked": {
"rollup": {
"code": 80,
"import_statements": 21
},
"webpack": {
"code": 8457
"code": 7611
}
}
},
+1
View File
@@ -307,6 +307,7 @@ function Table({ columns, data, updateMyData, skipReset }) {
// when we edit the data.
autoResetPage: !skipReset,
autoResetSelectedRows: !skipReset,
disableMultiSort: true,
},
useFilters,
useGroupBy,
@@ -227,10 +227,7 @@ function useInstance(instance) {
defaultCanPivot,
} = instance
ensurePluginOrder(plugins, ['useGroupBy'], 'usePivotColumns', [
'useSortBy',
'useExpanded',
])
ensurePluginOrder(plugins, ['useGroupBy'], 'usePivotColumns')
const getInstance = useGetLatest(instance)
-9
View File
@@ -1,5 +1,3 @@
import { ensurePluginOrder } from '../publicUtils'
const cellStyles = {
position: 'absolute',
top: 0,
@@ -9,7 +7,6 @@ export const useAbsoluteLayout = hooks => {
hooks.getTableBodyProps.push(getRowStyles)
hooks.getRowProps.push(getRowStyles)
hooks.getHeaderGroupProps.push(getRowStyles)
hooks.useInstance.push(useInstance)
hooks.getHeaderProps.push((props, { column }) => [
props,
@@ -45,9 +42,3 @@ const getRowStyles = (props, { instance }) => [
},
},
]
function useInstance({ plugins }) {
ensurePluginOrder(plugins, [], useAbsoluteLayout.pluginName, [
'useResizeColumns',
])
}
+8
View File
@@ -7,6 +7,7 @@ import {
actions,
useMountedLayoutEffect,
makePropGetter,
ensurePluginOrder,
} from '../publicUtils'
// Actions
@@ -128,10 +129,17 @@ function useInstance(instance) {
expandSubRows = true,
autoResetExpanded = true,
getHooks,
plugins,
state: { expanded },
dispatch,
} = instance
ensurePluginOrder(
plugins,
['useSortBy', 'useGroupBy', 'usePivotColumns', 'useGlobalFilter'],
'useExpanded'
)
const getAutoResetExpanded = useGetLatest(autoResetExpanded)
let isAllRowsExpanded = Boolean(
-7
View File
@@ -6,7 +6,6 @@ import {
actions,
useMountedLayoutEffect,
functionalUpdate,
ensurePluginOrder,
useGetLatest,
} from '../publicUtils'
@@ -69,14 +68,8 @@ function useInstance(instance) {
state: { globalFilter: globalFilterValue },
dispatch,
autoResetGlobalFilter = true,
plugins,
} = instance
ensurePluginOrder(plugins, [], 'useGlobalFilter', [
'useSortBy',
'useExpanded',
])
const setGlobalFilter = React.useCallback(
filterValue => {
dispatch({ type: actions.setGlobalFilter, filterValue })
+1 -1
View File
@@ -137,7 +137,7 @@ function useInstance(instance) {
getHooks,
} = instance
ensurePluginOrder(plugins, [], 'useGroupBy', ['useSortBy', 'useExpanded'])
ensurePluginOrder(plugins, ['useFilters'], 'useGroupBy')
const getInstance = useGetLatest(instance)
+1 -2
View File
@@ -98,8 +98,7 @@ function useInstance(instance) {
ensurePluginOrder(
plugins,
['useGlobalFilter', 'useFilters', 'useGroupBy', 'useSortBy', 'useExpanded'],
'usePagination',
[]
'usePagination'
)
const getAutoResetPage = useGetLatest(autoResetPage)
+6
View File
@@ -3,6 +3,7 @@ import {
defaultColumn,
makePropGetter,
useGetLatest,
ensurePluginOrder,
} from '../publicUtils'
import { getFirstDefined } from '../utils'
@@ -23,6 +24,7 @@ export const useResizeColumns = hooks => {
},
})
hooks.stateReducers.push(reducer)
hooks.useInstance.push(useInstance)
hooks.useInstanceBeforeDimensions.push(useInstanceBeforeDimensions)
}
@@ -220,6 +222,10 @@ const useInstanceBeforeDimensions = instance => {
})
}
function useInstance({ plugins }) {
ensurePluginOrder(plugins, ['useAbsoluteLayout'], 'useResizeColumns')
}
function getLeafHeaders(header) {
const leafHeaders = []
const recurseHeader = header => {
+1 -2
View File
@@ -174,8 +174,7 @@ function useInstance(instance) {
ensurePluginOrder(
plugins,
['useFilters', 'useGroupBy', 'useSortBy'],
'useRowSelect',
[]
'useRowSelect'
)
const selectedFlatRows = React.useMemo(() => {
+5 -1
View File
@@ -195,7 +195,11 @@ function useInstance(instance) {
autoResetSortBy = true,
} = instance
ensurePluginOrder(plugins, ['useFilters'], 'useSortBy', ['useExpanded'])
ensurePluginOrder(
plugins,
['useFilters', 'useGlobalFilter', 'useGroupBy', 'usePivotColumns'],
'useSortBy'
)
// Updates sorting based on a columnId, desc flag and multi flag
const toggleSortBy = React.useCallback(
+5 -11
View File
@@ -122,6 +122,11 @@ export const loopHooks = (hooks, context, meta = {}) =>
})
export function ensurePluginOrder(plugins, befores, pluginName, afters) {
if (process.env.NODE_ENV !== 'production' && afters) {
throw new Error(
`Defining plugins in the "after" section of ensurePluginOrder is no longer supported (see plugin ${pluginName})`
)
}
const pluginIndex = plugins.findIndex(
plugin => plugin.pluginName === pluginName
)
@@ -148,17 +153,6 @@ This usually means you need to need to name your plugin hook by setting the 'plu
}
}
})
afters.forEach(after => {
const afterIndex = plugins.findIndex(plugin => plugin.pluginName === after)
if (process.env.NODE_ENV !== 'production') {
if (afterIndex > -1 && afterIndex < pluginIndex) {
throw new Error(
`React Table: The ${pluginName} plugin hook must be placed before the ${after} plugin hook!`
)
}
}
})
}
export function functionalUpdate(updater, old) {