-
Notifications
You must be signed in to change notification settings - Fork 11
⚛️ Add directives to handle providesContext
and usesContext
#68
Conversation
// Create vNode. Note that all `wpBlock` props should exist now to make directives work. | ||
const vNode = h(type, props, children); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I've assumed that options.vnode
would run every time h()
is used. Maybe I'm wrong here. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're not. That's the way it works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first glance, it looks great to me. I'm glad the current implementation of the directives is flexible enough to inject atomic functionality into the vdom. However, I was hoping we could delegate more to the wrapper component and less to the vdom internals.
But we can keep playing with this API in other PRs.
I left three things inside
Thanks for your review @luisherranz. I'm merging this PR. 😄 |
Closes #67
I've refactored
toVdom
significantly and added support for directives like in WordPress/gutenberg#44034. There are still some code I haven't moved to directives, like sourced attributes generation and inner blocks location (not sure if it is possible).Also, I created three directives:
type
and renders the block component (if it exists).providesContext
and renders a wrapper around block children.usesContext
, that injects acontext
property to a block component using a HOC.Directives are placed in
src/directives
.