1
1
2
2
import Scuttlebutt , { filter } from 'scuttlebutt-vector'
3
3
import * as orderedHistory from './orderedHistory'
4
+ import getDelayedDispatch from './getDelayedDispatch'
4
5
5
6
import {
6
7
// action constants
@@ -16,50 +17,6 @@ export function isGossipType(type = '') {
16
17
return type . substr ( 0 , 1 ) !== '@'
17
18
}
18
19
19
- // queue a _reduxDispatch call, debounced by animation frame.
20
- // configurable, but requires use of private methods at the moment
21
- // keep a reference to dispatcher because methods will change over time
22
- function getDelayedDispatch ( dispatcher ) {
23
- if ( typeof window === 'undefined'
24
- || typeof window . requestAnimationFrame !== 'function' ) {
25
- return false
26
- }
27
-
28
- const queue = [ ]
29
-
30
- function drainQueue ( ) {
31
- let state = dispatcher . _reduxGetState ( ) ,
32
- i
33
-
34
- for ( i = 0 ; i < 100 && ( i <= queue . length - 1 ) ; i ++ ) {
35
- // for-real dispatch the last action, triggering redux's subscribe
36
- // (and thus UI re-renders). This prioritises crunching data over
37
- // feedback, but potentially we should dispatch perodically, even
38
- // with items in the queue
39
- if ( i < queue . length - 1 ) {
40
- state = dispatcher . _historyReducer ( state , queue [ i ] )
41
- } else {
42
- dispatcher . _reduxDispatch ( queue [ i ] )
43
- }
44
- }
45
-
46
- // reset the queue
47
- queue . splice ( 0 , i + 1 )
48
-
49
- if ( queue . length )
50
- window . requestAnimationFrame ( drainQueue )
51
- }
52
-
53
- return function delayedDispatch ( action ) {
54
- queue . push ( action )
55
-
56
- // on first action, queue dispatching the action queue
57
- if ( queue . length === 1 ) {
58
- window . requestAnimationFrame ( drainQueue )
59
- }
60
- }
61
- }
62
-
63
20
const defaultOptions = {
64
21
customDispatch : getDelayedDispatch ,
65
22
isGossipType : isGossipType ,
0 commit comments