-
Notifications
You must be signed in to change notification settings - Fork 310
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
Constant string in component HTML attributes #478
Comments
I have an other argument : when i create a component, i don't really know in advance in wich attributes i will use constant strings or model variables. This is especially true when i create a library of components for the developpers . |
The best option here is to rewrite it to smth what Angular2 and Aurelia do. I mean by default all attributes are static and when you suffix them with <tab title="test title"></tab>
<tab title.bind="article.title"></tab> |
I agree that having the attributes be evaluated by default as static is better. Another point is that this is backward incompatible so must be done with caution |
Rivets component attributes currently do not need the <my-component rv-if="config.shouldShowComponent" phrase="Hello World!"></my-component> I use components extensively and roughly 90% of my component attributes are dynamic, not static. I am sure that this is why Mike originally wrote components so that the default is dynamic, not static. I can see the value in declaring attributes as static on the component element, rather than in the component object, so I would suggest something like a <my-component counter="model.counter" static-phrase="Hello World!"></my-component> (a prefix, rather than a suffix, so that the actual name of the attribute is closest to its value) If the default were static, developers would find themselves writing |
It would be a specific binding, e.g, Your example would be
As i said the problem with this is backwards compatibility. To get backward compatible an alternative is use a binding for static props like you proposed. I would just add a prefix to get consistent with the rest of library: |
I agree, attributes must be dynamic by default. However, in dynamic attributes, we should be able to send a primitive data (string or int). It's possible in every binders:
My point was : primitive values are not activated on components. To "simulate" primitive values we have to declare static attributes. If we activate primitive values it will be like all binders Your exemple would like:
|
@jccazeaux Yep I actually think your solution makes the most sense, probably, although the |
@Leeds-eBooks That's correct. I made the update on my github but never sent the pull request: https://github.com/jccazeaux/rivets/tree/Component-constant-attributes |
Well I'm personally in agreement if you did submit a pull request, but I don't think I should make this decision on my own. Would be good to get @Duder-onomy 's opinion on this at least, as well as the other people in this thread. |
How about passing numeric values? |
As I understand it, you'd just do |
I don't know, in the docs it says that primitive can be numeric, string or null but does not has examples with it. Later i will do some tests and post here. I think we should replicate the behavior of binding syntax, if it accepts |
Rivets handles numeric values as primitives. It's done in parsers.coffee:
As you can see, booleans, numbers, strings are considered as primitive types. |
Ok, and what about id, class, title, hidden, other html specific attributes which expected to be static? |
As custom component elements are treated as divs by the browser, it is unlikely that any attributes other than |
…. New tests for components reveal an error in forEach on attributes: attributes is not an array. An error was revealed too in View import : cyclic dependency between view and binding;
…. New tests for components reveal an error in forEach on attributes: attributes is not an array. An error was revealed too in View import : cyclic dependency between view and binding;
this may be closed |
In binders we can use simple quotes to define constant string
But in components this doesn't work, instead we must declare the attribute as "static". It would have been less confusing to have the same method no? Or there is a reason i don't see?
I would like to write
Instead of
The text was updated successfully, but these errors were encountered: