Skip to content

Commit 08ba7d9

Browse files
committed
fix: but rAF scheduling behind flag
1 parent 1a897b0 commit 08ba7d9

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/index.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ import { interpret } from 'xstate'
1616
export interface BottomSheetMachineProps {
1717
initialHeight?: number | GetInitialHeight
1818
snapPoints?: GetSnapPoints
19+
unstable__requestAnimationFrame?: boolean
1920
}
2021

2122
function createStore({
2223
initialHeight = defaultInitialHeight,
2324
snapPoints = defaultSnapPoints,
25+
unstable__requestAnimationFrame = false,
2426
}: BottomSheetMachineProps = {}) {
2527
console.debug('createStore')
2628
const service = interpret(
@@ -51,15 +53,16 @@ function createStore({
5153
transient = state
5254
console.log('transient', state.value, state.context)
5355
if (state.changed) {
54-
cancelAnimationFrame(rAF)
55-
rAF = requestAnimationFrame(() => {
56-
console.group('onStoreChange')
57-
console.log({ value: state.value, context: state.context })
58-
transient = snapshot = state
59-
onStoreChange()
60-
console.groupEnd()
61-
})
62-
console.groupEnd()
56+
if (unstable__requestAnimationFrame) {
57+
cancelAnimationFrame(rAF)
58+
rAF = requestAnimationFrame(() => {
59+
console.group('onStoreChange')
60+
console.log({ value: state.value, context: state.context })
61+
transient = snapshot = state
62+
onStoreChange()
63+
console.groupEnd()
64+
})
65+
} else onStoreChange()
6366
}
6467
console.groupEnd()
6568
})

0 commit comments

Comments
 (0)