All Projects → stadux → stadux

stadux / stadux

Licence: other
No description or website provided.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to stadux

react-immer
No nonsense state management with Immer and React hooks
Stars: ✭ 13 (-13.33%)
Mutual labels:  state-management
okito
Your best flutter coding friend. All in one; state management, navigation management(with dynamic routing), local storage, localization, dependency injection, cool extensions with best usages and with the support of best utilities!
Stars: ✭ 37 (+146.67%)
Mutual labels:  state-management
NestedReact
BackboneJS compatibility layer for React-MVx MVVM framework.
Stars: ✭ 79 (+426.67%)
Mutual labels:  state-management
vue-reactive-store
A VueX alternative : declarative + reactive + centralized way to structure your data store. Inspired by VueX and Vue.js . Compatible with vue-devtools.
Stars: ✭ 27 (+80%)
Mutual labels:  state-management
lamp-luwak
Service-oriented state management for React
Stars: ✭ 12 (-20%)
Mutual labels:  state-management
react-without-redux
React State Management without Redux
Stars: ✭ 33 (+120%)
Mutual labels:  state-management
xstate.dart
xstate for dart & flutter
Stars: ✭ 31 (+106.67%)
Mutual labels:  state-management
useSharedState
useSharedState is a simple hook that can be used to share state between multiple React components.
Stars: ✭ 0 (-100%)
Mutual labels:  state-management
beyond
An approach to scalable Flutter development
Stars: ✭ 55 (+266.67%)
Mutual labels:  state-management
Teapot
Unidirectional Dataflow library for Android inspired by The Elm Architecture
Stars: ✭ 29 (+93.33%)
Mutual labels:  state-management
react-mlyn
react bindings to mlyn
Stars: ✭ 19 (+26.67%)
Mutual labels:  state-management
vuex-dry
[NO LONGER MAINTAINED] `vuex-dry` helps keep your vuex codes DRY.
Stars: ✭ 55 (+266.67%)
Mutual labels:  state-management
xstate
State machines and statecharts for the modern web.
Stars: ✭ 21,286 (+141806.67%)
Mutual labels:  state-management
ReduxSimple
Simple Stupid Redux Store using Reactive Extensions
Stars: ✭ 119 (+693.33%)
Mutual labels:  state-management
tstate-machine
TypeScript implementation of State Manager(like StateMachine)
Stars: ✭ 20 (+33.33%)
Mutual labels:  state-management
devon4flutter-non-bloc-arch
A guide aiming to bridge the gap between the absolute Flutter basics and clean, structured Flutter Development
Stars: ✭ 283 (+1786.67%)
Mutual labels:  state-management
dobux
🍃 Lightweight responsive state management solution.
Stars: ✭ 75 (+400%)
Mutual labels:  state-management
agile
🌌 Global State and Logic Library for JavaScript/Typescript applications
Stars: ✭ 90 (+500%)
Mutual labels:  state-management
redux-auto
Automatically generate Redux stories and actions from your folder and file structure
Stars: ✭ 43 (+186.67%)
Mutual labels:  state-management
Flutter Roadmap
This is a flutter roadmap and documentation repository. If anyone is interested you can join the party to help the community and make flutter great again.
Stars: ✭ 47 (+213.33%)
Mutual labels:  state-management

stadux

npm bundle size

A state manager that is highly inspired by Effector but much simpler with only about 100 lines of code.

Introduction

Stadux is an multi-store state manager for Javascript apps (React/React Native/Node.js), that allows you to manage data in complex applications without the risk of inflating the monolithic central store, with clear control flow, good type support and high capacity API. Stadux supports TypeScript out of the box.

Core concepts

  • Event Event is a function that describe what happened.
  • Store Store is the unit of state that you want to manage and will update according to the event.
  • Effect Side effect is hard to manage and effect will fire event when side effect start, done or failed.

That's all the connect that you need to know!

Installation

npm install --save stadux
# or
yarn add stadux

API

createEvent

// create event with `string` type of payload
const sayHi = createEvent<string>()

// you can watch for the event to happen
sayHi.watch(console.log)

// fire the event with payload
sayHi('Peter') // Peter
sayHi('Drew')  // Drew

createStore

const increment = createEvent('increment')
const decrement = createEvent('decrement')
const resetCounter = createEvent('reset counter')

const counter = createStore(0) // create store with init value
  .on(increment, state => state + 1) // update when event fired
  .on(decrement, state => state - 1)
  .reset(resetCounter) // reset when event fired

counter.watch(console.log) // you can also watch to the store

increment()    // State: 1
decrement()    // State: 0
decrement()    // State: -1
resetCounter() // State: 0
increment()    // State: 1

// use `gestState` to get value in store
const count = counter.getState()
// you can also use select to map value in the store
const greaterThan10 = counter.select(v => v > 10)

createEffect

type Todo = { name: string }
// build an effect to fetch API
const fetchTodoList = createEffect<
  { token: string }, // params of effect function
  Todo[] // response
>(({ token }) => axios.get(`https://todos?token=${token}`).then(v => v.data))

const todoList = createStore<{
  todos: Todo[]
  loading: boolean
  error: string
}>({ todos: [], loading: false, error: '' })
  .on(fetchTodoList.start, (state, payload) => ({
    ...state,
    loading: true,
    error: '',
  }))
  .on(fetchTodoList.done, (state, { result }) => ({
    ...state,
    todos: result,
    loading: false,
    error: '',
  }))
  .on(fetchTodoList.fail, (state, { error }) => ({
    ...state,
    loading: false,
    error: error.message,
  }))

// after fetchTodoList been called, it will fire `fetchTodoList.start`
// when fetch todo list succeed, it will fire `fetchTodoList.done` event with respond value
// when fetch todo list failed, it will fire `fetchTodoList.fail` event with error reason
fetchTodoList({ token: '' })

Use in React

npm install --save stadux-react
# or
yarn add stadux-react
const increment = createEvent()
const decrement = createEvent()
const resetCounter = createEvent()
const counter = createStore(0)
  .on(increment, state => state + 1)
  .on(decrement, state => state - 1)
  .reset(resetCounter)

const CountComponent = () => {
  const count = useStore(counter)

  return <div>Count is: {count}</div>
}
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].