Skip to content

Commit

Permalink
fix: but rAF scheduling behind flag
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed May 29, 2022
1 parent 1a897b0 commit 08ba7d9
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ import { interpret } from 'xstate'
export interface BottomSheetMachineProps {
initialHeight?: number | GetInitialHeight
snapPoints?: GetSnapPoints
unstable__requestAnimationFrame?: boolean
}

function createStore({
initialHeight = defaultInitialHeight,
snapPoints = defaultSnapPoints,
unstable__requestAnimationFrame = false,
}: BottomSheetMachineProps = {}) {
console.debug('createStore')
const service = interpret(
Expand Down Expand Up @@ -51,15 +53,16 @@ function createStore({
transient = state
console.log('transient', state.value, state.context)
if (state.changed) {
cancelAnimationFrame(rAF)
rAF = requestAnimationFrame(() => {
console.group('onStoreChange')
console.log({ value: state.value, context: state.context })
transient = snapshot = state
onStoreChange()
console.groupEnd()
})
console.groupEnd()
if (unstable__requestAnimationFrame) {
cancelAnimationFrame(rAF)
rAF = requestAnimationFrame(() => {
console.group('onStoreChange')
console.log({ value: state.value, context: state.context })
transient = snapshot = state
onStoreChange()
console.groupEnd()
})
} else onStoreChange()
}
console.groupEnd()
})
Expand Down

0 comments on commit 08ba7d9

Please sign in to comment.