File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change 1+ import raf from 'rc-util/lib/raf' ;
2+
3+ export default function channelUpdate ( callback : VoidFunction ) {
4+ if ( typeof MessageChannel === 'undefined' ) {
5+ raf ( callback ) ;
6+ } else {
7+ const channel = new MessageChannel ( ) ;
8+ channel . port1 . onmessage = ( ) => callback ( ) ;
9+ channel . port2 . postMessage ( undefined ) ;
10+ }
11+ }
Original file line number Diff line number Diff line change 11import useEvent from 'rc-util/lib/hooks/useEvent' ;
22import * as React from 'react' ;
33import { unstable_batchedUpdates } from 'react-dom' ;
4+ import channelUpdate from './channelUpdate' ;
45
56type Updater < T > = T | ( ( origin : T ) => T ) ;
67
@@ -20,16 +21,14 @@ export function useBatcher() {
2021 if ( ! updateFuncRef . current ) {
2122 updateFuncRef . current = [ ] ;
2223
23- const channel = new MessageChannel ( ) ;
24- channel . port1 . onmessage = ( ) => {
24+ channelUpdate ( ( ) => {
2525 unstable_batchedUpdates ( ( ) => {
2626 updateFuncRef . current . forEach ( fn => {
2727 fn ( ) ;
2828 } ) ;
2929 updateFuncRef . current = null ;
3030 } ) ;
31- } ;
32- channel . port2 . postMessage ( undefined ) ;
31+ } ) ;
3332 }
3433
3534 updateFuncRef . current . push ( callback ) ;
You can’t perform that action at this time.
0 commit comments