Closed michalczaplinski closed 1 year ago
Nope, don't strictly need it!
But not specifying it might be confusing because state.favorites.post
is used inside of the togglePost()
action. So if the user only looks at the post-favourite
block they might be confused where it comes from. And it does not hurt to specify it in both places.
On the other hand, it might also be a little confusing to specify it in both places... But less so. Would you agree?
I thought it could also be an example showing that the state
you define in the store
is global, and other blocks can use it. But as you say, maybe it is more confusing for the users. I honestly don't know what approach is better 😄
an example showing that the state you define in the store is global
Hmm, I think I like your reasoning better 😄
I ll remove the state.favorites.posts
in the favorites-number
block and I ll add a comment clarifying that this state is global and defined in the other block.
I ll merge the branch now. Thanks for the comments! 👍
⚠️ Stacked PR (note the PR base)
The
view.js
file for thefavorites-number
block contains the actions and state that are also used by thepost-favorites
block.I've added a new
view.js
file for thepost-favorites
block that includes the references to the state and actions used in that block'srender.php
.This way, the actions, state and selectors are defined within the same block and there's a better separation of concerns.