-
Notifications
You must be signed in to change notification settings - Fork 30
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
Alternative approach to rendering #530
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…new RenderContext, if it is a Tag
some cleanup
This was
linked to
issues
Oct 1, 2021
Closed
I just added one more issue (#405 ) that should be fixed by this. |
… global render is called
addGlobalStyle(s)
- fix SelectField component to reflect the new rendering mechanism: unite static and dynamic tags into one rendering block - optimize rendering of <tr> and <th> parts of the DataTable component to reduce not needed intermediate nodes.
- improves all `renderEach` methods by adding the command to clear all sub-elements of the target node, if an existing tag should be used as mount-point (so `into` is set!) This way `render` and `renderEach` behave the same way and there is no edge case left (static children would always appear after the dynamic mounted elements, even though they are defined before the `renderEach` method) - check if some tag is already a mount-point at initialization. Prints out an error message in order to help with debugging then.
ghost
approved these changes
Oct 21, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
renderEach()
on same level #346All this was only necessary to enable to mix mount-points with static DOM tags below the same parent node.
→ Optimization only for one edge case! → not a good idea!
New Solution
The new rendering is based upon mount-points, that are always represented by a dedicated tag within the DOM tree! The dynamic content is then rendered below this mount-point-tag. This is true for all render variations, so for
render
as well as forrenderEach
variants.To be more precise, there is one
div
-tag inserted at the location where therender
method is called:This will result in the following DOM structure:
The CSS class
mount-point
makes thediv
"invisible" to the client (bydisplay="contents"
), the data attributedata-mount-point
is primarely added to support readability or debugging.It is worth to emphasize, that this mount-point-tag remains under full control of the framework. So all rendered tags below this tag, will be cleared out every time a new value appears on the flow. So do not try to use or touch this tag or any child from outside of the
render
function!This works similar for dynamic lists:
Which will result in this DOM structure:
Recipe: Mixing dynamic and static content within the same level
If it is absolutely clear that the mount-point will be the only element of some parent tag, then the render methods offer the optional
into
parameter, which accepts an existingRenderContext
as anchor for the mount-point. In this case the rendering engine uses the existing parent node as reference for the mount-point:This will result in the following DOM structure:
If you are in a situation where you absolutly have to mix static elements with dynamic (flow based) content within the same DOM level, then the new rendering offers a solution too: Try to integrate the static aspect within a
map
expression!Let's consider the following example sketch we would like to achieve:
The simplest solution would be to just call the
renderEach
method directly within the<ul>
context after the static<li>
portions. But this would violate the constraint, that all<li>
tags must appear on the same DOM level (refer to the first example output to see, that an extra<div>
would be insterted after the static portion).So the correct way is to provide the
into = this
parameter in order to lift up the dynamic portion into the surrounding<ul>
tag and to integrate the static portion within the flow by somemap
expression:The result is exactly the same as the scetch from above.
You might habe recognized that the
into
parameter could be omitted, if the extra<div>
does not affect the overall structure (in this case all<li>
elements would still remain on the same level within the DOM!).Migration Guide
For the most if not all parts of your application nothing has to be changed!
So first of all please compile and test your application. If there are no compiler errors and the application appears and functions as it did before, do nothing!
There are only few exceptions to this rule:
renderElement
does not exist anymore. You will get compile errors of course, so this is easy to detect. Change all occurrences torender
instead to solve this problem. If needed, apply the next two patterns on top.into = this
parameter at the render functions calls.map
as shown in the recipe section before).StackUp
orLineUp
component with dynamic content, make sure to set theinto = this
parameter in order to make thespacing
property work again.Further Information
For more details have a look at the documentation
fixes #531
fixes #405
fixes #346
fixes #538