File tree 2 files changed +38
-8
lines changed 2 files changed +38
-8
lines changed Original file line number Diff line number Diff line change @@ -53,15 +53,33 @@ var patchReduxStore = function patchReduxStore(origStore) {
53
53
listeners . push ( listener ) ;
54
54
55
55
if ( listeners . length === 1 ) {
56
- unsubscribe = origStore . subscribe ( function ( ) {
56
+ var pending = false ;
57
+
58
+ var runBatchedUpdates = function runBatchedUpdates ( ) {
59
+ if ( stateForUpdates ) {
60
+ pending = true ;
61
+ return ;
62
+ }
63
+
57
64
stateForUpdates = origStore . getState ( ) ;
65
+
66
+ var onFinishRendering = function onFinishRendering ( ) {
67
+ stateForUpdates = null ;
68
+
69
+ if ( pending ) {
70
+ pending = false ;
71
+ runBatchedUpdates ( ) ;
72
+ }
73
+ } ;
74
+
58
75
( 0 , _batchedUpdates . batchedUpdates ) ( function ( ) {
59
76
listeners . forEach ( function ( l ) {
60
77
return l ( ) ;
61
78
} ) ;
62
- } ) ;
63
- stateForUpdates = null ;
64
- } ) ;
79
+ } , onFinishRendering ) ;
80
+ } ;
81
+
82
+ unsubscribe = origStore . subscribe ( runBatchedUpdates ) ;
65
83
}
66
84
67
85
return function ( ) {
Original file line number Diff line number Diff line change @@ -45,13 +45,25 @@ const patchReduxStore = (origStore) => {
45
45
const subscribe = ( listener ) => {
46
46
listeners . push ( listener ) ;
47
47
if ( listeners . length === 1 ) {
48
- unsubscribe = origStore . subscribe ( ( ) => {
48
+ let pending = false ;
49
+ const runBatchedUpdates = ( ) => {
50
+ if ( stateForUpdates ) {
51
+ pending = true ;
52
+ return ;
53
+ }
49
54
stateForUpdates = origStore . getState ( ) ;
55
+ const onFinishRendering = ( ) => {
56
+ stateForUpdates = null ;
57
+ if ( pending ) {
58
+ pending = false ;
59
+ runBatchedUpdates ( ) ;
60
+ }
61
+ } ;
50
62
batchedUpdates ( ( ) => {
51
63
listeners . forEach ( l => l ( ) ) ;
52
- } ) ;
53
- stateForUpdates = null ;
54
- } ) ;
64
+ } , onFinishRendering ) ;
65
+ } ;
66
+ unsubscribe = origStore . subscribe ( runBatchedUpdates ) ;
55
67
}
56
68
return ( ) => {
57
69
const index = listeners . indexOf ( listener ) ;
You can’t perform that action at this time.
0 commit comments