Documentation
¶
Overview ¶
Package redux provides a simple implementation of a Redux-like state management library in Go.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type QuitUpdate ¶ added in v0.7.7
type QuitUpdate struct{}
QuitUpdate is the type of the quit update of the store.
type StateChange ¶ added in v0.7.5
type StateChange[S State] interface { // Prev gets the previous state of the store. Prev() S // Curr gets the current state of the store. Curr() S }
StateChange is the type of the state change of the store.
func NewStateChange ¶ added in v0.7.5
func NewStateChange[S State](prev, curr S) StateChange[S]
NewStateChange creates a new state change.
type Store ¶
type Store[S State] interface { // Dispatch dispatches an event to the store. Dispatch(actions ...Action) // State gets the current state of the store. State(s ...S) S // Dispose disposes the store. Dispose() Subscription[S] }
Store is the type of the store.
func New ¶
New creates a new store.
Example ¶
package main
import (
"context"
"fmt"
"github.com/katallaxie/pkg/redux"
)
func main() {
type noopState struct {
Name string
}
r := func(_ noopState, _ redux.Update) noopState {
return noopState{Name: "bar"}
}
a := func() redux.Update {
return "foo"
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
s := redux.New(ctx, noopState{Name: "foo"}, r)
defer s.Dispose()
sub := s.Subscribe()
s.Dispatch(a)
out := <-sub
fmt.Println(out.Curr(), out.Prev())
}
Output: {bar} {foo}
type Subscription ¶
type Subscription[S State] interface { // Subscribe subscribes to the store. Subscribe() <-chan StateChange[S] // Cancel cancels the subscription. CancelSubscription(<-chan StateChange[S]) }
Subscription is the type of the subscription of the store.
Click to show internal directories.
Click to hide internal directories.