-
Notifications
You must be signed in to change notification settings - Fork 0
Component object data model #11
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
Conversation
kbond
left a comment
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.
Looks great!
| * | ||
| * @internal | ||
| */ | ||
| final class DataModelPropsSubscriber implements EventSubscriberInterface |
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.
Curious why you chose to put this in twig components? Is there value in having it here or just to make the transition from twig to live easier/consistent?
| use PHPUnit\Framework\TestCase; | ||
| use Symfony\UX\TwigComponent\Util\ModelBindingParser; | ||
|
|
||
| final class ModeBindingParserTest extends TestCase |
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.
| final class ModeBindingParserTest extends TestCase | |
| final class ModelBindingParserTest extends TestCase |
| @@ -0,0 +1,5 @@ | |||
| <div> | |||
| {{ component('textarea_component', { | |||
| 'data-model': 'value:content' | |||
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.
This should work w/o value:, right? Is this tested?
I see it's unit tested.
| .. code-block:: twig | ||
| {{ component('textarea_field', { | ||
| 'data-model': 'user.firstName:first user.lastName:last', |
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.
🤯 This is cool!
… components This also includes the dispatching of several new PHP events.
7e7ebec to
13c6632
Compare
TODO (2) of symfony#500
This is all about establishing communication between a parent & child component. Suppose you have a parent form component with a
$blogContentproperty. This component renders a child component (e.g. a reusable smart rich text editor) with a$valueproperty.The idea is that I want to pass my
$blogContentproperty INTO the child as a prop calledvalue. That can be done today, of course - e.g.{{ component('rich_editor', { value: blogContent }) }}. BUT, I also want that, when thevalueprop is modified by the end-user (e.g. they type into the rich text editor), that the new value is also set onto the parent component'sblogContentprop. THAT's really what this feature is about.Syntax to do this (from inside parent component's template):
Or simply
'data-model': 'blogContent'if your child prop is calledvalue(it defaults tovalue).To get this syntax/functionality, I'm looking at:
A) Vue https://vuejs.org/guide/components/events.html#usage-with-v-model
where
<CustomComponent v-model="searchText">is short for:which translates to
modelValueprop into the child set to the parent component'ssearchTextand
modelValuechanges inside the child, please set it onto thesearchTextprop on the parent(note Vue used to use
valueas their default name withv-modelbut switched tomodelValue- I'm not sure why).B) From Alpine.js -
x-modelable:the
x-modelandx-modelabletranslate to:A) Grab the
numberdata from the parent scope and make it available ascountin the childand
B) When
countin the child updates, please update thenumberin the parentCheers!