-
Notifications
You must be signed in to change notification settings - Fork 843
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract setState queuing into a service, re-use it in EuiIcon (#2565)
* Extract datagrid's enqueue functionality into a re-usable service; put it to use in EuiIcon * changelog
- Loading branch information
1 parent
b03fa30
commit cfd81c6
Showing
7 changed files
with
70 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { unstable_batchedUpdates } from 'react-dom'; | ||
|
||
const _queue: Function[] = []; | ||
|
||
function processQueue() { | ||
// the queued functions trigger react setStates which, if unbatched, | ||
// each cause a full update->render->dom pass _per function_ | ||
// instead, tell React to wait until all updates are finished before re-rendering | ||
unstable_batchedUpdates(() => { | ||
for (let i = 0; i < _queue.length; i++) { | ||
_queue[i](); | ||
} | ||
_queue.length = 0; | ||
}); | ||
} | ||
|
||
export function enqueueStateChange(fn: Function) { | ||
if (_queue.length === 0) { | ||
setTimeout(processQueue); | ||
} | ||
_queue.push(fn); | ||
} |