Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Reactive Architecture Boston Droidcon

HIFILEO
March 27, 2018

Reactive Architecture Boston Droidcon

Presentation given at Boston Droidcon about Reactive Architecture.

HIFILEO

March 27, 2018

Transcript

60 slides
  1. Kudos • Managing State with RxJava - Jack Wharton •

    The Rx Workflow Problem - Ray Ryan • Reactive Clean Architecture - Lucia Payo • Don’t Break The Chain - Dan Lew
  2. Goal • Define it • History Lesson • Rx Problems

    & Solution • Think in Images, Dream in Code
  3. MVVM Rx Problem Unless you can model your entire system

    synchronously, a single asynchronous source breaks imperative programming. Jake Wharton - Managing State with Rx
  4. MVVM Rx Problem .doOnNext(loadMoreCommand -> { loadMoreEnabledBehaviorSubject.onNext(false); if (loadMoreCommand.getLoadMoreType() ==

    SCROLL) { adapterDataPublishSubject.onNext(AdapterUiCommand.createAddNull()); movieViewInfoList.add(null); } } }) .observeOn(Schedulers.computation()) .flatMap(loadMoreCommand -> serviceGateway.getNowPlaying(++pageNumber)) .delay(sleepSeconds, TimeUnit.SECONDS) .flatMap(new NowPlayingViewModel.MovieListFetcher()) .flatMap(new TranslateForUiFunction()) .doOnError(throwable -> pageNumber--;) .observeOn(AndroidSchedulers.mainThread()) .doOnNext(movieViewInfos -> { if (!firstLoad.get()) { movieViewInfoList.remove(movieViewInfoList.size() - 1); adapterDataPublishSubject.onNext(AdapterUiCommand.createRemoveNull()); } }) .onErrorResumeNext(movieViewInfos -> { showErrorPublishSubject.onNext(true); loadMorePublishSubject.onNext(new LoadMoreCommand(SCROLL)); }) .subscribe(movieViewInfos -> { movieViewInfoList.addAll(movieViewInfos); adapterDataPublishSubject.onNext( new AdapterUiCommand(AdapterUiCommand.CommandType.ADD, movieViewInfos)); //address first load //… //enable scroll }
  5. Deep Dive • As a user, show a list of

    "Now Playing" movies. Poster, Title, Release Date, & Rating. • As a user, any rating at eight or above should be stared. • As a user, I only want to see ratings rounded to the nearest whole digit. • As a user, while scrolling, keep loading "Now Playing" movies until you hit the last page. • Example #1
  6. Deeper Dive • New requirement • As a user, restore

    the last page I was on when the "Now Playing" screen restarts. • Example #2
  7. We Need To Go Deeper • New Requirement • As

    a user, I want to filter my results based on Rating. • Note - Filter at any moment.
  8. { We Need To Go Deeper Concat + Publish Filter

    Result Filter On / Off }Observable.merge<Result>
  9. We Need To Go Deeper • So let’s look at

    code for the: New Requirement • Example #3
  10. Summary • Read, Watch, Repeat… • Remember (Like Redux) •

    Save State using UiModel • Don’t break the stream • Do you need a subject? • Speed Increase + Quality Increase

More Decks by HIFILEO

Other Decks in Technology