-
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.
Opens the block inspector automatically when the block is selected (#…
- Loading branch information
1 parent
f00a6e2
commit a81e0dc
Showing
3 changed files
with
52 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Given a selector returns a functions that returns the listener only | ||
* if the returned value from the selector changes. | ||
* | ||
* @param {function} selector Selector. | ||
* @param {function} listener Listener. | ||
* @return {function} Listener creator. | ||
*/ | ||
export const onChangeListener = ( selector, listener ) => { | ||
let previousValue = selector(); | ||
return () => { | ||
const selectedValue = selector(); | ||
if ( selectedValue !== previousValue ) { | ||
previousValue = selectedValue; | ||
listener( selectedValue ); | ||
} | ||
}; | ||
}; |