-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try: Alternative attributes initialization #892
Conversation
I like this much more. |
I agree with this. At some point we might not want to pass a node. I wonder if calling it something different would discourage block implementors inspecting the object and encourage only using our selectors. |
I'm not sure what you mean. Can't it be something like |
It could. I struggled to think of other use-cases for this source matching, and kept it generic to equivalent extracting of |
You already know my thoughts here, this still feels an imperative approach, I still think declarative approach is better (consolidate our |
We can also do something à la { _internal: HTMLElement } |
@youknowriad Why does it feel imperative? In React you can also set the initial state in the constructor? |
@iseulde Yes, and React is not fully declarative right. I'm just comparing the approach of this branch with having something like #865 (comment) (which is more "declarative" IMO) |
Those were two separate questions, sorry. :) |
I'm not sure I get what the difference is between having a wrapper function or having an object with each of the items having functions in terms of being declarative. |
If you have a function like:
while having I agree that we could consider |
Right, you can still do it, just not for the whole object at once, but for each attribute. |
@youknowriad I see what you're getting at, but also don't entirely agree that it's necessarily imperative because it makes use of a function, since the intent of the function is in returning an object, not performing side-effects, in much the same way that React's I do agree that this could be clearer if it weren't a function at all. However, I think there's some value in marking this as an action that occurs in initializing a block. The Another consideration contrasting the function and object is that the latter requires a fair bit more API awareness (developer overhead) to accommodate type coercion and defaulting. With a function, this becomes "just code" (object spread to default, |
@aduth I understand the points raised here and this "the latter requires a fair bit more API awareness (developer overhead) " is a good point. But I'd like to ask, how do you see us implement the |
I find |
Related: #672 I'm not totally sure. It's good to bring up. I'd remarked previously at #714 (comment). My uncertainty there on how we plan to use the Inspector still stands; when we change something in the inspector, what does it affect? I don't think it's any different than what we have now: it sets an attribute, which is either serialized into the markup or encoded in the block string. This itself is in no way incompatible with Where it gets interesting is if we wanted to consolidate inspector logic into an attributes field to allow automated field generation. It's an interesting idea, though in my experience can be burdensome and inflexible (order, styling, custom fields). If we were to do something like this, it might be wise to subscribe to JSON schema (already used in core APIs) and perhaps an existing form builder utility. To me, the obvious alternatives are:
|
@aduth That's one of the reasons these discussions are so great. Reading your comment here made me change my mind :). One of my main arguments for the |
Closing in favor of #1905 |
Closes #865
Related: #391
This pull request seeks to explore an alternative approach to initializing and serializing attributes. See #865 for more detail on motivation.
Specifically, the goals with these changes are:
getInitialAttributes
wp.blocks.query
towp.blocks.source
in an effort to clarify their passiveness and use as extraction strategieswp.blocks.query.query
Downsides being:
getInitialAttributes
)? Ideally they'd not be traversing it themselves, and we might like to have the option to change its structure without impacting backwards compatibility. My first approach passedcontent
as the raw HTML string, but at this point we'd already have done a single HTML parse pass, and would presumably like to limit the number of parsing passes.getNodeAttribute( 'img', 'src' )( node );
, where block implementation only returnsgetNodeAttribute( 'img', 'src' )
nodeName: getNodeName( node, [ '*' ] )
get
/find
distinction is one we wantTesting instructions:
This is not a complete implementation and will surely fail tests and usage in the editor. At this point it's more an exploration / proposal / example. Review code changes instead. Also note that the implementation of the image block's encoded
align
attribute is subject to change in future efforts to eliminate duplicated source of truth, but is not a focus of this pull request.