-
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
Components enhancements #553
Comments
Component implementation now really falls short. |
One more point: currently there is no way to clean up component (for example |
Just to summarize efforts
It's really easy to add if (typeof this.component.controller === 'function') {
this.component.initialize = defaultInitializer;
}
function defaultInitializer(el, attrs) {
var scope = {};
scope[this.type] = this.component.controller.call(this, attrs);
return scope;
} |
I have a question about transclusion: <form-field type="number">
<label>My custom label</label>
<div rv-part="error">My custom error message</div>
</form-field> What will be |
@jccazeaux in my fork I use |
@stalniy I took some time to go deeper in components. I want to have your opinion on something I found.
It is not true, In the code I found that Rivets binds component's attributes at root of component's model. This means we can access attributes directly without <todo-item item="myItem">
<!-- this is component's template -->
{ item }
</todo-item> There, databinding is activated like doc describes it. There is only a glitch here : component's model is not initialized at first. You have to change parent's value at least once. This glitch is very easy to fix if necessary Were you aware of this? |
Hey @jccazeaux I have finally got round to this. I thought that this bug you found was because you were declaring the component as a function rather than as a class, so I forked your fiddle here and as I thought, when declaring the component as an es6 class it works correctly, updating the parent property. I don't know enough about JS classes to explain why this is the case but if you follow the docs, declaring a component using |
Hi @Leeds-eBooks your fiddle is interesting. It's not the using of JS class that changed the thing. Look at this.
So to set initial value in binding you have to do it in |
Currently components lacks really powerful features:
initialize
andtemplate
and last one is called first then first one. That means that developer can decide which template to render based on input information from the attributes. For example, I'd like to have a component which is something similar toinput
tags with different types but more complex, e.g.datepicker
,autocomplete
, etc. So, that I do this in HTML:And my component is this:
Currently it's not possible. The only possible solution is to create separate component for each
form-field
. But logically it should be one component with extendable points and some shared behaviour2.
initialize
accepts 2 arguments: object of attributes andHtmlElement
and this allows devs to write worse code as it mixes concepts (view - element, parsed attrs - kind of model). Another reason why it should be split into 2 because view (rivets binders) assigns view related variables (i.e.rv-each-*
) right into my component controller what can lead to names collisions and unpredictable behaviour. So, something like{ [componentName]: component.initialize() }
should be view scope and not justcomponent.initialize()
result.3. Sometimes you have a component with its default template but then you want to use it in another place with a bit different template. Currently there is no way to change components parts. This is what
transclusion
cares about. So, it allows to define parts inside components which can be overridden if necessary. So, you can do like this:And Components template:
In this example
form-field
will replacepart
which is calledlabel
inside default template with the provided tag.4. Components doesn't not allow to return document fragment from their template. In the same time document fragment is the most performant way to put a bunch of HTML in DOM tree.
5. Sometimes you want to specify component's template as a string (when there is no need in function, you just have prepared HTML or want to put it right there without writing extra function)
Here no need in function, so more convenient to pass just a string.
6. No support for dependent components like
tabset
andtab
. For example currently this is not possible as components just remove inner htmlAlso it's not possible to access parent component inside child one at the moment.
@blikblum, @Leeds-eBooks, @jccazeaux want to hear your thoughts about this as I have already done all this (and a bit more in my fork). So, if we are ok with that we could split these tasks to smaller one and I will create a separate pull-request for each.
The text was updated successfully, but these errors were encountered: