Skip to content

ReduxKit/ReduxKitReactiveCocoa

Repository files navigation

ReduxKitReactiveCocoa

ReactiveCocoa bindings for ReduxKit.

Usage / Quick start

import ReactiveCocoa
import ReduxKit
import ReduxKitReactiveCocoa

// 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> = ReduxKitReactiveCocoa.createStore(reducer)

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

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

disposable.dispose()

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

Installation

Add ReduxKitReactiveCocoa to Cartfile

github "ReduxKit/ReduxKitReactiveCocoa" ~> 0.1

Run in terminal:

$ carthage update

Add ReduxKitReactiveCocoa to your Podfile:

pod 'ReduxKitReactiveCocoa', '~> 0.1'

Then, run the following command:

$ pod install

API

createStore

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

Uses createStateStream to create a ReduxKit.Store<State> using a ReactiveCocoa.Observer<State, NoError> stream.

createStateStream

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

Accepts a State and returns ReduxKit.StateStream<State> using a ReactiveCocoa.Observer<State, NoError> as the stream provider.

createDisposable

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

Accepts a ReactiveCocoa.Disposable and returns it wrapped as a ReduxDisposable.