Code Monkey home page Code Monkey logo

redux-ios's Introduction

Redux for iOS

This app demonstrates how Redux concepts can be used in an iOS app

One app state

There big difference to any other app architecture is that Redux has only one state for the whole app. The app state is kept in the Store. The state can be be changed form anywhere and will update any UI that subscribed to reflect the new app state.

Action are used to trigger the transfer of the app state to a new state. Listeners get updated whenever the app state changes. The power of Redux is in the Reducers which are used to transfer app state. Reducers can be composed. An single app reducer is configured in the Store which may then call other reducers to transfer parts of the app state. This is a great way to decompose state tranistion and keep code organised.

Unidirectional data flow

Data flows only in one direction. When the UI changes it sends an Action to the Store via a Dispatch method. The app state gets transferred into a new state by calling the app reducer which then calles various reducers and composes the new app state. After a state change all listeneres get notified. A view controller would for example subscribe to state changes and it's update method gets called which in turn updates the whole UI (or View Model if MVVM is used)

Redux flow in iOS

  1. An Action is created and dispatched to the Store. Actions may be created by view controllers, data sources anything that wants to change the state of the app.
  2. The Store invokes the app Reducer with it’s current state and the Action.
  3. The app Reducer calls other reducers to handle the Action.
  4. The other Reducers return their state change.
  5. The app Reducer combines the states from all reducers into a new state and the Store updates the App State.
  6. The Store notifies all Subscribers about the new App State. Subscribers will most likely be View Controllers who then update their views to reflect the new App State.
  7. View controllers may create a new Action to reflect any user interaction and calls dispatch on the Store. Other objects may also creata action e.g. a data sources may create an action. Data received on a web socket could also trigger the creation of an Action to reflect changes.

And the cycle repeats.

Redux flow in iOS

Sample iOS App

The sample app demonstrates how Redux is used and what problem it elegantly solve. The sample app has a settings view controller that shows two settings which can be toggled on or off. The user can toggle facebook on that screen which will create a toggle action. To demonstrate the power of Redux another screen has a plain old button which creates the same action to toggle facebook. No matter which screen changes the setting the other screen will be updated - nice.

Redux References

Other iOS Redux packages

redux-ios's People

Contributors

masamichiueta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.