fritz2 v0.8 Release Notes
Release Date: 2020-12-03 // about 4 years ago-
๐ฅ breaking changes
๐ This release contains changes that break code written with earlier versions. Hopefully these are the last major api-changes prior to fritz2 1.0:
Setting attributes per function
In fritz2 0.8 we decided to use functions to set attribute values instead of vars with delegation.
๐ That way you do not have to wrap constant values in aFlow
anymore. This yields better performance and theconst()
-function could be removed. For convenience reasons we also added a new functionasString
forFlow
s to
convert aFlow
to aFlow<String>
by calling thetoString()
method internally.input { type("text") // native value(myStore.data) // flow name(otherStore.data.asString()) // otherStore.data is not a Flow of String}
RenderContext
replacesHtmlElements
๐ We renamed the
HtmlElements
interface toRenderContext
, because we think this name better fits the Kotlin DSL approach.
The idea behind it is that everyrender
function creates a newRenderContext
in which
๐ newTag
s can be created. This also means that you must replace the receiver type in your custom component-functions accordingly:val errorStore = storeOf("some text")// own componentfun RenderContext.errorText(text: String): P { return p("error") { +text } } errorStore.data.render { //this: RenderContext errorText(it) }
โ Adding Text and Comments
We clarified the creation of TextNodes in
Tag
s. Now you use unary+
-operator for constantString
s
to append text at this position to yourTag
. If you have aFlow
, callasText()
instead.
To create a CommentNode, you can use the!
-operator andasComment()
analogous. This intentionally follows a different approach in contrast to the attribute functions so it can be distinguished more easily.p { +"Hello " myStore.data.asText() !"this is a comment" myStore.data.asComment() }
Evolution of
render()
andrenderEach()
๐ Using former fritz2-versions you mapped a
Flow
of data to aFlow
ofTag
s and created aMountPoint
explicitly by callingbind()
at some place in your rendering. This was error prone. Since nobody would do anything with aFlow<Tag>
other than binding it, allrender
functions now implicitly create the mount point and therefore nobind()
is necessary anymore. It has been removed completely.val myStore = storeOf(listOf("a","b","c")) render { ul { myStore.data.renderEach { li { +it } } // no .bind() here anymore } }
๐ For performance reasons the render-functions prior to version 0.8 did not allow more than one root-element. In version 0.8 the standard
render
allows you to add as many root elements to your context as you want or even none:val myStore = storeOf(42)// renders multiple root-elementsmyStore.data.render { repeat(it) { div { +"one more" } } }// does only render something if value is large enoughmyStore.data.render { if (it \> 100) { div { +"number" } } }
๐ If you you do not need this feature (because you know you will always have exactly one root-element) use
renderElement()
instead to get (slightly) improved performance.๐
render()
andrenderElement()
now reserve their place in the DOM until the content is rendered by using a temporary placeholder. Since this costs some performance you can disable it when you are sure that there are no sibling-elements on the same level in your DOM-tree by settingrenderElement(preserveOrder = false)
. Use this when you have to render lots of elements (in huge lists, tables, etc.).Instead of
someListFlow.each().render {...}.bind()
you now simply writesomeListFlow.renderEach {...}
. This is analog for all flavors ofrenderEach
onStore
s andFlow
s with and without anidProvider
.
Please note thatrenderEach()
still allows only one root-element (likerenderElement
)!Tracker offers
Flow<Boolean>
๐
Tracker
now implementsFlow<Boolean>
instead ofFlow<String?>
so it adopts better to most use-cases. Find an example here.๐ new features
๐ improvements
- โก๏ธ update all dependencies to latest version PR#166
- extend Router functionality PR#197
- โฌ๏ธ upgraded Dokka-version and moved to html for api-docs PR#194
- annotation processor visibility option PR#178
- โ use local test server PR#165
๐ fixed bugs
Previous changes from v0.7.2
-
Small patch resolving a memory issue related to coroutine scopes.