<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Laimonas Turauskas on Medium]]></title>
        <description><![CDATA[Stories by Laimonas Turauskas on Medium]]></description>
        <link>https://medium.com/@ThatLime?source=rss-eeb6311ddecd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*QSZwyt-1PdMSGmf7.jpeg</url>
            <title>Stories by Laimonas Turauskas on Medium</title>
            <link>https://medium.com/@ThatLime?source=rss-eeb6311ddecd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 03:08:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ThatLime/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[What the Formula? Managing state on Android]]></title>
            <link>https://tech.instacart.com/what-the-formula-managing-state-on-android-f5569ce09274?source=rss-eeb6311ddecd------2</link>
            <guid isPermaLink="false">https://medium.com/p/f5569ce09274</guid>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[rxjava]]></category>
            <dc:creator><![CDATA[Laimonas Turauskas]]></dc:creator>
            <pubDate>Tue, 08 Oct 2019 17:31:49 GMT</pubDate>
            <atom:updated>2019-10-08T20:34:46.646Z</atom:updated>
            <content:encoded><![CDATA[<p>State management is usually the most complex part of a UI application. At Instacart, we have been using RxJava to manage state for a few years now. As our Android team grew, we realized that there was a steep learning curve for new developers to get started. We started to experiment with how we could reduce complexity. After a few iterations, we are excited to announce <a href="https://github.com/instacart/formula">Formula</a> — an open-source state management library built in Kotlin. Formula provides a simple, declarative, and composable API for managing your app complexity. The goal is to express the essence of your program without much ceremony.</p><h3>Building a simple app</h3><p>Probably the easiest way to show you how Formula works is to build a simple stopwatch application. It will show how long the stopwatch has been running and allow the user to start/stop or reset it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*PjDmEYg80VnIIwDMBGEenw.png" /></figure><p>When working with Formula, the recommended way to start is by defining what the UI needs to display and what actions the user will be able to take. We model this with Kotlin data classes and call this concept a RenderModel. We model user actions as event listeners on the render model.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8117e61aa28451324cfd1df55b3f327b/href">https://medium.com/media/8117e61aa28451324cfd1df55b3f327b/href</a></iframe><p>Render model is an immutable representation of your view. Any time we want to update UI, we will create a new instance and pass it to the RenderView. Render view is responsible for taking a render model and applying it to Android views.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b00c51bc6d7420ba3d94974f903afcb3/href">https://medium.com/media/b00c51bc6d7420ba3d94974f903afcb3/href</a></iframe><p>With rendering logic out of the way, let’s see how we actually create the render model. Render model creation is the responsibility of the Formula interface. Let’s create a StopwatchFormula class that extends it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/24095a2f5598ce4b1394d40c9df3149b/href">https://medium.com/media/24095a2f5598ce4b1394d40c9df3149b/href</a></iframe><p>Formula interface takes three generic parameters: Input, State and Render Model (we will not use input in this example). In Formula, we keep all our dynamic properties within a single Kotlin data class which we call State. For the time being, we will use an empty State object as a placeholder. The evaluate function takes the current state and is responsible for creating the render model.</p><p>Our current implementation always returns the same render model. Before we make it dynamic, let’s connect this implementation to our render view. There is an extension function start that creates an RxJava observable from the Formula interface.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/62518af8624bd514e158f144de15b885/href">https://medium.com/media/62518af8624bd514e158f144de15b885/href</a></iframe><p>For simplicity sake, I’ve placed this logic directly in the activity. In a real application, it should be placed within a surface that survives configuration changes such as AndroidX ViewModel or formula-android module.</p><p>Now that we are observing render model changes, let’s start making the UI dynamic. For example, when the user clicks the “Start” button, we want to reflect this change and update the button to show “Stop”. We need a dynamic property to keep track if the stopwatch was started. Let’s update our State to include isRunning. We initially set isRunning to false. If you have worked with Redux or MVI, this should look familiar to you.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/90690c280ff461992daf3e0d2a7acd22/href">https://medium.com/media/90690c280ff461992daf3e0d2a7acd22/href</a></iframe><p>Let’s update the start/stop button render model creation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/81af08d931f9c3b65dff6fb3d86d886b/href">https://medium.com/media/81af08d931f9c3b65dff6fb3d86d886b/href</a></iframe><p>Any time user clicks this button, we want to toggle isRunning and create a new render model. We will use FormulaContext to accomplish this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c25a0bdba684d2591df5f7ade176bbe4/href">https://medium.com/media/c25a0bdba684d2591df5f7ade176bbe4/href</a></iframe><p>FormulaContext is a special object passed by the runtime that allows us to create callbacks and define transitions to a new state. Any time onSelected is called we transition to a state where isRunning is inverted (if it was true it becomes false and vice-versa). Instead of mutating the state, we use the data class copy method to create a new instance. A transition will cause evaluate to be called again with the new state, new render model will be created, the Observable will emit the new value and our UI will be updated.</p><p>Now that we have a functioning button, we actually need to run the stopwatch and update the UI as time passes. Let’s add a new property to our state class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d9e4b1ba6277ce813ff467e47edea87/href">https://medium.com/media/0d9e4b1ba6277ce813ff467e47edea87/href</a></iframe><p>The actual implementation to create a display value from milliseconds is a bit complex, so let’s just append ms to time passed.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3054d6dedb45b4a5e78c347bcf2ccb10/href">https://medium.com/media/3054d6dedb45b4a5e78c347bcf2ccb10/href</a></iframe><p>To update timePassedInMillis we will use the RxJava interval operator.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d8c43d261165ac436ff9e5919a1d4ab/href">https://medium.com/media/3d8c43d261165ac436ff9e5919a1d4ab/href</a></iframe><p>When the stopwatch is running, we want to listen to this observable and update timePassedInMillis on each event. To add this behavior we need to update evaluate function. As part of each state change, Formula can decide what services it wants to run and listen to. We update our Evaluation and use conditional logic within context.updates block to declare when we want our observable to run.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/546e4f745b2d4e876af20b328e68a98a/href">https://medium.com/media/546e4f745b2d4e876af20b328e68a98a/href</a></iframe><p>Starting the stopwatch now updates the time passed label. The logic here is very simple: when isRunning is true, listen to incrementTimePassedEvents and increment timePassedInMillis. The updates mechanism is agnostic to RxJava so you need to wrap it using RxStream. The event callback is very similar to UI event callbacks except it’s already scoped so you don’t need to use context.callback.</p><p>We still need to handle the reset button clicks. This is the same as implementing the start/stop button. There are no new concepts to introduce here. Any time reset button is selected we transition to a new state where timePassedInMillis is set to 0 and isRunning is set to false.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/451aae689e0eb1852df12a08ac032ee3/href">https://medium.com/media/451aae689e0eb1852df12a08ac032ee3/href</a></iframe><p>And we are done. You can find the source code <a href="https://github.com/instacart/formula/tree/master/samples/stopwatch">here</a>.</p><h3>Learning More</h3><p>There are still a lot of things that we didn’t go over such as composition, testing or side-effects. If you want to learn more, take a look at the <a href="https://instacart.github.io/formula/">documentation</a>, <a href="https://github.com/instacart/formula/tree/master/samples">samples</a> or the <a href="https://github.com/instacart/formula">Github repository</a>. If you have any questions or feedback you can find me on <a href="https://twitter.com/thatlime">Twitter</a>.</p><p>Interested in projects like Formula? Check out Instacart’s current engineering openings <a href="https://www.instacartcareers.com/">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f5569ce09274" width="1" height="1" alt=""><hr><p><a href="https://tech.instacart.com/what-the-formula-managing-state-on-android-f5569ce09274">What the Formula? Managing state on Android</a> was originally published in <a href="https://tech.instacart.com/">tech-at-instacart</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RxJava & State: The Basics]]></title>
            <link>https://tech.instacart.com/rxjava-state-the-basics-f842eaee7ee1?source=rss-eeb6311ddecd------2</link>
            <guid isPermaLink="false">https://medium.com/p/f842eaee7ee1</guid>
            <category><![CDATA[rxjava]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[reactive-programming]]></category>
            <category><![CDATA[functional-programming]]></category>
            <dc:creator><![CDATA[Laimonas Turauskas]]></dc:creator>
            <pubDate>Tue, 03 Apr 2018 17:45:30 GMT</pubDate>
            <atom:updated>2018-04-13T02:29:59.023Z</atom:updated>
            <content:encoded><![CDATA[<p>At Instacart, we have increasingly been using a reactive functional approach to manage state. The goal is to have a deterministic Android application that is easy to understand, test and maintain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*AmeJZxRL_sE9c4YXfGPNhA.jpeg" /></figure><p>Let’s say we have a form to add a new comment. Basic requirements are:<br>1. There is a single text field that the user can modify.<br>2. There is a submit button that the user can press to add a comment.<br>3. We only enable the submit button when comment entered is longer than 5 characters.<br>4. Disable the submit button while we are uploading the comment</p><p>How would we approach this problem in a reactive functional way? First, let’s define a data class that defines our view state:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/645e8227f1b8dfa816abdc5b617f572e/href">https://medium.com/media/645e8227f1b8dfa816abdc5b617f572e/href</a></iframe><p>Now, let’s define how our view will look:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/081233178999d4c090973ecd1ea39cc8/href">https://medium.com/media/081233178999d4c090973ecd1ea39cc8/href</a></iframe><p>We laid out the basic contract for the view. In this case, we made the view as stupid as possible. It doesn’t contain any logic besides taking an immutable state object and updating itself. When user types a new letter, we trigger onTextEntered callback. We then create a new CommentFormViewState object and pass it back to setViewState for the view to re-render.</p><p>CommentFormViewState is made up of data and callbacks. It is the final product that the view sees. The question is how we update the state after the callback is triggered? To do this, let’s first create a new class that represents only the data and a couple of classes to represent the user events.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2aadcace1d3b1b78a19b01a58d7c95b/href">https://medium.com/media/a2aadcace1d3b1b78a19b01a58d7c95b/href</a></iframe><p>There are two actions that the user can take:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ac013820d22a3374630ac15782cff7f/href">https://medium.com/media/9ac013820d22a3374630ac15782cff7f/href</a></iframe><p>Now, that we have defined data and user actions, we can model the relationship between them. Here is a basic signature of the function that takes user event streams and returns user data stream.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/90cdf971167d7d26fee5a2c06546fffc/href">https://medium.com/media/90cdf971167d7d26fee5a2c06546fffc/href</a></iframe><p>Before we implement this function, we need to introduce a concept, common in functional state management, called reducer. A reducer is a function that takes an event, the current state and returns a new state object.</p><p>Here is a signature of a reducer function:</p><pre>fun reduce(event: E, state: T): T</pre><p>Reducers are supposed to be pure in a functional sense, which means that two identical inputs will provide identical output.</p><p>Here is our reducer for text changed event:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c04035cda2fb88f2aa8d3dd89f65bea3/href">https://medium.com/media/c04035cda2fb88f2aa8d3dd89f65bea3/href</a></iframe><p>Now, let’s plug this into RxJava</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab310bcabcb9a5dbc72d60970983fb05/href">https://medium.com/media/ab310bcabcb9a5dbc72d60970983fb05/href</a></iframe><p>We still need to incorporate submit comment actions. When user clicks submit, we want to trigger a network request and keep the data updated. To be able to do that, let’s define an interface for the api.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/13a6f371595405a937d39aa878bc68a2/href">https://medium.com/media/13a6f371595405a937d39aa878bc68a2/href</a></iframe><p>Now that we have our service, let’s setup comment submission.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0c451ac7182d7a4d3c95d901542c8b17/href">https://medium.com/media/0c451ac7182d7a4d3c95d901542c8b17/href</a></iframe><p>As we are working in a statically typed system, to use RxJava scan operator, all events must have a matching type or a super type. As you can see, we have an issue where the events stream data type becomes Any.</p><p>To be able to reduce, we would need check if the object is of a particular type.</p><pre>if (event is TextChangedEvent) {<br>  // Handle text changed event<br>} else if (event is Lce&lt;Comment&gt;) {<br>  // DOES NOT COMPILE ^<br>}</pre><p>In simple cases, it’s a bit ugly. But when using with types that have generic type parameters, it is hard to maintain type safety. Due to type erasure, you cannot safely check that the generic parameter is of a specific type.</p><p>Is there another way? Of course! Let’s take a step back and look at our reduce function</p><pre>fun reduce(event: E, state: T): T</pre><p>What if we apply function currying to this?</p><pre>fun reduce(event: E): (T) -&gt; T</pre><p>So, what happened here? We split the function! Previously, we had a function that took two parameters and returned a state object. Now, it takes only the event and returns a function that takes the state and returns the state. Functional magic!</p><p>So, how can we use this?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1101f31ae3232f1502b3a5c72f477342/href">https://medium.com/media/1101f31ae3232f1502b3a5c72f477342/href</a></iframe><p>We created a common type (CommentFormData) -&gt; CommentFormData that we can now use.</p><p>To make this even better, let’s declare a kotlin typealias.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/94150e3d82babff27092be4bdf902715/href">https://medium.com/media/94150e3d82babff27092be4bdf902715/href</a></iframe><p>And now, let’s replace the code</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c74efb39bdb4387b47ec3dd41627c562/href">https://medium.com/media/c74efb39bdb4387b47ec3dd41627c562/href</a></iframe><p>We have managed to define the logic behind comment form data! Now that this part is done, let’s take the data and create a view state using it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/392802f186210bbe9866b8a71e0c6e53/href">https://medium.com/media/392802f186210bbe9866b8a71e0c6e53/href</a></iframe><p>To finish this reactive component, let’s delegate user actions to the CommentFormModel and use the data provided to create the view state. We will use <a href="https://github.com/JakeWharton/RxRelay">RxRelay’s</a> to achieve this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe31ecb3ccd19fcc6e79dce8ba14b7bb/href">https://medium.com/media/fe31ecb3ccd19fcc6e79dce8ba14b7bb/href</a></iframe><p>The final step is connecting the view model to the view.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f29875831d3dd88ea8a17e386e13a9b/href">https://medium.com/media/7f29875831d3dd88ea8a17e386e13a9b/href</a></iframe><p>You might ask, why would we model our application this way? If you are not familiar with functional patterns and RxJava, this can be intimidating. However, once you learn these concepts and start applying them, the benefits are clear and it’s hard to go back.</p><p><strong>Testability<br></strong>Each class is responsible only for one thing, code is mostly side-effect free and most of the logic lives outside of the Android framework. This enables us to easily test majority of our code using simple jUnit tests.</p><p><strong>Predictability<br></strong>The contract between classes is clearly defined. Each class has only one public method that defines it’s API. For the inputs provided, this method will give you the same deterministic output.</p><p><strong>Maintainability<br></strong>When we combine predictability and testability, we get code that is highly maintainable.</p><p><strong>Shameless Plug</strong></p><p>If you are interesting in building functional android applications, <a href="https://play.google.com/store/apps/details?id=com.instacart.client">Instacart</a> is hiring. Email me at <a href="/service/mailto:laimonas.turauskas@instacart.com">laimonas.turauskas@instacart.com</a></p><p><strong>For help with the article, special thanks to: </strong><br>Maksim Golivkin<br>Colin White</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f842eaee7ee1" width="1" height="1" alt=""><hr><p><a href="https://tech.instacart.com/rxjava-state-the-basics-f842eaee7ee1">RxJava &amp; State: The Basics</a> was originally published in <a href="https://tech.instacart.com/">tech-at-instacart</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LCE: Modeling Data Loading in RxJava]]></title>
            <link>https://tech.instacart.com/lce-modeling-data-loading-in-rxjava-b798ac98d80?source=rss-eeb6311ddecd------2</link>
            <guid isPermaLink="false">https://medium.com/p/b798ac98d80</guid>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[rxjava]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[reactive-state]]></category>
            <dc:creator><![CDATA[Laimonas Turauskas]]></dc:creator>
            <pubDate>Mon, 24 Apr 2017 18:29:59 GMT</pubDate>
            <atom:updated>2021-03-19T17:50:04.663Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*g0gQAHNAquznMf8j325JPA.gif" /></figure><p>If you are a mobile application developer, one situation you will commonly run into is loading and displaying data to a user. With that reality, there are almost always two caveats:</p><ol><li>Data might take time to arrive, or</li><li>It might fail to arrive due to unforeseen circumstances like a bad network connection</li></ol><p>A common situation when using RxJava to load data</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/797f411a271bdb12c7a1ea3819cf844f/href">https://medium.com/media/797f411a271bdb12c7a1ea3819cf844f/href</a></iframe><p>As long as data loading conditions are very simple, this is effective. But, what if the conditions defining the data can change and we need to reload the data? What if data is updated and we need to propagate that update? We can try to model it in an idiomatic way</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/65b717df76130083b9496d6b8988c156/href">https://medium.com/media/65b717df76130083b9496d6b8988c156/href</a></iframe><p>There are a couple of issues here:</p><ol><li>We lose the context of when the data is refreshing/loading</li><li>Either we are not propagating errors or it will kill our stream</li></ol><p>To solve this issue, let’s create an immutable value type that provides this context to us.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bde6aa8932493a5c223e963cbd0f7920/href">https://medium.com/media/bde6aa8932493a5c223e963cbd0f7920/href</a></iframe><p>Let’s update our repository signature to</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/310eb73adc2f954582b76c5a3cfb8fbf/href">https://medium.com/media/310eb73adc2f954582b76c5a3cfb8fbf/href</a></iframe><p>Now we can consume the data</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b2d8cce15a6c7bc018fb6a33e91d95c2/href">https://medium.com/media/b2d8cce15a6c7bc018fb6a33e91d95c2/href</a></iframe><h4>Constructing Lce Observables</h4><p>So far, I’ve only shown the stubbed version of Observable&lt;Lce&lt;Data&gt;&gt;. The reason is that it is an implementation detail. How you construct it will depend on your data requirements.</p><p>Here is how a simple single request implementation could look like when using a Retrofit api</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca9991995a18d6ad7724d6e1bedb1b24/href">https://medium.com/media/ca9991995a18d6ad7724d6e1bedb1b24/href</a></iframe><p>If you want it to be refreshable</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3fd109959135aee810f0ae3daa32b38a/href">https://medium.com/media/3fd109959135aee810f0ae3daa32b38a/href</a></iframe><p>The view implementation doesn’t have to change much or at all to handle this change. We are hiding implementation details from the view layer while at the same time keeping the logic unit testable to ensure correct behavior.</p><h4>Combining</h4><p>Let’s say that the view requires data combined from two sources. We can easily compose these observables into a single stream</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/60e1d0f4d358c31b5e6ca3fa6fd0061e/href">https://medium.com/media/60e1d0f4d358c31b5e6ca3fa6fd0061e/href</a></iframe><p>If something triggers user or content update, this stream will propagate the correct events down to the view. So if either the user or the content is loading, the view will show that.</p><h4>Real world use case</h4><p>On the Instacart consumer app, we require user data to be available before we make any subsequent API calls.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b88a0dddfb2eafbb1cd0844781a45e99/href">https://medium.com/media/b88a0dddfb2eafbb1cd0844781a45e99/href</a></iframe><p>To display the store chooser, we need the list of stores. Stores depend on the zip code you are in. Every time the zip code changes, we need to refresh the stores.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b6d7f52985804b03938daf2f36b909f/href">https://medium.com/media/7b6d7f52985804b03938daf2f36b909f/href</a></iframe><h4><strong>Conclusion</strong></h4><p>The conditions for when to show the progress bar or error state often become messy and complicated. I’ve seen and wrote screens where showProgress(true/false) was sprinkled across many methods. This made adding and modifying code very complicated where a small change could easily break a loading condition on some edge case. This pattern helps to avoid such situations, while allowing loading / content / error logic to be tested.</p><p><strong>Update: </strong>you can find the library here<strong> </strong><a href="https://github.com/Laimiux/lce">https://github.com/Laimiux/lce</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b798ac98d80" width="1" height="1" alt=""><hr><p><a href="https://tech.instacart.com/lce-modeling-data-loading-in-rxjava-b798ac98d80">LCE: Modeling Data Loading in RxJava</a> was originally published in <a href="https://tech.instacart.com/">tech-at-instacart</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>