@@ -6,19 +6,16 @@ import { queue } from './queue';
66// this runs the passed function and delays all re-renders
77// until the function is finished running
88export function batch ( fn , ctx , args ) {
9- let result ;
109 if ( queue . isInsideBatch ) {
11- result = fn . apply ( ctx , args ) ;
12- } else {
13- try {
14- queue . on ( ) ;
15- result = fn . apply ( ctx , args ) ;
16- } finally {
17- queue . flush ( ) ;
18- queue . off ( ) ;
19- }
10+ return fn . apply ( ctx , args ) ;
11+ }
12+ try {
13+ queue . on ( ) ;
14+ return fn . apply ( ctx , args ) ;
15+ } finally {
16+ queue . flush ( ) ;
17+ queue . off ( ) ;
2018 }
21- return result ;
2219}
2320
2421// this creates and returns a batched version of the passed function
@@ -92,13 +89,19 @@ if (globalObj.Promise) {
9289 batchMethodsCallbacks ( Promise . prototype , [ 'then' , 'catch' ] ) ;
9390}
9491
92+ // Event listener batching causes an input caret jumping bug:
93+ // https://github.com/RisingStack/react-easy-state/issues/92.
94+ // This part has to be commented out to prevent that bug.
95+ // React batches setStates in its event listeners anyways
96+ // so this commenting this part out is not a huge issue.
97+
9598// batch addEventListener calls
96- if ( globalObj . EventTarget ) {
99+ /* if (globalObj.EventTarget) {
97100 batchMethodsCallbacks(EventTarget.prototype, [
98101 'addEventListener',
99102 'removeEventListener',
100103 ]);
101- }
104+ } */
102105
103106// this batches websocket event handlers
104107if ( globalObj . WebSocket ) {
0 commit comments