-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Data: Add a batch function to the data module to batch actions (#34046)
- Loading branch information
1 parent
5df0cd5
commit 76fe632
Showing
9 changed files
with
171 additions
and
14 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,46 @@ | ||
/** | ||
* Create an event emitter. | ||
* | ||
* @return {import("../types").WPDataEmitter} Emitter. | ||
*/ | ||
export function createEmitter() { | ||
let isPaused = false; | ||
let isPending = false; | ||
const listeners = new Set(); | ||
const notifyListeners = () => | ||
// We use Array.from to clone the listeners Set | ||
// This ensures that we don't run a listener | ||
// that was added as a response to another listener. | ||
Array.from( listeners ).forEach( ( listener ) => listener() ); | ||
|
||
return { | ||
get isPaused() { | ||
return isPaused; | ||
}, | ||
|
||
subscribe( listener ) { | ||
listeners.add( listener ); | ||
return () => listeners.delete( listener ); | ||
}, | ||
|
||
pause() { | ||
isPaused = true; | ||
}, | ||
|
||
resume() { | ||
isPaused = false; | ||
if ( isPending ) { | ||
isPending = false; | ||
notifyListeners(); | ||
} | ||
}, | ||
|
||
emit() { | ||
if ( isPaused ) { | ||
isPending = true; | ||
return; | ||
} | ||
notifyListeners(); | ||
}, | ||
}; | ||
} |
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 |
---|---|---|
|
@@ -16,5 +16,6 @@ | |
"include": [ | ||
"src/redux-store/metadata/**/*", | ||
"src/promise-middleware.js", | ||
"src/utils", | ||
] | ||
} |
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