Documentation ¶
Overview ¶
Package godux implements a state management for your backend application. It's inspired in Redux, but with simplest concepts. - State: Your application state don't change. - Actions: Your action is used in reducers, to return new value based on State. - Reducers: Actions describe the fact that something happened, but don’t specify how the application’s state changes in response. This is the job of a reducer.
This library was inspired in Redux.
Example ¶
package main import ( "fmt" "github.com/luisvinicius167/godux" ) func main() { // Creating new Store store := godux.NewStore() // Set state store.SetState("count", 1) // Creating new Action increment := func(number int) godux.Action { return godux.Action{ Type: "INCREMENT", Value: number, } } decrement := func(number int) godux.Action { return godux.Action{ Type: "DECREMENT", Value: number, } } // reducer function reducer := func(action godux.Action) interface{} { switch action.Type { case "INCREMENT": return store.GetState("count").(int) + action.Value.(int) case "DECREMENT": return store.GetState("count").(int) - action.Value.(int) default: return store.GetAllState() } } // Add your reducer function to return new values based on your state store.Reducer(reducer) // Receive new value newCount := store.Dispatch(increment(10)) // 1+10=11 subCount := store.Dispatch(decrement(10)) // 1-10=-9 fmt.Printf("Your Store state is: %d. Your newCount is: %d. Your subCount is: %d\n", store.GetState("count"), newCount, subCount) }
Output: Your Store state is: 1. Your newCount is: 11. Your subCount is: -9
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action struct { Type string Value interface{} }
Action that you create to change the State
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store Your central store that has your application state
func (*Store) GetAllState ¶
func (s *Store) GetAllState() interface{}
GetAllState return a full copy of the current state.
Click to show internal directories.
Click to hide internal directories.