CocoaPods trunk is moving to be read-only. Read more on the blog, there are 19 months to go.

ReduxKitRxSwift 0.1.4

ReduxKitRxSwift 0.1.4

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Dec 2015
SPMSupports SPM

Maintained by Karl Bowden.



 
Depends on:
ReduxKit~> 0.1
RxSwift~> 2.0.0-beta
 

  • By
  • Aleksander Herforth Rendtslev and Karl Bowden

ReduxKitRxSwift

RxSwift bindings for ReduxKit.

import ReduxKitRxSwift
let store = createStore(reducer)

Usage / Quick start

import RxSwift
import Redux
import ReduxKitRxSwift

// Setup State, Actions and Reducers
struct State {
    let count: Int
}

struct IncrementAction: SimpleStandardAction {
    let meta: Any? = nil
    let error: Bool = false
    let rawPayload: Any? = nil
}

func reducer(previousState: State? = nil, action: Action) -> State {
    let state = previousState ?? State(count: 0)

    switch action {
    case let action as IncrementAction:
        return State(count: state.count + 1)
    default:
        return state
    }
}

// Create the Store
let store: Store<State> = ReduxKitRxSwift.createStore(reducer)

let disposable = store.subscribe { print("Count: \($0.count)") }
// -> Count: 0

store.dispatch(IncrementAction())
// -> Count: 1

disposable.dispose()

store.dispatch(IncrementAction())
// ->

Installation

API

createStore

func createStore<State>(reducer: Reducer, state: State? = nil)
    -> Store<State>

Uses createStateStream to create a ReduxKit.Store<State> using an RxSwift.Variable<State> stream.

createStateStream

public func createStream<State>(state: State)
    -> StateStream<State>

Accepts a State and returns ReduxKit.StateStream<State> using an RxSwift.Variable<State> as the stream provider.

createDisposable

func createDisposable(disposable: RxSwift.Disposable)
    -> ReduxDisposable

Accepts an RxSwift.Disposable and returns it wrapped as a ReduxDisposable.

The returned disposable only supports the disposable.dispose() function and does not return disposed state (disposable.disposed always returns false).