-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: table use sticky for fixed column
- Loading branch information
1 parent
4fed700
commit 38569c2
Showing
18 changed files
with
613 additions
and
235 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { Ref } from 'vue'; | ||
import { onBeforeUnmount, ref } from 'vue'; | ||
import wrapperRaf from '../raf'; | ||
|
||
export type Updater<State> = (prev: State) => State; | ||
/** | ||
* Execute code before next frame but async | ||
*/ | ||
export function useLayoutState<State>( | ||
defaultState: State, | ||
): [Ref<State>, (updater: Updater<State>) => void] { | ||
const stateRef = ref(defaultState); | ||
let tempState = stateRef.value; | ||
|
||
let updateBatchRef = []; | ||
const rafRef = ref(); | ||
function setFrameState(updater: Updater<State>) { | ||
wrapperRaf.cancel(rafRef.value); | ||
updateBatchRef.push(updater); | ||
|
||
rafRef.value = wrapperRaf(() => { | ||
const prevBatch = updateBatchRef; | ||
// const prevState = stateRef.value; | ||
updateBatchRef = []; | ||
|
||
prevBatch.forEach(batchUpdater => { | ||
tempState = batchUpdater(tempState); | ||
}); | ||
|
||
// if (tempState !== stateRef.value) { | ||
stateRef.value = tempState; | ||
// } | ||
}); | ||
} | ||
|
||
onBeforeUnmount(() => { | ||
wrapperRaf.cancel(rafRef.value); | ||
}); | ||
|
||
return [stateRef as Ref<State>, setFrameState]; | ||
} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.