1- English | [ 简体中文 ] ( ./README.zh-CN .md )
1+ 简体中文 | [ English ] ( ./README.cn .md )
22
33# icestore
44
5- > Simple and friendly state for React.
5+ > 简单友好的状态管理方案。
66
77[ ![ NPM version] ( https://img.shields.io/npm/v/@ice/store.svg?style=flat )] ( https://npmjs.org/package/@ice/store )
8- [ ![ Package Quality] ( https://npm.packagequality.com/shield/@ice%2Fstore.svg )] ( https://packagequality.com/#?package=@ice/store )
9- [ ![ build status] ( https://img.shields.io/travis/ice-lab/icestore.svg?style=flat-square )] ( https://travis-ci.org/ice-lab/icestore )
8+ [ ![ build status] ( https://github.com/ice-lab/icestore/actions/workflows/ci.yml/badge.svg )] ( https://github.com/ice-lab/icestore/actions/workflows/ci.yml )
109[ ![ NPM downloads] ( http://img.shields.io/npm/dm/@ice/store.svg?style=flat )] ( https://npmjs.org/package/@ice/store )
11- [ ![ Known Vulnerabilities] ( https://snyk.io/test/npm/@ice/store/badge.svg )] ( https://snyk.io/test/npm/@ice/store )
12- [ ![ David deps] ( https://img.shields.io/david/ice-lab/icestore.svg?style=flat-square )] ( https://david-dm.org/ice-lab/icestore )
1310[ ![ codecov] ( https://codecov.io/gh/ice-lab/icestore/branch/master/graph/badge.svg )] ( https://codecov.io/gh/ice-lab/icestore )
1411
15- <table >
16- <thead >
17- <tr>
18- <th colspan="5"><center>🕹 CodeSandbox demos 🕹</center></th>
19- </tr>
20- </thead >
21- <tbody >
22- <tr>
23- <td><a href="https://codesandbox.io/s/github/ice-lab/icestore/tree/master/examples/counter?module=/src/index.tsx">Counter</a></td>
24- <td><a href="https://codesandbox.io/s/github/ice-lab/icestore/tree/master/examples/todos?module=/src/index.tsx">Todos</a></td>
25- </tr>
26- </tbody >
27- </table >
12+ ## 版本
2813
29- ## Introduction
14+ | 版本 | 代码分支 | 文档 |
15+ | --- | --- | --- |
16+ | V2 | master | [ Docs] ( https://github.com/ice-lab/icestore#documents )
17+ | V1 | stable/1.x | [ Docs] ( https://github.com/ice-lab/icestore/tree/stable/1.x#documents )
3018
31- icestore is a simple and friendly state management library for React. It has the following core features:
19+ ## 安装
3220
33- - ** Minimal & Familiar API** : No additional learning costs, easy to get started with the knowledge of Redux && React Hooks.
34- - ** Built in Async Status** : Records loading and error status of effects, simplifying the rendering logic in the view layer.
35- - ** Class Component Support** : Make old projects enjoying the fun of lightweight state management with friendly compatibility strategy.
36- - ** TypeScript Support** : Provide complete type definitions to support intelliSense in VS Code.
21+ icestore 是面向 React 应用的、简单友好的状态管理方案。它包含以下核心特征:
3722
38- See the [ comparison table] ( docs/recipes.md#Comparison ) for more details.
23+ * ** 简单、熟悉的 API** :不需要额外的学习成本,只需要了解 React Hooks,对 Redux 用户友好。
24+ * ** 集成异步处理** :记录异步操作时的执行状态,简化视图中对于等待或错误的处理逻辑。
25+ * ** 支持组件 Class 写法** :友好的兼容策略可以让老项目享受轻量状态管理的乐趣。
26+ * ** 良好的 TypeScript 支持** :提供完整的 TypeScript 类型定义,在 VS Code 中能获得完整的类型检查和推断。
3927
40- ## Basic example
28+ 查看[ 《能力对比表》] ( docs/recipes.md#Comparison ) 了解更多细节。
29+
30+ ## 示例
31+
32+ - [ Counter] ( https://codesandbox.io/s/github/ice-lab/icestore/tree/master/examples/counter )
33+ - [ Todos] ( https://codesandbox.io/s/github/ice-lab/icestore/tree/master/examples/todos )
34+ - [ Class Component Support] ( https://codesandbox.io/s/github/ice-lab/icestore/tree/master/examples/classComponent )
35+ - [ withModel] ( https://codesandbox.io/s/github/ice-lab/icestore/tree/master/examples/withModel )
36+
37+ ## 快速开始
4138
4239``` jsx
4340import React from ' react' ;
4441import ReactDOM from ' react-dom' ;
4542import { createStore } from ' @ice/store' ;
4643
47- const delay = (time ) =>
48- new Promise ((resolve ) => setTimeout (() => resolve (), time));
44+ const delay = (time ) => new Promise ((resolve ) => setTimeout (() => resolve (), time));
4945
50- // 1️⃣ Use a model to define your store
46+ // 1️⃣ 使用模型定义你的状态
5147const counter = {
5248 state: 0 ,
5349 reducers: {
54- increment : (prevState ) => prevState + 1 ,
55- decrement : (prevState ) => prevState - 1 ,
50+ increment : (prevState ) => prevState + 1 ,
51+ decrement : (prevState ) => prevState - 1 ,
5652 },
5753 effects : () => ({
5854 async asyncDecrement () {
5955 await delay (1000 );
6056 this .decrement ();
6157 },
62- }),
58+ })
6359};
6460
6561const models = {
6662 counter,
6763};
6864
69- // 2️⃣ Create the store
65+ // 2️⃣ 创建 Store
7066const store = createStore (models);
7167
72- // 3️⃣ Consume model
68+ // 3️⃣ 消费模型
7369const { useModel } = store;
7470function Counter () {
75- const [count , dispatchers ] = useModel (' counter' );
71+ const [ count , dispatchers ] = useModel (' counter' );
7672 const { increment , asyncDecrement } = dispatchers;
7773 return (
7874 < div>
7975 < span> {count}< / span>
80- < button type= " button" onClick= {increment}>
81- +
82- < / button>
83- < button type= " button" onClick= {asyncDecrement}>
84- -
85- < / button>
76+ < button type= " button" onClick= {increment}> + < / button>
77+ < button type= " button" onClick= {asyncDecrement}> - < / button>
8678 < / div>
8779 );
8880}
8981
90- // 4️⃣ Wrap your components with Provider
82+ // 4️⃣ 绑定视图
9183const { Provider } = store;
9284function App () {
9385 return (
@@ -101,50 +93,35 @@ const rootElement = document.getElementById('root');
10193ReactDOM .render (< App / > , rootElement);
10294```
10395
104- ## Installation
96+ ## 安装
10597
106- icestore requires React 16.8.0 or later.
98+ 使用 icestore 需要 React 在 16.8.0 版本以上。
10799
108100``` bash
109- npm install @ice/store --save
101+ $ npm install @ice/store --save
110102```
111103
112- ## Documents
104+ ## 文档
113105
114106- [ API] ( ./docs/api.md )
115- - [ Recipes] ( ./docs/recipes.md )
116- - [ Upgrade Guidelines] ( ./docs/upgrade-guidelines.md )
117- - [ Migration] ( ./docs/migration.md )
118- - [ Q & A] ( ./docs/qna.md )
119-
120- ## Examples
121-
122- - [ Counter] ( https://codesandbox.io/s/github/ice-lab/icestore/tree/master/examples/counter )
123- - [ Todos] ( https://codesandbox.io/s/github/ice-lab/icestore/tree/master/examples/todos )
124- - [ Class Component Support] ( https://codesandbox.io/s/github/ice-lab/icestore/tree/master/examples/classComponent )
125- - [ withModel] ( https://codesandbox.io/s/github/ice-lab/icestore/tree/master/examples/withModel )
126-
127- ## Browser Compatibility
128-
129- | ![ Chrome] ( https://raw.github.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png ) | ![ Firefox] ( https://raw.github.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png ) | ![ Edge] ( https://raw.github.com/alrra/browser-logos/master/src/edge/edge_48x48.png ) | ![ IE] ( https://raw.github.com/alrra/browser-logos/master/src/archive/internet-explorer_9-11/internet-explorer_9-11_48x48.png ) | ![ Safari] ( https://raw.github.com/alrra/browser-logos/master/src/safari/safari_48x48.png ) | ![ Opera] ( https://raw.github.com/alrra/browser-logos/master/src/opera/opera_48x48.png ) | ![ UC] ( https://raw.github.com/alrra/browser-logos/master/src/uc/uc_48x48.png ) |
130- | :--------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------: | :--------------------------------------------------------------------------: |
131- | ✔ | ✔ | ✔ | 9+ ✔ | ✔ | ✔ | ✔ |
132-
133- ## Inspiration
107+ - [ 更多技巧] ( ./docs/recipes.md )
108+ - [ 从 V1 版本升级] ( ./docs/upgrade-guidelines.md )
109+ - [ 常见问题] ( ./docs/qna.md )
134110
135- icestore refines and builds upon the ideas of [ rematch ] ( https://github.com/rematch/rematch ) & [ constate ] ( https://github.com/diegohaz/constate ) .
111+ ## 灵感
136112
137- ## Contributors
113+ 创造 icestore 的灵感来自于 [ rematch ] ( https://github.com/rematch/rematch ) 和 [ constate ] ( https://github.com/diegohaz/constate ) 。
138114
139- Feel free to report any questions as an [ issue ] ( https://github.com/ice-lab/icestore/issues/new ) , we'd love to have your helping hand on icestore.
115+ ## 参与贡献
140116
141- If you're interested in icestore, see [ CONTRIBUTING.md ] ( https://github.com/alibaba/ ice/blob/master/.github/CONTRIBUTING.md ) for more information to learn how to get started.
117+ 欢迎通过 [ issue ] ( https://github.com/ice-lab/icestore/issues/new ) 反馈问题。
142118
143- Develop :
119+ 开发 :
144120
145121``` bash
146122$ cd icestore/
147123$ npm install
124+ $ npm run test
148125$ npm run watch
149126
150127$ cd examples/counter
0 commit comments