redux

package module
v1.5.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2019 License: MIT Imports: 1 Imported by: 0

README

redux

version badges Build Status Build status Go Report Card codecov GoDoc GitHub license

This is a redux implementation in Go.

I hope this project can help you manage the complex update flow in Go.

Origin version

Install

$ go get github.com/dannypsnl/redux

Usage

Basic example

// As you can see, you don't need to checking nil or not now
// Now redux-go will initial the state with zero value of that type
func counter(state int, action string) int {
    switch action {
    case "INC":
        return state + 1
    case "DEC":
        return state - 1
    default:
        return state
    }
}

func main() {
    // redux/v2/store
    store := store.New(counter)
    store.Dispatch("INC")
    fmt.Printf("%d\n", store.StateOf(counter)) // should print out: 1
}

More stunning

func main() {
    counter := func(state, payload int) int {
        return state + payload
    }
    store := store.New(counter)
    store.Dispatch(100)
    store.Dispatch(-50)
    fmt.Printf("%d\n", store.StateOf(counter)) // should print out: 50
}

Documentation

Overview

Package redux provides primitives for manage data by single way flow.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reducer added in v1.5.0

type Reducer func(interface{}, action.Action) interface{}

Directories

Path Synopsis
Package action provides Action implementation for redux
Package action provides Action implementation for redux
example should be empty, it's purpose is let example of doc can appear on godoc page
example should be empty, it's purpose is let example of doc can appear on godoc page
v1
package v1
package v1
Package middleware provides middleware helper type for redux Example: func Logger(s *store.Store) middleware.Middleware { return func(next middleware.Next) middleware.Next { return func(act *action.Action) *action.Action { return next(act) } } }
Package middleware provides middleware helper type for redux Example: func Logger(s *store.Store) middleware.Middleware { return func(next middleware.Next) middleware.Next { return func(act *action.Action) *action.Action { return next(act) } } }
rematch provide rematch API Example: func counter(s interface{}, a action.Action) interface{} { return reCounter.Reduce()(s, a) } func init() { reCounter = rematch.Reducer { State: 0, Reducers: rematch.Reducers { "INC": func(state interface{}, act action.Action) interface{} { return state.(int)+act.Args["payload"].(int) }, "DEC": func(state interface{}, act action.Action) interface{} { return state.(int)-act.Args["payload"].(int) }, } } } func main() { store := store.New(counter) store.Dispatch(reCounter.
rematch provide rematch API Example: func counter(s interface{}, a action.Action) interface{} { return reCounter.Reduce()(s, a) } func init() { reCounter = rematch.Reducer { State: 0, Reducers: rematch.Reducers { "INC": func(state interface{}, act action.Action) interface{} { return state.(int)+act.Args["payload"].(int) }, "DEC": func(state interface{}, act action.Action) interface{} { return state.(int)-act.Args["payload"].(int) }, } } } func main() { store := store.New(counter) store.Dispatch(reCounter.
Package store provides the store implement for redux.
Package store provides the store implement for redux.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL