All Projects β†’ FluxorOrg β†’ Fluxor

FluxorOrg / Fluxor

Licence: mit
Unidirectional Data Flow in Swift πŸš€ based on Combine 🚜

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Fluxor

roda
RΓΆda: A stream-oriented scripting language
Stars: ✭ 43 (-50.57%)
Mutual labels:  data-flow
richflow
A Node.js and JavaScript synchronous data pipeline processing, data sharing and stream processing library. Actionable & Transformable Pipeline data processing.
Stars: ✭ 17 (-80.46%)
Mutual labels:  data-flow
Cdc Kafka Hadoop
MySQL to NoSQL real time dataflow
Stars: ✭ 13 (-85.06%)
Mutual labels:  data-flow
eventkit
Event-driven data pipelines
Stars: ✭ 94 (+8.05%)
Mutual labels:  data-flow
react-wrangler
A react component for simple declarative state management with "one way data flow" and side effects
Stars: ✭ 16 (-81.61%)
Mutual labels:  data-flow
actionizer
Simple pub/sub for data flow like Redux.
Stars: ✭ 21 (-75.86%)
Mutual labels:  data-flow
Reactpatterns
React patterns & techniques to use in development for React Developer βš› .
Stars: ✭ 201 (+131.03%)
Mutual labels:  data-flow
React In Patterns Cn
React in patterns δΈ­ζ–‡η‰ˆ
Stars: ✭ 1,107 (+1172.41%)
Mutual labels:  data-flow
GVProf
GVProf: A Value Profiler for GPU-based Clusters
Stars: ✭ 25 (-71.26%)
Mutual labels:  data-flow
Clj Unifier
[DEPRECATED] A Clojure(Script) library for unified responses
Stars: ✭ 25 (-71.26%)
Mutual labels:  data-flow
mutable
State containers with dirty checking and more
Stars: ✭ 32 (-63.22%)
Mutual labels:  data-flow
rule-engine
εŸΊδΊŽζ΅η¨‹,δΊ‹δ»Άι©±εŠ¨,可拓展,响应式,θ½»ι‡ηΊ§ηš„θ§„εˆ™εΌ•ζ“Žγ€‚
Stars: ✭ 165 (+89.66%)
Mutual labels:  data-flow
Store
Android Library for Async Data Loading and Caching
Stars: ✭ 3,593 (+4029.89%)
Mutual labels:  data-flow
realar
5 kB Advanced state manager for React
Stars: ✭ 41 (-52.87%)
Mutual labels:  data-flow
Sidecar
Some old C++ code I developed while at MIT. Could be useful if you have an old radar lying around.
Stars: ✭ 20 (-77.01%)
Mutual labels:  data-flow
graflow
A graph stream library for Javascript
Stars: ✭ 53 (-39.08%)
Mutual labels:  data-flow
Systemizer
A system design tool that allows you to simulate data flow of distributed systems.
Stars: ✭ 1,219 (+1301.15%)
Mutual labels:  data-flow
Goflow
Flow-based and dataflow programming library for Go (golang)
Stars: ✭ 1,276 (+1366.67%)
Mutual labels:  data-flow
Datakit
Connect processes into powerful data pipelines with a simple git-like filesystem interface
Stars: ✭ 951 (+993.1%)
Mutual labels:  data-flow
Xreact
reactive x react = xreact
Stars: ✭ 565 (+549.43%)
Mutual labels:  data-flow


Fluxor

Unidirectional Data Flow in Swift - inspired by Redux and NgRx.
Based on Combine - ideal for use with SwiftUI.

Swift version Swift PM Platforms Twitter
CI Documentation Maintainability Test Coverage

Why do I need Fluxor?

When developing apps, it can quickly become difficult to keep track of the flow of data. Data flows in multiple directions and can easily become inconsistent with Multiple Sources of Truth.

With Fluxor, data flows in only one direction, there is only one Single Source of Truth, updates to the state are done with pure functions, the flow in the app can easily be followed, and all the individual parts can be unit tested separately.

How does it work?

Fluxor is made up from the following types:

  • Store contains an immutable state (the Single Source of Truth).
  • Actions are dispatched on the Store to update the state.
  • Reducers gives the Store a new state based on the Actions dispatched.
  • Selectors selects (and eventually transform) part(s) of the state to use (eg. in views).
  • Effects gets triggered by Actions, and can perform async task which in turn can dispatch new Actions.
  • Interceptors intercepts every dispatched Action and state change for easier debugging.

Installation

Fluxor can be installed as a dependency to your project using Swift Package Manager, by simply adding https://github.com/FluxorOrg/Fluxor.git.

Requirements

  • iOS 13.0+ / macOS 10.15+ / tvOS 13.0+
  • Xcode 11.0+
  • Swift 5.2+

Usage

As a minimum, an app using Fluxor will need a Store, an Action, a Reducer, a Selector and a state.

Here is a setup where firing the IncrementAction (1) will increment the counter (2) in AppState (3), and when selecting with the counterSelector (4) on the Store will publish the counter everytime the state changes (5).

import Combine
import Fluxor
import Foundation

// 3
struct AppState {
    var counter: Int
}

// 1
struct IncrementAction: Action {
    let increment: Int
}

// 4
let counterSelector = Selector(keyPath: \AppState.counter)

let store = Store(initialState: AppState(counter: 0))
store.register(reducer: Reducer(
    ReduceOn(IncrementAction.self) { state, action in
        state.counter += action.increment // 2
    }
))

let cancellable = store.select(counterSelector).sink {
    print("Current count: \($0)") // 5
}

store.dispatch(action: IncrementAction(increment: 42))
// Will print out "Current count: 42"

Side Effects

The above example is a simple use case, where an Action is dispatched and the state is updated by a Reducer. In cases where something should happen when an Action is dispatched (eg. fetching data from the internet or some system service), Fluxor provides Effects.

Effects are registered in the Store and will receive all Actions dispatched. An Effect will in most cases be a Publisher mapped from the dispatched Action - the mapped Action will be dispatched on the Store.

Alternatively an Effect can also be a Cancellable when it don't need to have an Action dispatched.

import Combine
import Fluxor
import Foundation

class TodosEffects: Effects {
    typealias Environment = AppEnvironment

    let fetchTodos = Effect<Environment>.dispatchingOne { actions, environment in
        actions.ofType(FetchTodosAction.self)
            .flatMap { _ in
                environment.todoService.fetchTodos()
                    .map { DidFetchTodosAction(todos: $0) }
                    .catch { _ in Just(DidFailFetchingTodosAction(error: "An error occurred.")) }
            }
            .eraseToAnyPublisher()
    }
}

Intercepting actions and changes

If read-only access to all Actions dispatched and state changes is needed, an Interceptor can be used. Interceptor is just a protocol, and when registered in the Store, instances of types conforming to this protocol will receive a callback everytime an Action is dispatched.

Fluxor comes with two implementations of Interceptor:

  • PrintInterceptor for printing Actions and state changes to the log.
  • TestInterceptor to help assert that specific Actions was dispatched in unit tests.

Packages for using it with SwiftUI and testing

Fluxor comes with packages, to make it easier to use it with SwiftUI and for testing apps using Fluxor.

Debugging with FluxorExplorer

Fluxor has a companion app, FluxorExplorer, which helps when debugging apps using Fluxor. FluxorExplorer lets you look through the dispatched Actions and state changes, to debug the data flow of the app.

FluxorExplorer is available on the App Store but also available as open source.

Download on the App Store

To learn more about how to use FluxorExplorer, go to the repository for the app.

Apps using Fluxor

Real world apps

Sample apps

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].