Hi all, I've been learning about Compose and found...
# compose
j
Hi all, I've been learning about Compose and found the docs make an incorrect claim that they are pure functions: https://android.googlesource.com/platform/frameworks/support/+/androidx-master-dev/compose/README.md I've sent a pull request to fix that: https://android-review.googlesource.com/c/platform/frameworks/support/+/958319 Would be great to get someone to review that.
πŸ‘ 5
c
+2
j
Thanks!
j
Yes I was also thinking that during presentation
c
The point we were trying to make is that the only side-effect the function should have is producing the tree. There isn't really a well understood term for that. The closest is monad but then only 5 people know what that means.
☝️ 4
j
Why not: fun Greeting(name: String): Composable { return Text(text = "Hello $name") }
🚫 1
πŸ’― 1
😱 1
t
@Chuck Jazdzewski [G] partially pure functions, then?
πŸ‘ 1
g
The closest is monad but than only 5 people know what that means
But who would think that so many people know what pure function means and now they are giving you hard time for not being transparent... referentially 🧌
r
@themishkun Pragmatically pure :)
simple smile 5
@ghedeon James doesn't count, he's a fan of Scala :)
πŸ‘ 3
t
@romainguy yeah, kotlin fans LOVE the word "pragmatically" :)
c
@Jeremy That would work and is the approach take by React and Flutter. However, there is more opportunity for optimization along the line we took. For example if "name" is the same on recomposition we can skip the call entirely. We don't need to compare its result from last time to tell that it doesn't change. This is similar to the approaches taken by, for example, Ember and Angular.
πŸ€” 1
βž• 2
☝️ 2
t
@Chuck Jazdzewski [G] is this really takes so much work to compare two `id`s in two generated data structures? In my team most screens consist of root recyclerviews with adapters for buttons, galleries, texts and titles, etc. and we see no perfomance impact on that.
j
πŸ€” I think I just need to dig into more. Its just less clear from example what its actually doing
c
The
RecyclerView
is doing a lot of work behind the scenes to deliver this performance.
j
Is there any examples of unit tests? If multiple tests are executing does any global state need to be reset?
πŸ‘ 1
c
@Jeremy There are many unit tests in the repository and they can be found in the
androidTest
directory of the various modules. The memoization information is stored in the composer's slot table and is local for the composition. It is not global. However, currently we use a global to simplify the code generation of composable functions so only one composition can be occurring at a time. We plan to change this to rewrite composable functions to take the composer as a parameter. This will remove global as well as speed up composition.
j
Thanks for response. I'll dig through the androidTest code a bit more
So api would be : fun Greeting(name: String, compose: Composable) ?
c
There will be a synthetic function produced with the parameter. The API will remain that same at the source level. We will redirect calls to composable functions to the synthetic.
πŸ‘ 1
j
Sorry I missed the chatter here. It's definitely not monadic either. I don't think we should try to use any FP terms since the FP zealots will freak out. I'm not quite a zealot, just an advocate of using terms correctly.
I don't know what is really going on with Composable but it does seem like the API could use an IO Monad instead but you would need a return statement which I'll admit doesn't seem as nicely declarative as what exists today.