All Projects → nanxiaobei → Flooks

nanxiaobei / Flooks

Licence: mit
🍸 A state manager for React Hooks

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Flooks

mafuba
Simple state container for react apps.
Stars: ✭ 20 (-90.05%)
Mutual labels:  flux, state, store
Iostore
极简的全局数据管理方案,基于 React Hooks API
Stars: ✭ 99 (-50.75%)
Mutual labels:  hooks, state, store
Westore
更好的小程序项目架构
Stars: ✭ 3,897 (+1838.81%)
Mutual labels:  state, store, model
Clean State
🐻 A pure and compact state manager, using React-hooks native implementation, automatically connect the module organization architecture. 🍋
Stars: ✭ 107 (-46.77%)
Mutual labels:  hooks, flux, state
mutable
State containers with dirty checking and more
Stars: ✭ 32 (-84.08%)
Mutual labels:  flux, model, state
RxReduxK
Micro-framework for Redux implemented in Kotlin
Stars: ✭ 65 (-67.66%)
Mutual labels:  flux, state, store
Reatom
State manager with a focus of all needs
Stars: ✭ 567 (+182.09%)
Mutual labels:  flux, state, store
Freezer
A tree data structure that emits events on updates, even if the modification is triggered by one of the leaves, making it easier to think in a reactive way.
Stars: ✭ 1,268 (+530.85%)
Mutual labels:  flux, store
Use Substate
🍙 Lightweight (<600B minified + gzipped) React Hook to subscribe to a subset of your single app state.
Stars: ✭ 97 (-51.74%)
Mutual labels:  hooks, store
Datastore
🐹 Bloat free and flexible interface for data store and database access.
Stars: ✭ 99 (-50.75%)
Mutual labels:  model, store
Tiny Atom
Pragmatic and concise state management.
Stars: ✭ 109 (-45.77%)
Mutual labels:  flux, state
Svelte Store Router
Store-based router for Svelte
Stars: ✭ 54 (-73.13%)
Mutual labels:  state, store
Use Global Context
A new way to use “useContext” better
Stars: ✭ 34 (-83.08%)
Mutual labels:  hooks, state
Mithril Data
A rich data model library for Mithril javascript framework
Stars: ✭ 17 (-91.54%)
Mutual labels:  model, state
Outstated
Simple hooks-based state management for React
Stars: ✭ 102 (-49.25%)
Mutual labels:  hooks, state
Vue State Store
📮 VSS (Vue State Store) - Vue State Management (with Publish & Subscribe pattern)
Stars: ✭ 128 (-36.32%)
Mutual labels:  state, store
Tng Hooks
Provides React-inspired 'hooks' like useState(..) for stand-alone functions
Stars: ✭ 954 (+374.63%)
Mutual labels:  hooks, state
Simpler State
The simplest app state management for React
Stars: ✭ 68 (-66.17%)
Mutual labels:  hooks, state
Fielder
A field-first form library for React and React Native
Stars: ✭ 160 (-20.4%)
Mutual labels:  hooks, state
Redux Zero
A lightweight state container based on Redux
Stars: ✭ 1,977 (+883.58%)
Mutual labels:  flux, state

🍸 flooks 3.0

A state manager for React Hooks, maybe the simplest.

npm GitHub Workflow Status Codecov npm bundle size npm type definitions GitHub

Auto loading state ▨ Modules ▨ Re-render control


English × 简体中文


Install

yarn add flooks

# or

npm install flooks

Example

// counter model

const counter = (now) => ({
  count: 0,
  add() {
    const { count } = now(); // <----- now()        :: get own model
    now({ count: count + 1 }); // <--- now(payload) :: set own model
  },
});

export default counter;
// trigger model

import counter from './counter';

const trigger = (now) => ({
  async addLater() {
    const { add } = now(counter); // <-- now(model) :: get other models
    await new Promise((resolve) => setTimeout(resolve, 1000));
    add();
  },
});

export default trigger;
// App component

import useModel from 'flooks';
import counter from './counter';
import trigger from './trigger';

function App() {
  const { count, add } = useModel(counter, ['count']); // <-- ['count'] :: re-render control
  const { addLater } = useModel(trigger); // <-------- addLater.loading :: auto loading state

  return (
    <>
      <p>{count}</p>
      <button onClick={add}>+</button>
      <button onClick={addLater}>+ ⌛{addLater.loading && '...'}</button>
    </>
  );
}

* Auto loading state - When someFn is async, someFn.loading can be used as its loading state.

Demo

∷ Live demo ∷

API

useModel()

Pass a model, returns the model data.

* Re-render control - useModel(model, deps), deps is optional, same as that of useEffect.

const { a, b } = useModel(someModel, ['a', 'b']);

// useModel(model) <-------------- now(payload) always trigger a re-render
// useModel(model, []) <---------- now(payload) never trigger a re-render
// useModel(model, ['a', 'b']) <-- now(payload) trigger a re-render when a or b inside payload

now()

now is the param to model, can be used in 3 ways.

import anotherModel from './anotherModel';

const ownModel = (now) => ({
  modelFn() {
    const { a, b } = now(); // <-------------- 1. get own model
    now({ a: a + b }); // <------------------- 2. update own model (payload is an object)
    const { x, y } = now(anotherModel); // <-- 3. get other models
  },
});

Philosophy

  • The philosophy of flooks is decentralization, so recommend binding a page component and a model as one.
  • No need to add a file like store.js or models.js, because no need to distribute the store from top now.
  • A model has its own space, when call now(anotherModel) to get other models, all models can be connected.

License

MIT License (c) nanxiaobei

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