-
-
Notifications
You must be signed in to change notification settings - Fork 96
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
.ref only supports properties on context #214
Comments
Hmm. @jdanyow What do you think of this? |
sounds reasonable. A workaround (after today's release) will be to do something like this: <datatable with="section2" ref="datatable"> I think this^^^ will work... Another thing we might want to look into when making changes to |
The idea being that you don't want to add the An array seems an obvious idea, but not very friendly to use, as you need to know the index of the model you want the control for. And that index can change over time. Also, because collections can change over time, it means that the binding may have to regenerate the array several times (by mutation, since coders may have captured the value). I think that index values might become confusing, e.g. what about nested loops? If I want to store a ref on my root and there are two loops before the Other idea: It looks to me like a reversed In the end, I think as a coder I would just store the |
@jdanyow Let's not jump into ref arrays so fast. I want to understand what the developers are trying to do that for first...there may be a better way we want to encourage. I think that arrays of refs could get pretty involved... |
The main problem with a multi-level ref is what you do when the upper-level(s) of the expression are initially undefined? (eg. 'section2.datatable' and section2 is currently undefined). Also, what if "section2" is defined/assigned by a ref itself - you've now got an ordering issue to take care of/resolve. I know it's a workaround, but it seems that a property setter on the outermost view-model would put the onus on that view-model to disseminate the references elsewhere (ie. into subobjects), for example during bind( ). Regarding ref arrays, it's not necessarily the same level of "power", but we need to keep in mind that if you are using a repeat-for, then you are already iterating over a container of something (the "data"), so perhaps a simple starting point would be a means to put a "ref" into the "item" (within the container) to store a reference to the view-model for that item. |
Agree- we've run into problems with the auto-creation of object-hierarchies: #205 Lets table this for now- it sounds like there are potentially as many CONS as there are PROS to putting this in. |
I was reviewing our codebase and found some hacks that referred to this issue. I feel a bit like it was closed because the discussion wandered off the subject.
I only want to be able to do I don't know if the The fact that In fact, it is a vexing API that Going further, if it supported indexing as well (as it should), the <div repeat.for="item in list">
<!-- Store on each item: -->
<thing thing.ref="item.thing"></thing>
<!-- Store in an array on main VM: -->
<thing thing.ref="things[$index]"></thing>
</div> |
@jdanyow I'd like to revisit this. I saw it come up again in another issue recently as well. I'm wondering if we could just enhance the syntax interpreter to parse the value into an epxression and then pass that to the ref binding which would simply call assign on the expression, passing it the specified reference value type. What do you think? |
sounds good to me |
I'm thinking that would be backwards compatible and add the feature that most people want. I'll assign this to you. (but the IE bug is more important :)) |
Thanks for the release! Just in time 😄 |
Can you guys clarify what the status is on this? I see the bug is closed, but what exactly was implemented and does this allow capturing of refs within a for loop as mentioned? I could really use this. |
Oops. Sorry. You can now place binding expressions in the ref :) |
Thanks! Verified it's working like a champ.
|
It would be nice to be able to do things like
<datatable datatable.ref='section2.datatable'>
.But this currently doesn't work as
NameExpression
only supports properties directly on context (it doescontext[property] = value
).As assigning values to path is already supported by Aurelia (e.g. in bindings), I guess it shouldn't be too hard to reuse the same setter code for
NameExpression
.It would be the attributes behaviour more consistent and more powerful.
The text was updated successfully, but these errors were encountered: