levibostian / Teller-iOS

iOS library that manages your app's cached data with ease.
MIT License
13 stars 0 forks source link

Fix quick flash in the UI when first load the cache. #93

Open levibostian opened 4 years ago

levibostian commented 4 years ago

When Teller first loads up, it will load with a DataState of "none". Teller internally requires this state so the state machine can move to valid nodes when you set requirements on the Repository.

However, the UI of the app should not be observing this none state. Why? Because your app might have something like an animation in your app that switches between states. Animation plus a very fast (milliseconds) observing of DataState in Teller between the "none" state and a valid state with a cache causes your UI to have a weird flicker effect in it.

Proposal

When a DataState is in the "none" state, do not deliver that to observers. Let them wait those few milliseconds until the cache is observed and the UI can receive a real response.

What I expect to happen after this change

If we had an example app in this repo, before this fix, you would observe a Teller repository. You would receive a DataState of type none and then very quickly after, you would receive a DataState not of type none. After this fix, you would only receive a DataState not of type none and the none type is ignored.