But I still want to tease:

What provider, connections, Actions, reducers, Effects, Dispatch, PUT, Call, payload, @Observable, @computed, @observer, @inject…

A bunch of template code, concepts, philosophical principles… There are tons of apis.

I just want to get off the page early, get off the gym early, accompany girls…

So, I want a state management library like this:

  • Lightweight individuals do more mobile development
  • No template code, minimal Api
  • It’s intuitive and doesn’t have a complicated concept. Just change the action to state
  • Clarity makes it easier to write maintainable and readable code
  • High efficiency higher development efficiency, this is important
  • Typescript state and Action support intelligent hints highly

I am a pragmatist. Development efficiency, code maintainability and readability, and development experience are more important than all kinds of paradigms and theories. There is no need to be pure.

One day, I saw the immer of mobx author, and I felt that using immer, I could realize the ideal state management tool, so I built a wheel called Stamen, what’s the feature of it? Show you the code: Stamen.

If there is a core feature, it should be “brevity”, meaning that users can write code with brevity and focus on the business rather than their own source code, leaving the problem to users.

CodeSandbox example: on the Basic | Async

The usage is relatively simple:

import React from 'react';
import { render } from 'react-dom';
import { createStore } from 'stamen';

const { consume, mutate } = createStore({ count: 1 });

const App = (a)= > (
  <div>
    <span>{consume(state => state.count)}</span>
    <button onClick={()= > mutate(state => state.count--)}>-</button>
    <button onClick={()= > mutate(state => state.count++)}>+</button>
  </div>
);

render(<App />, document.getElementById('root'));
Copy the code

Only state and Action, no other concepts, only one API:

const { consume, mutate } = createStore({ count: 1 });
Copy the code

The Stamen code implementation is only 40 lines long, which is more than enough functionality for most projects.

For more usage, see:

Making: github.com/forsigner/s… Documents: forsigner.com/stamen-zh-c…