rematch

package
Version: 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: 3 Imported by: 0

Documentation

Overview

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.
        Action("INC").
            Arg("payload", 10))
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reducer

type Reducer struct {
	State    interface{}
	Reducers Reducers
}

Reducer provide a readable structure help you build reducer more rematchable

Example:

var r rematch.Reducer
func init() {
    r = Reducer {
        State: 0,
        Reducers: rematch.Reducers {
            "INC": func(s interface{}, a action.Action) interface{} {
                return s.(int) + 1
            }
        },
    }
}

!Note: the limit at here is store using function address generate reducer name, so we have to use Reduce and a func proxy to using rematch Reducer

func (*Reducer) Action

func (r *Reducer) Action(typ string) *action.Action

Action in rematch Reducer help us detect only the action exist in this rematch Reducer can be using

Else will panic

func (*Reducer) Reduce

func (r *Reducer) Reduce() redux.Reducer

Reduce return store acceptable reducer(func form)

Usage:

func reducer(s interface{}, a action.Action) interface{} {
    return r.Reduce()(s, a)
}

type Reducers

type Reducers map[string]redux.Reducer

Reducers let we can meta reducer group much more readable

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL