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
render()
should not use a <span> to contain rendered elements
#151
Comments
I just thought that if we went this way it would be pretty easy to make an extension function that would make things even cleaner (IMO anyway 😄) div(fomantic.menu).render(state.listAreas()) {
// ...
} I'm not sure about the name I think it would be confusing to call it Or go with something like Thinking about it I'd even say that I'd move |
I've experimented with this a bit and it seem to work fine but I'm not sure what to do with this: kweb-core/src/main/kotlin/kweb/Element.kt Lines 426 to 433 in c2073e9
I think that the first |
Requiring a wrapper element like the But In exchange for doing this server-side housekeeping we shouldn't need any wrapper element at all - would that address your use case? |
Yes, getting rid of wrapping |
I think if we reuse the same We'd also need to make sure that new elements get inserted at the same positions under the parent element as the replaced elements. Another approach would be to use a new |
Are there any other important factors? Like speed for example? |
It should be possible to make this improvement without sacrificing speed. Currently we can just call Element.removeChildren() on the wrapper The proposed new approach would require the server to pass a list of the element IDs to be deleted to the browser which would then delete them, this should be a single websocket message. I don't anticipate this being inefficient unless there are a very large number elements to be deleted. Oh, and we also need to ensure that any subsequently added elements are added in the same position as those they replace. |
This one can be hard. If we don't have the container element the children added by render could be interleaved with other components. Then re-render would have a really hard time to address that. |
Yeah, getting element replacement right in situations where there are sibling elements that are not part of the I'm confident it's doable though if we think about the problem the right way, needs more thought. |
render()
function optionally take container elementrender()
should not use a <span> to contain rendered elements
Note: version 0.7.19 doesn't yet eliminate the need for a container element, but it does allow you to change the type of element used with |
This is nice! |
Not right now I'm afraid, I could add another parameter to The stop-gap would be something like: render(containerElementTag = "li", containerConfig = { it.classes("item") }) { ... } Not very elegant, but hopefully temporary - would this work for you? |
Well it would work for this exact use-case. Why you don't like the idea of just passing |
Good point, just released render(container = { li().classes("item") }, value = v) { ... } (The reason I'm not allowing a raw |
So would something like this work? val el = li().classes("item")
render(container = { el }, value = v) { ... } |
Yes - that would probably work with the current implementation - so I guess it was inaccurate to say it would ensure use of the parent ElementCreator, but it would encourage it (I view this as a stopgap measure until we can remove the need for a container element, it's far from perfect). Is there a particular reason to pass in an |
Relevant for appending multiple elements:
Notes:
|
After quite a bit of thought and discussion with @Derek52, I think I have a solution. While it would be nice if we could do this without needing to add any additional elements to the DOM - I don't think this will be practical because any approach I can think of for keeping track of which elements need to be replaced has some very nasty edge cases. Rather than wrapping the We modify We should also predefine a JavaScript function that can be given two element ids and which will delete any sibling elements between them. This can be used by |
Render was redesigned a while ago to remove the |
The
render()
function internally usesspan
as it's container element. Removing it would be a god send, but I don't think there is an easy way to do this so what we can do instead is provide a way for user to give it some custom element as container.The problem I've stumbled upon goes like this. I want to create dynamically filled dropdown using fomantic. So I did this:
This works, but because of the span it doesn't look right (styling is wrong). So instead I think we could do this:
Tell me what do you think.
The text was updated successfully, but these errors were encountered: