Skip to content

Gnimuc/Redux.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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