SkillAgentSearch skills...

Gredux

a predictable, immutable state container in go

Install / Use

/learn @avahowell/Gredux
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

gredux

Go Report Card Build Status codecov GoDoc

gredux is a golang implementation of a redux-esque state container. The aim is to provide a structure for writing applications which have consistent, predictable behaviour.

Example Usage


import (
	"github.com/avahowell/gredux"
)

// Create an initial state for the Store
type counterState struct {
	count int
}

// Instantiate a new store around this state
store := gredux.New(counterState{0})

// Create a reducer which increments "count" when it receives an "increment" 
// action, and decrements when it receives a "decrement" action.
store.Reducer(func(state gredux.State, action gredux.Action) gredux.State {
	switch action.ID {
	case "increment":
		return counterState{state.(counterState).count + action.Data.(int)}
	case "decrement":
		return counterState{state.(counterState).count - action.Data.(int)}
	default:
		return state
	}
})

store.Dispatch(Action{"increment", 5})
store.Dispatch(Action{"decrement", 2})

fmt.Println(store.State().(counterState).count) // prints 3

// Register a func to be called after each state update
store.AfterUpdate(func(state State) {
	fmt.Println(state.(counterState).count) // prints the count after every state update
})
store.Dispatch(Action{"decrement", 2})

License

The MIT License (MIT)

View on GitHub
GitHub Stars96
CategoryDevelopment
Updated2mo ago
Forks5

Languages

Go

Security Score

95/100

Audited on Jan 25, 2026

No findings