Тёмный

Managing State with RxJava by Jake Wharton 

Devoxx
Подписаться 157 тыс.
Просмотров 107 тыс.
50% 1

Please subscribe to our RU-vid channel @ bit.ly/devoxx-youtube
Like us on Facebook @ / devoxxcom
Follow us on Twitter @ / devoxx
RxJava's use in building Android apps has grown rapidly! Combining and composing synchronous and asynchronous sources of data has become easy. That burden that remains is where to put the overall state of the application and how to handle its changes. This talk will be an exploration in how we can increase the confidence and determinism of our app state.
Because Rx isn't specific to Android, we'll look at state management approaches employed by other platforms and languages and whether or not they're appropriate to use. We will also look at how state management fits into application architectures such as MVP and MVVM.
Attendees of this talk should already be comfortable with reactive programming and RxJava's APIs.
Jake Wharton is an Android developer at Square working on Square Cash. He has been living with a severe allergy to boilerplate code and bad APIs for years and speaks at conferences all around the world in an effort to educate more about this terrible disease.

Наука

Опубликовано:

 

12 апр 2017

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 98   
@MohamedISoliman
@MohamedISoliman 5 лет назад
watched this for 4th time, and still amaze me
@nullpointerE
@nullpointerE 7 лет назад
One of the best talks that demonstrates the actual advantages of reactive programming. Very deep.
@AnitShrestha
@AnitShrestha 6 лет назад
Although got to watch it a year after, I loved the way everything was presented! Very neatly put the code with the descriptive explanation of the complicated concepts. Thank you very much!
@MauroBanze
@MauroBanze 5 лет назад
Awesome talk. I love how you explained the problem in detail, makes it super simple to get the point of the talk. Also the slides and animations are very useful in aiding comprehension. Thank you Jake
@igorg.8624
@igorg.8624 6 лет назад
Essentially what was described in this video is an event bus implemented in RxJava. Having done a similar implementation for my own project recently, I started to appreciate Rx for this approach...
@joney78
@joney78 3 года назад
Would love to see this approach using kotlin coroutine's flow api.
@lancecarl8649
@lancecarl8649 2 года назад
Instablaster
@necroCODE
@necroCODE 5 лет назад
I love how he explains things, Jake Wharton would be a great teacher!
@roxferesr
@roxferesr 7 лет назад
Awesome talk Jake! Thanks for explaining a relatively complex subject so simply. One thing I didn't get though is, how is the observable subscribing conf changes, rotations? provided that we are not using subjects "there's no subjects, there's no relays, there's none of these things that are ... not the ideal way of representing state"
@amintalukder7189
@amintalukder7189 9 месяцев назад
By far the great presentation and so rich materials... Great ....
@KENTOSI
@KENTOSI 4 года назад
What an amazing talk! So in depth and clear. Well done.
@tillsimon9543
@tillsimon9543 7 лет назад
Unfortunalety he forgot to mention how to handle the case where an event supersedes another (37:48). Any hints what RX-technique he was gonna refer to?
@shuwushu
@shuwushu 2 года назад
One of the most inspiring video I have seen about Rx
@UkrainianGuitarHero
@UkrainianGuitarHero 5 лет назад
The UI has 2 responsibilities: producing events, and rendering the results. Both require state management. This approach only solves the rendering part of the state problem by "scanning" results into a model that's stored inside the stream. Now, let's say we have a button that increments a counter. And then there's another button that needs to take the count and send it to the server. Where do we get this value? As I see it, we have 2 options: 1. Store the count (or the entire model) in a variable in the UI class (Fragment) 2. Store the model down stream (next to the scan function) and allow upstream to yank into it at any time The second option is definitely bad since it breaks the unidirectional data flow concept. The first option kind of makes sense, but I'm wondering if there's another way.
@PraveerGupta
@PraveerGupta 7 лет назад
A complex topic explained very nicely and made easy to understand... Thanks..
@igorg.8624
@igorg.8624 6 лет назад
Easy to understand? Nothing about Rx is easy
@ukasztrojanowski3149
@ukasztrojanowski3149 6 лет назад
On a side note. What would be a good program to make slides like these?
@aandhereitgoes
@aandhereitgoes Год назад
We'll edit this in post :D
@shivangtrivedi3130
@shivangtrivedi3130 6 лет назад
Can I initialize interface object? I didn't get very first example
@mankinPT
@mankinPT 7 лет назад
"Will edit this in post" lol :)
@sirajuddaula2169
@sirajuddaula2169 4 года назад
i am wondering "user interface is essentially itself an asynchronous source" (06:01). Someone who can help me?
@andrewbeechey4402
@andrewbeechey4402 5 лет назад
When can we enjoy Part II and/or GITHUB example based on the ideas presented here? @Jake Wharton
@poetichustla13
@poetichustla13 7 лет назад
should be: if( !isDestroyed() ) { ... }
@bedprakashrout
@bedprakashrout 7 лет назад
SIdeEffects - AFAIU Side effects are accessing some data outside the stream. In the at 29:39 the map operator is also causing side effect by accessing view directly. Also the service is also not part of the stream used in the bellow flatmap. Am I missing something here?
@santoshkumardhanyamraju517
@santoshkumardhanyamraju517 7 лет назад
I think if the code is map operator is accessing data outside stream directly or indirectly (by calling another method), it will cause a side-effect.
@adventuresofjam6873
@adventuresofjam6873 7 лет назад
He is presenting the solution as a gradual refactor. You can't just take a screengrab and say that Jake is suggesting this is final or even that it will compile. He later refactors the this getText fetch by passing in all data needed for the action to start the stream. As far as side effects, he was especially speaking about the doOnNext operator since the doOnX family of operators simply does a thing depending on the stream state (Error, completed, next) and doesn't directly impact what is being propagated in the stream itself.
@grzegorzdvipek
@grzegorzdvipek 7 лет назад
I agree. 29:39 is already AFTER the refactoring. Thus I don't understand why Jake is not using his own library (RxBinding) to write something much more reactive like: .withLatestFrom(nameView.textChanges(), ...) instead of this map(). My general impression is that people don't know how to COMBINE streams to create the proper app logic.
@euleramon
@euleramon 3 года назад
Could someone tell me how the slide is made ? The presentation way used in this slide is really awesome !
@amirmuhsin
@amirmuhsin 2 года назад
He is using Keynote. The animations are called "magic".
@TheBreezerFly
@TheBreezerFly 6 лет назад
39:53 why use scan and not map? You are not using the accumulated state at all.
@vinaynagaraj4638
@vinaynagaraj4638 7 лет назад
Why do you unify `submitEvents` and `checkNameEvents` into a single `events` observable, then split them again with `publish()` and `ofType()`, when you can skip that and straight away do Observable.merge( submitEvent.compose(submit), checkNameEvent.compose(checkNameEvent)) to get a single observable stream the UI can subscribe to?
@arturdumchev3055
@arturdumchev3055 6 лет назад
because ofType operator creates new subscription. With publish you have connectable observable as a parameter, so onType doesn't creates more than one subscription. You can test it with Observable
@chaitanya04223
@chaitanya04223 7 лет назад
Which software is used for preparing this presentation.
@harshitbangar123
@harshitbangar123 6 лет назад
Keynote. jakewharton.com/the-conference-speaker-investment/
@kirillzhukov2407
@kirillzhukov2407 6 лет назад
Slides available here: speakerdeck.com/jakewharton/the-state-of-managing-state-with-rxjava-devoxx-us-2017
@sukram1998
@sukram1998 7 лет назад
Why is something like RxView.click(...) needed? What's the difference using a default click listener and implement the rest of the RxStuff there? I am quite sure I am missing something.. thank you anyway and good talk as always!
@Tubcio123
@Tubcio123 7 лет назад
RxView.clicks creates observable and emits events for you. Otherwise you would have to put unnecessary observable inside of a view and emit events yourself, it is boring task and can be simplified with such library as RxBinding. It is especially considerable difference when you've got complex ui and a lot of different events
@DanieleSegato
@DanieleSegato 7 лет назад
This question is for Jake, but not sure he'll ever read it. I've build an architecture very similar to the one you explained in this video but I didn't use the publish operator and I do not understand how you exactly use it to achieve the activity lifecycle independency of the data layer. Do you have a sample project to show so I can understand it better myself? thank you.
@cccc2740
@cccc2740 3 года назад
If everything is asynchronous, is here anything which is synchronous?
@zbynekjuros5139
@zbynekjuros5139 5 лет назад
I need this guy in my office.
@b.k4142
@b.k4142 5 лет назад
Hi everyone is important for beginner to master Rx java or LiveData ??? thanks!!
@GiorgiPeranidzeOriginal
@GiorgiPeranidzeOriginal 5 лет назад
no
@MatteoSomeSomensi
@MatteoSomeSomensi 7 лет назад
I don't understand the use of publish operator here: ObservableTransformer submitUi = events -> events.publish(shared -> Observable.merge( shared.ofType(SubmitEvent.class).compose(submit), shared.ofType(CheckNameEvent.class).compose(checkName))); Someone who can help me?
@iamvlad
@iamvlad 6 лет назад
The purpose is to split the events in the stream by event subtype, and pass all events in the stream of a given subtype as input to processor (ObservableTransformer). Then, the output streams of each of these specialize processors is merged back into one stream.
@ossamabounnite4922
@ossamabounnite4922 4 года назад
I've made this repository (github.com/OssamaDroid/ManageStateWithRxjava) for people interested in learning more about this pattern. It uses the same example from the talk.
@johnnyshoes3708
@johnnyshoes3708 7 лет назад
Yes, Pedro ( below ) is asking where does this fit inside a MVC/MVVM layout? Do we keep the Views thin, or now, jam everything back into the View? Over to you Jake!
@lanreakisanya5760
@lanreakisanya5760 7 лет назад
Is there a github project associated with this video please?
@JimAndreas
@JimAndreas 7 лет назад
I have forked his repo and have modified it to use the Android Studio native J8 processing, available if you download the 2.4 preview (currently pre-Beta). I also updated it to use RxJava2. The state of the demo code is about where Jake Wharton begins his talk here. I will experiment with his suggestions using my fork of Patrick's example. Here is a link: github.com/jimandreas/android-rxmvp-tutorial
@christianwheeler8441
@christianwheeler8441 6 лет назад
Link is down. Any chance you still know of an example repo somewhere?
@iamvlad
@iamvlad 6 лет назад
github.com/oldergod/android-architecture
@Sandip0892
@Sandip0892 4 года назад
@@kirillzhukov2407 The first one is no longer available and second isn't what was presented here because have a look at this line: github.com/patrick-doyle/android-rxmvp-tutorial/blob/fb6daa20071bdbbb9d17470bb618c69794529feb/app/src/main/java/com/twistedeqations/rxmvp/sample/activities/home/mvp/HomePresenter.java#L36 It uses side effect to change the ui state to loading which goes against to this presentation.
@uragannn
@uragannn 6 лет назад
Thank you, Jake Wharton!
@wyattberlinic1353
@wyattberlinic1353 6 лет назад
Are these slides available?
@kirillzhukov2407
@kirillzhukov2407 6 лет назад
speakerdeck.com/jakewharton/the-state-of-managing-state-with-rxjava-devoxx-us-2017
@70ME3E
@70ME3E 5 лет назад
-inProgress- isInProgress -success- isSuccessful
@Mgc28
@Mgc28 7 лет назад
The way Rx models this is amazing but i'm currently having issues associating this with some design model as Mvvm ou Mvp. As far as I understood, in some way, everything is done in the View, even with the separation between Actions and UiModels. What I mean by this is that, for example the view has the service (service.setName) which is making an API call. Should this be in, someway, modeling to a Mvp or Mvvm? Or is it that with Rx and the way it works, both presenters or view-models are removed from the architecture? Then again: Might just be me completely misunderstanding the concepts :) So if some one could enlight me on this I would really appreciate.
@ahmednawara2973
@ahmednawara2973 7 лет назад
The view wouldn't have the service. The transformers that would be used are separate files that can be injected into the Activity/Fragment/View and used in the composition of the Rx chains. Furthermore, part of the chain, particularly the observables making those API calls live outside of the Activity and are cached so that an activity can re-hook into them later. It may have looked like all of that stuff lived in the view cuz the view code was refactored onto the same slide but Jake mentioned that those become transformers independent of the view and hence can live in their own classes that you can test in isolation.
@OlsiSaqe
@OlsiSaqe 7 лет назад
Pedro Glória this to me seems more like a Redux. Btw I still didn't understand how it is supposed the DataLayer to long live when phone is rotated and activity is destroyed. Maybe he was referring to fragments with retain instance state?
@Zhuinden
@Zhuinden 7 лет назад
Don't put your data layer into your Activity. And the reason why MVP doesn't seem to model it well is because this is basically MVVM where instead of having a single instance of a view model, you represent it as an object that you create immutable copies of and send each instance through a stream that you subscribe to.
@VladimirDjokic
@VladimirDjokic 4 года назад
This is a great presentation really thank you ! I really meant. But after 10 years on Android that I have spent and only 3 months on flutter UI toolkit, pardon me, but forget Android UI tool kit and let's embrace Fluuter UI tool kit :-) . FLuuter is amazing piece of technology and for example, this with rx in Android, in Flutter is called BLoC and it is much better integrated in to UI . So @Jake Wharton I know that you have a lot of followers and people respect you, so start publishing videos about flutter and tell them to forget Android UI tool kit and let's start enjoy the life with flutter! Sorry for this comment :-)
@amirmuhsin
@amirmuhsin 2 года назад
Once in his tweet he said negative things about Flutter. He was also complaining about Dart
@VladimirDjokic
@VladimirDjokic 2 года назад
Yes I know , I don’t like dart language as well . But I like flutter and one code base it saves money and time!
@marko-lazic
@marko-lazic 7 лет назад
I liked
@phoenixwang1269
@phoenixwang1269 7 лет назад
finally!
@vasiliyzukanov9865
@vasiliyzukanov9865 7 лет назад
Jake always has the best slides when it comes to technical presentations and delivers like a boss ) The content, however, reinforced my opinion that RxJava is just a cool way to write spaghetti code. This entanglement between application's logic and framework's constructs is scary. That poor dude that will need to maintain Jake's code after he himself moves on...
@arunkumar9t2
@arunkumar9t2 7 лет назад
Well the entanglement is not necessary. If you use MVP + Clean then you have clear separation of concerns between layers. I find it easy to have my domain layer expose Observables instead of traditional callbacks. If anything, I find the Rx way to be more maintainable when I have lot of async code. I am rather curious to know your expanded thoughts on why you think its not maintainable.
@vasiliyzukanov9865
@vasiliyzukanov9865 7 лет назад
Arunkumar let's discuss in context of real code. My approach to MVP is summarized here: techyourchance.com/. When I had to ramp up new team member on codebase that used this approach it took few hours to explain MVP and why Activities are not views, and that's it - new developer is on board and productive. If you use the same approach, but add rx sugar on top, then it will take several days to weeks to ramp up new team member (unless he is pro in rx). In addition, all these subtle bugs that Jake showed in video are really subtle, which will make debug harder. And think what will happen if/when Jake moves on... Maybe there will be someone stepping in as a leader. But it is also possible that rx will no longer be that new shiny thing, and other contributors will move on too. The main issue with rx is that it is too intrusive - there is no easy way to refactor the code (and tests!) to non-rx, therefore using Rx basically means that you voluntarly tie your app's fate to the fate of a library that has no official support.
@johnysnowy35
@johnysnowy35 7 лет назад
Rx is not just a library. It's a way of thinking. Your argument about Rx being unpopular tomorrow can go for anything, does that mean we shouldn't try anything new? There's a big community around this, it's not going away any time soon.
@vasiliyzukanov9865
@vasiliyzukanov9865 7 лет назад
Arthur Sa​, personally, each time when I try new things I try very hard to forsee what the long term implication will be. Not for me, but for my employer and the project (unless it's my project in which case I can do whatever crazy things I want). I use many third party tools, but all of them are decoupled in a sense that it will take no more than one-two weeks to replace them if anything bad happens. As for whether Rx is going away any time soon - it depends on your definition of soon. 1 year? Probably not. 10 years? Probably yes. Entire languages were abandoned by the community. As for popularity, I invite you to take a look at Universal Image Loader - once the most popular library for Android, which is not being maintained now.
@JakeWharton
@JakeWharton 7 лет назад
Feedback from implementation over the last year has generally been the opposite. Since everything exists inside a stream every problem can be traced to an event, action, result, or model which are trivially observed from the outside. Data flow and state management is actually easier to understand because it's not scattered and imperatively managed. Your comment sounds like someone who loves riding horses lamenting the onset of automobiles. Until you've actually built something large with this approach, I'm afraid your overly-general fear-mongering comment reads emptily.
@CodyEngel
@CodyEngel 7 лет назад
This wasn't fixed in post. WTF?
@andrzejx2139
@andrzejx2139 7 лет назад
It's overcomplicated..
@vipinkumar7230
@vipinkumar7230 6 лет назад
extremely complicated
@jamesandresakis4871
@jamesandresakis4871 7 лет назад
Need busy work much ;)
@nyarian835
@nyarian835 5 лет назад
if-else wall looks ugly anywhere, because it is ugly design. just because kotlin makes in more concise doesn't mean that it is nice. kotlin's `when` example can possibly make somebody think that any solution's quality depends on language, and, more awful, that rotting design is actually a good one when it is short
@stanislavdimitrov8800
@stanislavdimitrov8800 4 года назад
Would you suggest a better solution to replace it in this case?
@DannTeBg
@DannTeBg 7 лет назад
Jesus fucking Christ, when you think things are not already complicated enough.... Great stuff though!
@johnnyshoes3708
@johnnyshoes3708 7 лет назад
I hate Android Studio. Everytime I add a line of code, I have to fight with the editor to import the right classes, or surround every damn line with a try-catch. My productivity has halved because I now use gradle, which compiles every time, whether I change the code or not. It takes minutes, every time, and then tells me, it took 7 secs. Yeh right. Android development sucks. And now it's getting worse, because geeks want us to use clever code, even though its not needed. There are how many libraries out there? 100s. Which do we use? It's all trial and error. Or jump onto the band wagon and use what's in fashion. Since, your super clever, Jake, tell us, since, most applications are similar. Give us the exact libraries to use. e.g. 2-way binding ( robobinding, etc ), butterknife, retrofit, dagger 2,Realm, blah, blah blah. Do we use MVVM, MVC, if so, where does all this nice code go? In the View layer? These libraries give us more questions than answers. Yours truly, Mr Angry!
@alexanderosmanov5743
@alexanderosmanov5743 7 лет назад
While there is some sense to what you are saying, I don't think you will get any answers with that attitude.
@FahadAyaz
@FahadAyaz 7 лет назад
You should enable auto adding unambiguous imports on the fly. Such a time-saver.
@adventuresofjam6873
@adventuresofjam6873 7 лет назад
Keep in mind that there are often good reasons for something in development to be 'in fashion'. It usually means that the thing is generically helpful in such a way that it can be applied to many different types of problems. So those are probably a good start. After that it's about what you want to accomplish - do you want to be able to TEST your code? If so, there are like four or five patterns right out the gate that will make your life way easier in Android. The, guess what, those four or five things are super common patterns and someone has written a reusable library for it.
@johnnyshoes3708
@johnnyshoes3708 7 лет назад
This is a joke right? This is supposed to make code better?
Далее
Christina Lee: Intro to RxJava
45:22
Просмотров 31 тыс.
Reactive Programming in Java by Venkat Subramaniam
52:20
Stray Kids "Chk Chk Boom" M/V
03:26
Просмотров 34 млн
How to Measure ANY Cliffs Height with a Rock
00:46
Просмотров 11 млн
10 Kotlin Tricks in 10 ish minutes by Jake Wharton
17:24
Go isn’t secure?!? feat. Low Level Learning | 053
51:14
The Future of Dependency Injection with Dagger 2
54:04
Understand Kotlin Coroutines on Android (Google I/O'19)
37:49
Droidcon SF - Common RxJava Mistakes
43:28
Просмотров 29 тыс.
DAGGER 2 - A New Type of dependency injection
40:16
Просмотров 234 тыс.
Why Did NOBODY Notice YOU'RE Autistic Before?
16:10
Просмотров 13 тыс.
Красиво, но телефон жаль
0:32
Просмотров 1,3 млн