-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…56613) * Update templates to the new `store()` API * Add changelog entry * Use wp_unique_id --------- Co-authored-by: Luis Herranz <luisherranz@gmail.com>
- Loading branch information
1 parent
90cd8db
commit 00ccb8b
Showing
3 changed files
with
24 additions
and
23 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
25 changes: 11 additions & 14 deletions
25
packages/create-block-interactive-template/block-templates/view.js.mustache
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 |
---|---|---|
@@ -1,26 +1,23 @@ | ||
{{#isBasicVariant}} | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { store } from "@wordpress/interactivity"; | ||
import { store, getContext } from "@wordpress/interactivity"; | ||
|
||
store( { | ||
store( '{{namespace}}', { | ||
actions: { | ||
'{{namespace}}': { | ||
toggle: ( { context } ) => { | ||
context[ '{{namespace}}' ].isOpen = !context[ '{{namespace}}' ].isOpen; | ||
}, | ||
toggle: () => { | ||
const context = getContext(); | ||
context.isOpen = ! context.isOpen; | ||
}, | ||
}, | ||
effects: { | ||
'{{namespace}}': { | ||
logIsOpen: ( { context } ) => { | ||
// Log the value of `isOpen` each time it changes. | ||
console.log( `Is open: ${ context[ '{{namespace}}' ].isOpen }` ); | ||
}, | ||
callbacks: { | ||
logIsOpen: () => { | ||
const { isOpen } = getContext(); | ||
// Log the value of `isOpen` each time it changes. | ||
console.log( `Is open: ${ isOpen }` ); | ||
}, | ||
}, | ||
} ); | ||
|
||
{{/isBasicVariant}} | ||
{{/isBasicVariant}} |