Redux.jl

A Julia implementation of Redux
Author Gnimuc
Popularity
12 Stars
Updated Last
9 Months Ago
Started In
August 2019

Redux

CI TagBot Codecov

Installation

pkg> add Redux

Quick Start

using Redux

# actions
struct IncrementAction <: AbstractSyncAction end
struct DecrementAction <: AbstractSyncAction end

const INCREMENT = IncrementAction()
const DECREMENT = DecrementAction()

# state
struct State <: AbstractImmutableState
    counter::Int
end

# reducers
counter(state::AbstractState, action::AbstractAction) = state
counter(state::Vector{<:AbstractState}, action::AbstractAction) = state
counter(state::State, action::IncrementAction) = State(state.counter + 1)
counter(state::State, action::DecrementAction) = State(state.counter - 1)

# create store
store = create_store(counter, State(0))

# get_state
@show get_state(store).counter

# dispatch action
dispatch!(store, INCREMENT)
@show get_state(store).counter

dispatch!(store, DECREMENT)
@show get_state(store).counter