WordPress / wp-movies-demo

Demo of the Interactivity API
https://wpmovies.dev
GNU General Public License v2.0
195 stars 42 forks source link

Move the state, actions & selectors used by a block to that blocks' `view.js` file #14

Closed michalczaplinski closed 1 year ago

michalczaplinski commented 1 year ago

⚠️ Stacked PR (note the PR base)

The view.js file for the favorites-number block contains the actions and state that are also used by the post-favorites block.

I've added a new view.js file for the post-favorites block that includes the references to the state and actions used in that block's render.php.

This way, the actions, state and selectors are defined within the same block and there's a better separation of concerns.

michalczaplinski commented 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?

SantosGuillamot commented 1 year ago

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 😄

michalczaplinski commented 1 year ago

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.

michalczaplinski commented 1 year ago

I ll merge the branch now. Thanks for the comments! 👍