All Projects → luisvinicius167 → Godux

luisvinicius167 / Godux

Licence: mit
State Management for Go Backend application inspired in Redux.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Godux

Xinglie.github.io
blog
Stars: ✭ 146 (-34.23%)
Mutual labels:  state
Redux Zero
A lightweight state container based on Redux
Stars: ✭ 1,977 (+790.54%)
Mutual labels:  state
Flooks
🍸 A state manager for React Hooks
Stars: ✭ 201 (-9.46%)
Mutual labels:  state
React Copy Write
✍️ Immutable state with a mutable API
Stars: ✭ 1,810 (+715.32%)
Mutual labels:  state
Mobx Rest
REST conventions for Mobx
Stars: ✭ 164 (-26.13%)
Mutual labels:  state
Pagestatemanager
manage the loading,emtpy,error state of page, use in xml or just in code
Stars: ✭ 173 (-22.07%)
Mutual labels:  state
Android Statefullayout
A custom Android ViewGroup to display different states of screen (CONTENT, PROGRESS, OFFLINE, EMPTY, etc.)
Stars: ✭ 140 (-36.94%)
Mutual labels:  state
React Easy State
Simple React state management. Made with ❤️ and ES6 Proxies.
Stars: ✭ 2,459 (+1007.66%)
Mutual labels:  state
Simpler State
The simplest app state management for React
Stars: ✭ 68 (-69.37%)
Mutual labels:  state
Statefulviewcontroller
Placeholder views based on content, loading, error or empty states
Stars: ✭ 2,139 (+863.51%)
Mutual labels:  state
Go Sdk
Dapr SDK for go
Stars: ✭ 149 (-32.88%)
Mutual labels:  state
Fielder
A field-first form library for React and React Native
Stars: ✭ 160 (-27.93%)
Mutual labels:  state
Valtio
💊 Valtio makes proxy-state simple for React and Vanilla
Stars: ✭ 3,389 (+1426.58%)
Mutual labels:  state
Svelte Css Vars
✨ Ever wanted to have reactive css variables in svelte? What if I told you there's a way?
Stars: ✭ 150 (-32.43%)
Mutual labels:  state
Store
A beautifully-simple framework-agnostic modern state management library.
Stars: ✭ 204 (-8.11%)
Mutual labels:  state
Contextism
😍 Use React Context better.
Stars: ✭ 141 (-36.49%)
Mutual labels:  state
Retalk
🐤 The Simplest Redux
Stars: ✭ 168 (-24.32%)
Mutual labels:  state
React Organism
Dead simple React state management to bring pure components alive
Stars: ✭ 219 (-1.35%)
Mutual labels:  state
Save Page State
A chrome extension to save the state of a page for further analysis
Stars: ✭ 208 (-6.31%)
Mutual labels:  state
Hydrated bloc
An extension to the bloc state management library which automatically persists and restores bloc states.
Stars: ✭ 181 (-18.47%)
Mutual labels:  state

godux

Join the chat at https://gitter.im/luisvinicius167/godux Go Report Card

State Management for Go Backend applications inspired by Redux.

Godux

╔═════════╗       ╔══════════╗       ╔═══════════╗       ╔═════════════════╗
║ Action  ║──────>║ Reducer  ║ ────> ║   Store   ║ ────> ║   Application   ║
╚═════════╝       ╚══════════╝       ╚═══════════╝       ╚═════════════════╝
     ^                                                            │
     └────────────────────────────────────────────────────────────┘

Install

  • Go: go get github.com/luisvinicius167/godux

Data Flow

godux gives go unidirectional data flow:

  • The Action returns a small map with specific directions that are dispatched to a Reducer.
  • The Reducer is a pure function (pure functions don't change original arguments) if relevant to it returns a new Value.
  • The Value becomes the new State of the Store.

Principles:

  • Global application state is held in the Store, as a single map.
  • State is ready-only (only change it only by replacing it with the Reducer).
  • Changes are made with pure functions - Actions/Reducers that do not change the actual object but make a changed copy.

Store:

A Store is basically a container that holds your application state.

    store := godux.NewStore()
	store.Setstate("count", 1)
    store.Setstate("Title", "I like godux!")

Action

Actions are just pure functions which pass on their inputs when they're dispatched. Actions are stored on the godux map as godux.Action.

    increment := func(number int) godux.Action {
		return godux.Action{
			Type:  "INCREMENT",
			Value: number,
		}
	}

Reducers

As in Redux:

"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".

Reducers are pure functions that take in actions and the state of the store as inputs and leave them all as they came in (aka. pure)-- especially the original state of the store must not be modified (it's accessed by store.GetState)).

    // reducer function
	reducer := func(action godux.Action) interface{} {
		switch action.Type {
		case "INCREMENT":
			return store.GetState("count").(int) + action.Value.(int)
		case "DECREMENT":
			return action.Value.(int) - store.GetState("count").(int)
		default:
			return store.GetAllState()
		}
	}
	// Add your reducer function to return new values basend on your state
	store.Reducer(reducer)

Dispatch

Dispatching an action is very easy.

    // Receive new value
	newCount := store.Dispatch(increment(1)) // return 2

API Reference

  • Store:

    • godux.newStore(): Create a single store with the state of your application (should only be used once).
    • godux.SetState(name string, value interface{}): Sets the state of the store.
    • godux.GetState(name string): Return a state's value.
    • godux.GetAllState(): Return the whole state as a map.
  • Reducer:
    • store.Reducer(func(action godux.Action)): Adding a reducer function to your Store.
  • Dispatch:
    • store.Dispatch(action godux.Action): Dispatching an action to your Reducer.
  • Action:

    • godux.Action( Type string, Value interface{}): Adding an easily available Action.

License

MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].