-
Notifications
You must be signed in to change notification settings - Fork 396
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
[Feature] Bind property of component readonly #3381
Comments
After thinking about it a bit, what you want isn't really a read-only binding. I think what you're after is a reverse binding, so rather than setting up a binding from the parent into the component, you want to set up a binding from the component into the parent that is controlled by the lifecycle of the parent, where there's no reason it couldn't also be read-write. Does that sound right? I'm not sure exactly what the best way to indicate that in the template would be, so if anyone has any bike-shedding they'd like to apply, the feedback would certainly be welcome! I also think a binding overriding a child's computed property could be problematic, so there may be some question as to whether or not that should be allowed. As far as Another option is handling this with events, and that would be my suggested workaround for now. Something like Ractive.helpers.link = function(parent, child, local, target) {
parent.link(target, local, { instance: child });
} <ValidatingTextBox on-init="link(@this, $1, 'inputStates.textbox0', 'isValid')" /> The helper could be simplified a bit if it always links from child to parent, as you could just pass the child ( |
I was somehow under the impression that bindings do not have a direction, since value updates are always synchronized in both directions. Though after reading your comment, and the documentation for
When I first tried it, I somehow expected Ractive to know, that he can't write there. And that I get an error when changing the variable in the parent (like you do if you attempt to write into a readonly computed property within the same instance). But the property was simply overriden, and the initial value never reached my variable in the parent. computed: {
isValid: {
get() {},
set() {}
}
} Though that also didn't work. Now - after your comment, and the documentation of That's a cool workaround, thanks! |
Description:
I've now been in the situation where I wanted to observe one of my child component's state multiple times.
For example, imagine a validating
TextBox
component, that surfaces whether it is currently valid through a property.Normally when binding to a child component's property, the binding is initialized by writing the parent's value into the child, thus overwriting the child's initial value.
Since there already is a
bind-<property>
syntax, I imagined something likerobind-<property>
orreadonlybind-<property>
:As far as I understood it, binding to the computed properties of a child is not possible at the moment (at least the binding always seemed to overwrite the computed property for me). I don't know the rationale behind this, but maybe such a
readonly
binding would make it possible to bind to the computed values of a child?Overall, then allowing something like this (wishful thinking):
The text was updated successfully, but these errors were encountered: