Skip to content

Unidirectional Data Flow in Swift - Inspired by ReSwift

License

Notifications You must be signed in to change notification settings

reloni/RxDataFlow

Repository files navigation

RxDataFlow

Build Status codecov Platform iOS Carthage compatible codebeat badge

Introduction

RxDataFlow is another implementation of unidirectional data flow architecture. This library is inspired by ReSwift (which was inspired by Redux).

More information will be added soon:)

Components

  • State: A data structure that describes state of application.
  • Reducer: A pure function that creates new state on base on action and current state.
  • Action: Actions describe state change. Reducer produce state changes according to dispatched action.

  1. The View Controller/View Model creates an Action and dispatch it to the FlowController.

  2. The FlowController switches to appropriate scheduler and sends the State and Action to the Reducer.

  3. The Reducer receives the current App State and the dispatched Action, computes and returns new State.

  4. The FlowController saves new State and sends it to the subscribers.

  • In case of an error FlowController doesn't change State and sends Error to all subscribers instead.
  • It's possible to setup special FallbackAction that will be dispatched in case of an error (see CompositeAction).
  1. Subscriber receives new State and operate accordingly: View Model may transform State, View Controller may directly bind data to the UI.

Dispatch rules

FlowController dispatches actions in internal SerialDispatchQueueScheduler (so all operations are asynchronous by default), all incoming actions first get in the queue and dispatches (Reducer get executed with current State and Action instances) one after another. For example if you dispatches three actions and every action requires network request - requests will not get fired simultaneously, but one after another.

Dependencies

Requirements

  • Xcode 10.0
  • Swift 5.0

Installation

github "reloni/RxDataFlow"

Example Projects

SimpleToDo - kind of "real world" app using this architecture, already in app store.

Credits

List of similar projects: