forked from mui/mui-x
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] Move away for the event system to trigger pipe processings (mu…
- Loading branch information
1 parent
148ab4f
commit 272f0ec
Showing
11 changed files
with
173 additions
and
90 deletions.
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
1 change: 1 addition & 0 deletions
1
packages/grid/x-data-grid/src/hooks/core/pipeProcessing/index.ts
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,3 +1,4 @@ | ||
export * from './gridPipeProcessingApi'; | ||
export * from './useGridPipeProcessing'; | ||
export * from './useGridRegisterPipeProcessor'; | ||
export * from './useGridRegisterPipeApplier'; |
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
40 changes: 40 additions & 0 deletions
40
packages/grid/x-data-grid/src/hooks/core/pipeProcessing/useGridRegisterPipeApplier.ts
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import * as React from 'react'; | ||
import { useFirstRender } from '../../utils/useFirstRender'; | ||
import { GridApiCommon } from '../../../models/api/gridApiCommon'; | ||
import { GridPipeProcessorGroup } from './gridPipeProcessingApi'; | ||
|
||
export const useGridRegisterPipeApplier = < | ||
Api extends GridApiCommon, | ||
G extends GridPipeProcessorGroup, | ||
>( | ||
apiRef: React.MutableRefObject<Api>, | ||
group: G, | ||
callback: () => void, | ||
) => { | ||
const cleanup = React.useRef<(() => void) | null>(); | ||
const id = React.useRef(`mui-${Math.round(Math.random() * 1e9)}`); | ||
|
||
const registerPreProcessor = React.useCallback(() => { | ||
cleanup.current = apiRef.current.unstable_registerPipeApplier(group, id.current, callback); | ||
}, [apiRef, callback, group]); | ||
|
||
useFirstRender(() => { | ||
registerPreProcessor(); | ||
}); | ||
|
||
const isFirstRender = React.useRef(true); | ||
React.useEffect(() => { | ||
if (isFirstRender.current) { | ||
isFirstRender.current = false; | ||
} else { | ||
registerPreProcessor(); | ||
} | ||
|
||
return () => { | ||
if (cleanup.current) { | ||
cleanup.current(); | ||
cleanup.current = null; | ||
} | ||
}; | ||
}, [registerPreProcessor]); | ||
}; |
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
Oops, something went wrong.