Swiftpack.co - NicholasTD07/TDRedux.swift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by NicholasTD07.
NicholasTD07/TDRedux.swift 3.0.0
Yet another Redux written in Swift
⭐️ 1
🕓 1 year ago
.package(url: "https://github.com/NicholasTD07/TDRedux.swift.git", from: "3.0.0")

TDRedux

CocoaPods Carthage compatible Swift Package Manager

Travis Codecov CocoaPods License

Yet another Redux written in Swift

Installation

Swift Package Manager

Add this repo as a dependency in your Package.swift file, for example:

import PackageDescription

let package = Package(
    name: "Example",
    dependencies: [
        .Package(url: "https://github.com/NicholasTD07/TDRedux.swift.git",
                 majorVersion: 2),
    ]
)

Carthage

github "NicholasTD07/TDRedux.swift" ~> 2.0

CocoaPods

pod 'TDRedux.swift', '~> 2.0'

TDRedux

Store

A Store holds a State. A State is the entire internal state of an application, which could be anything.

You can

  • create a Store with a Reducer
  • dispatch Actions to change a Store's State
  • subscribe to changes happens to the State of a Store

Read more: Redux in Swift Part 1 - Store and State

Reducer Type

A Reducer is a function which takes an optional State and an Action and returns a new State, defined as the following:

class Store<State> {
    typealias Reducer = (State?, Action) -> State
}

Read more: Redux in Swift Part 1 - Reducer and Action

Action

An Action describes what happened while it may carry some data, e.g. AddTodo(text: "buy milk") or ToggleTodo(atIndex: 1)

Action type is defined as

typealias Action = Any

Read more: Redux in Swift Part 1 - Reducer and Action

Reducer function

A helper function which wraps Reducers that take non-optional State and specific type of Action, so that: No more type-casting in hand written Reducers anymore. For example:

typealias CounterState = Int

enum CounterActions {
  case increase
  case decrease
}

let counterReducer: (CounterState, CounterActions) = /* ... */
let wrappedReducer: (CounterState?, Any) = Reducer(initialState: 0, reducer: counterReducer)

let counterStore = Store<CounterState>.init(with: wrappedReducer)

combineReducers

A helper function which combines an array of Reducers into one. For example:

typealias State = /* ... */
let arranOfReducers: [(State?, Any)] = [ /* ... */ ]
let combinedReducers: (State?, Any) = combineReducers(arranOfReducers)

Middleware

It provides a third-party extension point between dispatching an action, and the moment it reaches the reducer.

Redux doc: Middleware

What's Experimental?

Everything in Store is final

Store and every property and methods in Store are defined as final.

Let me know if you think the Store need to be subclassed and overridden.

Middleware

I am not too familiar with this concept in Redux and also I am not sure whether there are potential issues in my implementation or not.

License

TDRedux is released under the MIT license. See LICENSE for details.

Read More

GitHub

link
Stars: 1
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Swift 5!
4 years ago
  • Rename combine(reducers:) to combined(reducers:)
  • Update to Swift 5

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics