What about adding another root function to allow d...
# kvision
t
What about adding another root function to allow directly bind the state (like other components have)? It would simplify this:
Copy code
root = root("root") {}.bind(Store) { s ->
  if (s.appInitialized) {
    simplePanel { ... }
  } else {
    div { content = "Loading..." }
  }
}
r
The question is do we really want to suggest users, that binding the whole app like this is an optimal solution 🙂
t
Probably not, but what about using store subset?
Copy code
root = root("root") {}.bind(Store.sub { it.appInitialized }) { s ->
            if (s) {
                simplePanel { ... }
            } else {
                div { content = "Loading..." }
            }
        }
r
Personally lately I like chaining, explicit syntax better. I even consider deprecating direct state parameters and dropping them in the next major release 🙂 So I would probably like this better:
Copy code
root("root").bind(Store.sub { it.appInitialized}) { s ->
// ...
}
than this:
Copy code
root("root", Store.sub { it.appInitialized }) { s ->
// ...
}
The first approach would just require allowing nullable
init
parameter.
👍 1
t
ok, lets do it
I have another related idea:) I thing it would be usefull to have an option not to call the binding lambda at the time of binding. something like:
Copy code
div().bind(State, runImediatelly = false) {...}
r
It would require some work. Currently the initial immediate call is coming from `ObservableState`'s internal behavior. We would have to expand this interface with another method or another parameter to
subscribe
.
It would be a breaking change in both cases.
I've implemented this in a
kvision_5
branch with a simple condition based on a local variable, without touching
ObservableState
interface. Seems to work fine in my tests. https://github.com/rjaros/kvision/commit/0f60938e996e903be811be100a6e58f034cb14be