Skip to content

A sample of Unidirectional Data Flow ♺ usage. Bike data are fetched from CityBikes API. 🚴🏻‍♂️

License

Notifications You must be signed in to change notification settings

andremion/Bikes

Repository files navigation

Icon

Bikes

A sample of Unidirectional Data Flow usage.


License Apache 2.0 minSdkVersion 16 compileSdkVersion 29

Sample

The sample

Shows a map with markers in cities that have some bike sharing service. When you click in any of those cities, the app will show all the bike sharing stations with current status of bike availability. The app will initially try to position in the current user city obtained from location services.

The architecture

The abstract class UdfViewModel is a ViewModel subclass that delegates its UdfDispatcher implementation to UdfDispatcherImpl in order to handle all the Unidirectional Data Flow.

Each UdfViewModel should have one instance of UdfDispatcherImpl using specific UdfProcessor and UdfReducer implementations that basically do:

  • Processes each Action in UdfProcessor emitting a Result or ViewEffect. (Action => Result / ViewEffect)

    • It receives an Action, process some operation (fetching/saving from/to network or database) and returns an LiveData of Result that will be used by UdfReducer.
    • Additionally it may trigger a ViewEffect that means that it should be emitted but not kept as state such as: Showing a Snackbar, Navigating to another screen, etc.
  • Reduce the current cached ViewState taking Result in consideration by UdfReducer. (Current ViewState + Result => New ViewState)

    • It receives a Result from UdfProcessor and takes the current ViewState to produce another ViewState that will be cached.

API

Bike data are fetched from CityBikes API, a project that provides bike sharing data for apps, research and projects to use.

References

License

Copyright 2019 André Mion

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

A sample of Unidirectional Data Flow ♺ usage. Bike data are fetched from CityBikes API. 🚴🏻‍♂️

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages