THIS Flow Mistake Will Lead to Bugs in Your Code (StateFlow & Reactive Programming)

THIS Flow Mistake Will Lead to Bugs in Your Code (StateFlow & Reactive Programming)

Philipp Lackner

1 год назад

27,649 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@eduardoscaranari5262
@eduardoscaranari5262 - 09.11.2023 04:07

this is fantastic. thanks for such amazing content Philipp. 🤝

Ответить
@foivosstamopoulos4106
@foivosstamopoulos4106 - 26.08.2023 22:58

Great tutorial as always!!

Ответить
@abdurahmon2827
@abdurahmon2827 - 19.08.2023 20:37

Thanks bro you are life saver

Ответить
@valtteri_its_james
@valtteri_its_james - 06.07.2023 09:01

Mate, you are legend

Ответить
@Alchemist10241
@Alchemist10241 - 11.06.2023 07:10

I also learned a lot of new methods like maxByOrNull thanks

Ответить
@AmitJayant
@AmitJayant - 14.05.2023 19:30

In the combine example, isLoggedIn, chatMessages & users have default values. They will never change.
How to make them get data from database?

Ответить
@carlosmspk
@carlosmspk - 21.04.2023 11:33

in that last example, I don't understand why you say "Else we'd have to recalculate everything when any of the parameters changed". Isn't that what's happening anyways?
Isn't there a way to also get WHICH of the combined parameters changed? We might be talking about a very long list, and I don't want to recompute the entire thing if another, unrelated variable changed which would only change the variable in an easy to compute way (imagine, it'd only change a color, not the value of the list, or something similar)

Ответить
@tsmusic9587
@tsmusic9587 - 07.04.2023 05:31

u so handsome :*

Ответить
@czerewacz
@czerewacz - 07.03.2023 19:27

Phillip the G.O.A.T !!!

Ответить
@norayrmovsisyan
@norayrmovsisyan - 19.01.2023 10:27

thank you very much!

Ответить
@LightBueno
@LightBueno - 22.12.2022 17:46

legend

Ответить
@asadullahilyas
@asadullahilyas - 26.09.2022 20:48

I was making the same mistake..
I’ll get it fixed tomorrow as soon as I get my hands on that laptop

Ответить
@original_anu
@original_anu - 26.09.2022 15:29

This could be a good hint by IDE. When you are using state.value in operators like combine, suggest using that state in the dependents list
Similar useEffect with useState in react.

Ответить
@MyFoenix
@MyFoenix - 25.09.2022 23:54

Also, as mentioned above, I tried to change flow value in a viewmodel and combine did not fired. It was only fires when items goes from repository for example

Ответить
@MyFoenix
@MyFoenix - 25.09.2022 23:49

Hi! Did you try to combine more then 5 values? When I tried I got an error about types...

Ответить
@yeyaanshkit
@yeyaanshkit - 25.09.2022 10:17

Hi Phillip, please create a fresh Series of Android Development for beginners.. Please the Updated one..

Ответить
@summerwise
@summerwise - 24.09.2022 14:30

Hello, could you make a video about navigation with TopBar? I mean how to change topBar title and back button after changing our screen. In xml we can bind our toolbar to navgraph, idk how to do that on jetpack compose in right way.

Ответить
@tabassumfatima2398
@tabassumfatima2398 - 24.09.2022 09:54

Best video really like your content 👍

Ответить
@mohammedalramlawi691
@mohammedalramlawi691 - 24.09.2022 09:17

combine is very usefull, I loved it 🤩

Ответить
@Narslimmus
@Narslimmus - 24.09.2022 03:50

Oh man I was actually making this mistake a lot in my project, thanks for making this video :)).
Quick question, is there any advantage to using stateFlow instead of regular states/flows when working with compose only?

Ответить
@MrVipulLal
@MrVipulLal - 24.09.2022 01:42

Love your channel

Ответить
@bofu9662
@bofu9662 - 23.09.2022 17:30

Thanks a lot!

Ответить
@gerondkwenda
@gerondkwenda - 23.09.2022 14:56

Thanks for the great tutorial.

Ответить
@issamkerfah2407
@issamkerfah2407 - 23.09.2022 10:43

I would recommend passing the timeout as first parameter to SharingStarted.WhileSubscribed(), something like 2 seconds. this will ensure that the flow will not stopped and gets recalculated after screen rotation but instead it will stop if the app is in background.

Ответить
@omkarpawar1741
@omkarpawar1741 - 23.09.2022 06:49

can you provide a tutorial about mutablestatelistof with jetpack compose

Ответить
@ChrisAthanas
@ChrisAthanas - 23.09.2022 01:03

Phillip, bc there was not a github link to the code, I wrote the code you have here into a project. The first example worked fine, but the second example (with the combine) only accepts the initial state for the chatState StateFlow. All additional `user.update{ it + user }` or `chatMessages.update { it + message }` do not emit additional ChatStates via the `combine`.

It looks like this doesn't work as described.

You should always run your code in these examples to be sure they are working as intended!

It seems that the `combine` flow will not be re-triggered unless the values of the StateFlow variables change. Since the `List<ChatMessage>` does not change (only the contents of list change), the `combine` is never triggered. You will need to wrap the Lists and add a UUID (any random UUID) that indicates the underlying list has changed in order to trigger the `combine` to re-emit a new value. Thats the only way I could get this example to work.

Ответить
@mdisi5967
@mdisi5967 - 23.09.2022 00:39

Does live data have anything like this 🤔

Ответить
@pinoy_marites_beh
@pinoy_marites_beh - 22.09.2022 13:35

I tried exactly what you did in your example @Philipp, but it only updates the second flow (localUser) once, and every time I do something on the "_users" parent flow, the "localUser" flow doesnt get updated..

Ответить
@quantumgaming7
@quantumgaming7 - 22.09.2022 13:20

Really Nice Tips. Thanks for this.

Ответить
@iga137
@iga137 - 22.09.2022 10:42

Hi bro, please, make a video about the new logcat in AC)

Ответить
@skarloti
@skarloti - 22.09.2022 10:34

mutableStateListOf<User>()
instead
MutableStateFlow<List<User>>(emptyList()>
unless I want to use sealed class ResultOf<T> and get statuses for Loading, Error, Succes. Only in this case would I use Flows.

Ответить
@abiodunmoses2638
@abiodunmoses2638 - 22.09.2022 10:20

You keep giving me reasons to no longer use Compose States. Thank you.

Ответить
@shaiquekhan1185
@shaiquekhan1185 - 22.09.2022 06:50

what's your studio's theme? looks pretty cool.

Ответить
@ChrisAthanas
@ChrisAthanas - 22.09.2022 02:52

Phillipp, it would be helpful to us if you turned on `inlay hints` so we can see the types of your variable as opposed to having to manually select "type info"

Ответить
@nguyencodervn
@nguyencodervn - 22.09.2022 02:51

Thank you

Ответить
@s-w
@s-w - 22.09.2022 01:00

Thank you for the tips as usual!

Ответить
@mustafaammar551
@mustafaammar551 - 21.09.2022 21:29

you are the best

Ответить
@alicjamruk8446
@alicjamruk8446 - 21.09.2022 21:07

I really like your videos, they are very informative, but could you please be aware of using 'actually', it happens too often.

Ответить
@ruavaen
@ruavaen - 21.09.2022 20:46

Great video. Thanks

Ответить
@Khaled_Ahmed_Elsayed
@Khaled_Ahmed_Elsayed - 21.09.2022 20:05

But this isn't related entirely to flows, you are just stating the single responsibility principal, and avoiding coupling 2 variables in 1 function, isn't it?

Ответить
@TheAndroidFactory
@TheAndroidFactory - 21.09.2022 19:57

Love combine!

Ответить
@ukhanyov
@ukhanyov - 21.09.2022 18:58

Awesome, thank you

Ответить
@mark-147
@mark-147 - 21.09.2022 18:54

Excellent, thanks. Would be interested in some practical use cases where other SharingStarted values are used.

Ответить
@GilTheCohen
@GilTheCohen - 21.09.2022 18:46

Why are you not using mutableStateListOf ?

Ответить
@stanleykou5643
@stanleykou5643 - 21.09.2022 16:58

Wow

Ответить
@datel666
@datel666 - 21.09.2022 16:20

Great video as always

Ответить
@laszloforgacs8210
@laszloforgacs8210 - 21.09.2022 16:09

Very informative, I dig the recent topics on the channel!

Ответить
@samstoyroom
@samstoyroom - 21.09.2022 15:47

What's the difference between map{} and mapLatest{} ?

Ответить
@irsathkareem7513
@irsathkareem7513 - 21.09.2022 15:43

Please make video on exoplayer with compose ui CONTROLS, eagerly waiting

Ответить
@sabuta100
@sabuta100 - 21.09.2022 15:30

I know Rx is not that popular now that flows are out there, but it would be great if you make a series explaining operators and how to combine them. Your ability to teach and the effort behind that is so incredible that learning such a painful topic as Rx might be, would make it easy to understand. Thanks for all your videos!

Ответить