-
Notifications
You must be signed in to change notification settings - Fork 108
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
Limitations of the component model #128
Comments
Agree! |
Would it be better if we introduce some type classes to convert things to |
val warning = Some(<div>warning</div>)
<div>{dialog(Constants(<div>Some text</div> +: warning.bind.toSeq:_*)).bind}</div> The above code have been improved in Binding.scala for FXML, because the type of an HTML literal is |
There was a proposal to implement a new annotation |
Yes, I think it's a good idea anyway. When I implemented |
I have to admit, I do not fully understand the benefits of |
Good point! If I understand correctly, you introduced new extension point for Binding.scala to manage of children mounting. This is a useful feature, but it does not relate directly to the user defined tags. We need ability to decompose and organize our code with something like "dom templates": https://github.com/ThoughtWorksInc/Binding.scala/pull/132/files#diff-83b72dae9d603e2ad2d906c1dc0621e7R88 |
User defined tags are really cool! And I think this is the missing part when comparing with ReasonML. I will definitely use a lot when it becomes available 😆. In React there's some components that passing properties all the way through it children. For example, in this code for Antd menu:
Currently there are two ways to archive similar behavior in Binding.scala:
Is there a way that I can passing there kind of "internal" properties around when using user defined tags? |
Never mind my last comment. |
@lxohi could you describe here the material-UI approaches? |
@glmars Let's say that we want some components to build a navigation side panel. Antd's approach
<Menu ...>
<MenuItem ... />
<MenuItem ... />
<MenuItem ... />
</Menu>
Material-UI's approach
function foo() {
const open = ...;
function clickHandler() {
... modify open ...
}
return (
<List ...>
<ListItem ...>
{open ? <ExpandLess /> : <ExpandMore />}
</ListItem>
<Collapse in={open} ...>
</Collapse>
)
}
Although I was decided to not make my Binding.scala components works like Antd does. (which means passing a lot of things under the water and/or modify the other component from outside of it.) The Antd components are really easy to use and users will love it A LOT. So then...
Refs:
|
I prefer the material-ui's approach as well, except I thought |
This example is genius! And I believe it can loops again and again without having Maximum call stack size exceeded error in the browser which is more interesting :) |
Hi, @glmars, recently I created bindable.scala, a library that provides type classes to convert other types to I think bindable.scala solves the “containment” and “multiple holes” problem. How do you think of it? |
Hi, @Atry, I like it a lot! @lxohi will be happy too, I think :) Only some questions:
|
Hi, @glmars ,
|
|
Free free to create a PR for |
Introduction
In our company we have started using Binding.scala in several projects. The library is wonderful, especially when you write code like web designer does. But when we started decomposing our code, we faced the limitations of the component model, especially when processing child elements.
This issue is a meta-task to discuss this limitations
There are two component models in Binding.scala
Let's extract internal
div
in this example as a component:Please, see full source code here
@dom functions (official)
Official way is using a regular function with
@dom
annotation:Which can be used in other
@dom
functions:User defined tags (unofficial)
This is undocumented, but it is possible to write composable user defined tags. The same component as above is:
Which can be used in
@dom
functions:Features of the component model
Using attributes of an underline html element
It's easy to use attributes of an underline html element.
We should slightly change the implementation of our @dom component
and using:
Nothing changed in the implementation of user defined tag.
Use it like this:
Please, see full source code here
Creating a component attribute
In this chapter we'll create a
caption
attribute for our dialog.And second goal is check ability of using bindable attributes.
It's just an additional parameter of @dom component function:
and using:
It's quite hard to implement the same for user defined tag. But easy to use.
Please, see full source code here
Containment
Children can be absent, can contain single node, list of nodes, option node, text node etc. and their combinations.
A common type for all of this is
BindingSeq[Node]
, you can easily add such parameter to @dom component function:but it's inconvenient to use:
converting types to
BindingSeq[Node]
makes code less readable and kills a partial update❗Nothing changed in the implementation of user defined tag. And any kind of children can be used like a charm 😄:
Please, see full source code here
Multiple “holes” in a component
In both component models you can add
BindingSeq[Node]
parameter and have hard way on using it 😞Painless HTML creation
As you can see in previous examples, HTML creation is easy in @dom component (because of
@dom
magic):Unfortunately, it isn't possible to use
@dom
for implementing user defined tag. It would be great if we could write something like this:when using stays the same as before:
Please, see full source code here
Ops, there is some ugly workaround
Conclusion
Current state
Possible improvements
BindingSeq[Node]
(or to any other more appropriate type)List of references
The text was updated successfully, but these errors were encountered: