520 eve 2021. In the past year, I have been mainly engaged in business, but I have been pursuing and thinking about constantly improving the quality and speed of Coding. By chance, I was fortunate to focus on improving a stable and easy-to-use state management solution.

Welcome to Star and subscribe to my blog.

In the course of my work, I started with Redux, then vuex, then mobx, DVA, React hooks and even my own tools, and finally went back to Redux.

In the meantime, we’ve been looking for solutions that are easy to use and have full type hints. When we enter a keyword or two, the IDE automatically pops up the model corresponding to the Dispatch method, and then enters the empty string “”, automatically prompts for possible methods to be called, etc. There is so much state management code to write that there is no need to repeat things.

So write a new state management library?

Redux is already good, but the code is a bit cumbersome, so why rewrite it? Is redux-based encapsulation feasible?

Should you integrate other routing, modular loading and network request modules and let the user do most of the things through this tool?

This is actually what many integrated frameworks do. But state management is a separate module in itself, not necessarily coupled with other modules. Modularization for the future partial upgrade and transformation of the project to facilitate integration.

Now that we’re talking about type derivation hints, are only TypeScript projects perfectly capable of supporting them?

Of course, many types are defined in TypeScript, but JSDoc annotation type writing now allows JS projects to support type hints and derivations.

Is it compatible with existing projects?

As long as the corresponding rules are followed, it is compatible with normal conditions.

After selling for so long, I will release the project address:

Tredux:github.com/tredux-org/…

It’s not that hard to encapsulate, it’s how to make it cover everyday business development scenarios in the simplest possible usage.

If you think this solution is ok and want to use it in your own project or even your company’s project, but are not comfortable with relying on external libraries, you can put the source code (a TS file) in the project for separate reference.

The existing scheme has been running stably in business projects. Welcome to try it out.

Thank you for taking the time to read this article. If you like this article, please like, bookmark and share, so that more people can see this article, which is also the biggest encouragement and support for me!

Welcome to wechat (search “Su Xiyun’s blog”) orGithubSubscribe to my blog.