-
Notifications
You must be signed in to change notification settings - Fork 644
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
Question: Data Binding. #676
Comments
Related: #528 |
I'm evaluating markojs for my next project. I'm between vue.js, svelte.js and marko.js. I love the marko syntax and the way it accepts all javascript types as attributes (not just strings or extra markups). The only thing that I'm questioning right now is why there is no basic data bindings. It's not hard for a form have +50 fields, having one event and a function listener for every field will make my components very polluted with duplicated code. I've read #528 and it's such a common task for all of us, that it should be built in. |
@guilhermeaiolfi Do you have a particular proposal in mind? We are definitely open to ideas and I would agree that dealing with a complex form can get tedious. We are looking for user feedback and if there's a compelling proposal we would be interested in coordinating the effort to get it implemented. I think supporting a |
@patrick-steele-idem well, svelte use That looks "dirty" to me. Maybe introducing a general way of binding and creating components for , , <textarea /> could abstract that complexity away. |
I've had to do this with mixins to extend common functionality in components across a large project. With form handling, I have an attribute that would essentially flag the input to bind to a particular form element and set key-up and or change events accordingly. I feel that some enhancements to the state variables in conjunction with some tag attributes would be a great starting place for two way data binding. At this point, is there any concern about performance hits with adding data binding to components? |
Is that something you could share? I thought about the same thing, but I
couldn't do it flexible enough yet.
Em 24 de ago de 2017 22:00, "Ian Von Holt" <notifications@github.com>
escreveu:
… I've had to do this with mixins to extend common functionality in
components across a large project.
With form handling, I have an attribute that would essentially flag the
input to bind to a particular form element and set key-up and or change
events accordingly. I feel that some enhancements to the state variables in
conjunction with some tag attributes would be a great starting place for
two way data binding.
At this point, is there any concern about performance hits with adding
data binding to components?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#676 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAPhmEh_ZM-7EWD43LHTK6XJlrkpqwORks5sbhyRgaJpZM4NFY4s>
.
|
@guilhermeaiolfi I can't share the exact code that is used in-house. If I find myself free with some time this weekend I'll put a generic class, as an example, to get this going. @patrick-steele-idem I'd be more then happy to help get this one implemented if there is a large enough interest. |
I'm very interested. I would like to explore what we can support in user land before merging something into marko core. I would like to see something that is completely declarative that allows binding of input fields (including both DOM inputs and maybe input from custom components) to state properties on the component. @ianvonholt could you share some code how you are utilizing data binding (not necessarily the implementation)? Also, for reference: https://github.com/capaj/react-bound |
@patrick-steele-idem I'll show original Marko syntax and then the attributes I use. I kept it similar to Angular's Before:
A simple form element, before, would consist of a After:
Here everything is simplified a little bit. The input key and state object to bind to are set with the same attribute. This also creates a state object with |
to me something like |
@nmocruz it is interesting too. You could show any sample like that? |
I like the syntax @nmocruz suggested (See #870 for why Would we ever want to bind to something other than a In <input value:bind=state.address name="address" /> Out <input value=state.address on-input('setStateFromEvent', 'address') name="address" /> |
Since marko uses a syntax where attributes look like functions, e.g. Restricting this syntax to only apply to state would make things cleaner too: class {
onCreate() {
this.state = {
uname: '',
};
}
}
<input bind('uname') type="text" name="username"/> I've always been a fan of how v-model works in vue, in that vue chooses the correct value, event, and data (state) binding behind the scenes based on element tag and type. Developers can focus on being productive rather than trying to remember which cases to use which event/value or when to do special case handling etc. Vue model source: https://github.com/vuejs/vue/blob/master/src/platforms/web/compiler/directives/model.js This does obfuscate the data flow to the developer but most of the time that's not important. It does have a runtime byte size cost ( |
I am looking for the 2 way binding to implement form as well. Any update? |
The tags api preview now introduces two way binding (https://dev.to/ryansolid/introducing-the-marko-tags-api-preview-37o4#binding-eventsoperators) |
Do we have any conclusion here? |
@rajat8266 we've added two way binding support in the tags api preview, more info here. It will be natively supported in Marko 6, but for now you need the preview. |
Right now I'm changing the component state with events. When a value changes (e.g. in an input tag) I use the on-change or on-keypress events to handle state changes. However in a form with a lot of states you need to have a lot of event handlers in the component class.
It gets unwieldy to have full control over all the business logic. It would be easier and clean to have an attribute like angular or vue.js (v-model, model.. or something like this) that takes a property of the state object and update it automatically.
I don't know if such a feature is already available but from the documentation I haven't seen anything like that.
Is it possible to implement a 2 way data binding out of the box? or, if not possible, can you suggest the best pattern to manage such cases?
Thanks.
The text was updated successfully, but these errors were encountered: