Hi! Am I correct that Compose works only for funct...
# compose-web
t
Hi! Am I correct that Compose works only for functions but not for classes? I mean is it possible to use a class as a Composable? I worked quite a lot with React and I really didn't like when they started the shift to a function only approach. Seems good at first, but complicates things later.
a
Why do you need class?
b
To answer your question - no, compose is purely functional and declarative. If you want more imperative/class-based framework, have a look at kvision
t
Thanks for the answers. I know about KVision, actually I have my own, similar framework which is somewhat imperative / class based.
b
Doodle?
t
I don't really advertise it as the main goal was to support our own projects which it does.
I would like to use declarative UI, but I like classes as they let me organise the code much better than simple functions (been there, done that with react).
b
To each its own, I guess. I personally hate classes in react (or tornadoFX for that matter). Functions takes some getting used to, but once you get into a habit of making them pure and modular, they're much easier to manage and compose when compared to classes IMO
4
t
Even in Compose / Android there is viewmodels and such because many cases you do need a shared data. We have big, i mean BIG forms, there pure functions is a pain.
Anyway, thank you for the info.
s
Btw, (this is bad advice, but) you can use classes with Compose if you manage them with remember. The issue is that compose is made to work with functions anyway, so you have to come up with your own ways to handle component lifetimes, etc
👍 2
b
nothing stops you from passing a complex object into a function (as opposed to primitives) and still keeping it pure. I personally use redux pattern with compose, so most of my state is global (which does mean that my composables are not always pure, but it still keeps my app pure - for a given redux state, it will always behave the same)
c
Compose doesn't really know or care about classes itself, it is only concerned with function calls. Those functions can be defined at the top-level (which is most common) but it will work just the same having those functions grouped in top-level objects, classes (even
abstract
classes!), annotating property getter functions, interfaces, etc. It's all the same to Compose. Now the question of what Compose does with classes: absolutely nothing. You can use them purely for your own code organization, but Compose isn't going to call callbacks/render functions or anything automatically on them. They're purely a tool for you to better manage the web of
@Composable
function calls that a large app is going to create, but it's up to you to actually wire the two up.
t
Oh, this is interesting and opens up possibilities. Thanks for the idea.