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
Should the children in a loop inherit the parent mixins? #896
Comments
👍 for no |
Hmmm, sorry, after some thoughts, I don't think so now. How about <my-tag>
<ul>
<li each={ item in items }>{ @translate(item) }</li>
</ul>
</my-tag> |
Brilliant suggestion @cognitom the top level tag scope could be passed to all children. I am not sure that |
I would simply inherit all the parent properties to the children. If a child has a property named like the one in the parent it will not be overridden..it seems simple to implement and easy to understand. This will neither be a breaking change |
@rsbondi Good point! A down side of
@GianlucaGuarini It seems convenient. Actually, I chose that option for riot-bootstrap. But it was kind of "emergency avoidance". I'm wondering from the aspect of memory. If the tag has an array with 100 elements, 100 x 100 items will be made for the children... |
@cognitom javascript will pass only the reference to the object, it will not clone it, so the memory should not be a problem |
UPDATE: sorry, my understanding was wrong. Premitive types is immutable and passed by reference. so we don't have to worry about it at all, as @GianlucaGuarini said. |
Is that possible to tweak this line to include the all parent scopes? If so, children don't have to have inherited properties. It makes some sense for me because I can't imagine the use case from the constructor. How about..? <my-tag>
<child-tag>{ translate(item) }</child-tag> // good!
this.mixin('i18n')
</my-tag>
<child-tag>
<p><yield /></p>
var str = this.translate('something') // bad?: the inherited property seems confusable
</child-tag> Anyway, it's interesting discussion. 😄 |
But isn't this two different things? "Child tag" vs "loop child"? Or am I missing something in how riot handles loops and tags...? I don't find it naturally that a child tag should inherit the properties of a parent tag, it could lead to some strange cases of "guess the scope", and would easily lead to tight coupling between tags and thus non-reusable tags. But inside a loop (loop child) it would make a lot of sense to inherit the parent properties, or have them available with |
@cfenzo Thank you for the clarification. My fear with the anti- I like the idea of And as an aside just to make it mentioned: I want to ease the mental overhead of tracking nesting loop levels, but I don't want us to lose the ability to explicitly use the loop stack if we want using |
@rsbondi, how about this case? <app>
<my-tag />
</app>
<my-tag>
<child-tag>{ top.translate(top.titile1) }</child-tag>
this.mixin('translate')
this.title1 = 'Hello'
</my-tag>
<child-tag>
<span><yield /></span>
</child-tag>
We have two options now, and both have pros and cons. I hope there is a third option, it has not come to mind yet...
@cfenzo I agreed your concern about inherit. I think in addition "Child tag" and "Transcluded tag" should be different thing, too. cf. #856 |
In if(self.parent)
each(Object.keys(self.parent), function(k) {
if(!self[k]) self[k] = self.parent[k]
}) |
I have added the possibility to inherit all the parent properties for all the children tags in a loop! Riot will keep in sync only the child |
@tipiirai I have released riot 2.2.2-beta, we need to update the documentation describing that now in a loop the parent properties will be inherited by the children (see above). Please do not update the site until the documentation is complete. I will update the documentation during the next week. |
WIP: Update documentation to reflect parent property-in-loop changes in riot 2.2.2-beta To aid in riot#896
@GianlucaGuarini I hope I am not stepping on your toes but I took a stab at starting to update the documentation. |
@r4j4h thanks well done! Are we sure this is the only part in the doc we need to update? |
Not entirely sure, I glanced through to find different examples or mentions of This is the closest other thing I could find. |
@GianlucaGuarini @r4j4h This one bit me hard...sunk a bit of time into it. Think there's two problems here:
|
This doesn't seem to work with transclusion, which makes things even more confusing. For example: <my-tag>
<ul>
<li each={ item in items }>
<span>{ testy } - This works</span>
<my-custom-tag>{ testy } - Transcluded, this doesn't work</my-custom-tag>
</li>
</ul>
<script> this.testy = "hello"; </script>
</my-tag> Because of that and point 2) mentioned by @andynemzek, I went back to just using |
If I can add my .2$, I am against inheriting properties from parent, when you debug it's an hell, you get lot of name clashes and it's hard to recognize even what your |
I definitely like this feature, but do we still support the |
@tipiirai implementing the |
Now that I updated to 2.3, I see that my "success" messages get propogated to any child tags, and there didn't seem to be any way to avoid that. |
I'm still waiting for a solution for a parent's bandwagon problem, i.e. getting to the root tag from multiple transclusions requires use of "parent.parent.parent.parent". Angular solved this by making children inherit all named variables from parent scope. Can we do something like this? |
I am sure you are doing it just doing it in the wrong way.. Probably you should just switch to angular if it suits better your needs. Please post a valid example opening a new issue so we can check where is the problem |
@GianlucaGuarini nah, i like riot for it's simplicity, but there are some things that are bothering me. For tranclusions, I mean stacking tags like this: This way, it becomes hard to access ddata from input, for example. So is there a tip somewhere explaining the right way? |
Maybe this could help you structuring your core https://github.com/GianlucaGuarini/riot-app-example |
@5angel or use a flux pattern, such as with https://github.com/jimsparkman/RiotControl/ https://github.com/luisvinicius167/Riotux/ EDIT: that example uses something similar. |
Current riot (note
translate
is a mixin assigned tomy-tag
)My proposal ( the
li
tags will inherit the parent mixins if they will not have them already defined )The text was updated successfully, but these errors were encountered: