2.0.4 • Published 9 months ago

@ice/store v2.0.4

Weekly downloads
131
License
MIT
Repository
github
Last release
9 months ago

English | 简体中文

icestore

Simple and friendly state for React.

NPM version build status NPM downloads codecov

Versions

VersionBranchDocs
V2masterDocs
V1stable/1.xDocs

Introduction

icestore is a simple and friendly state management library for React. It has the following core features:

  • Minimal & Familiar API: No additional learning costs, easy to get started with the knowledge of Redux && React Hooks.
  • Built in Async Status: Records loading and error status of effects, simplifying the rendering logic in the view layer.
  • Class Component Support: Make old projects enjoying the fun of lightweight state management with friendly compatibility strategy.
  • TypeScript Support: Provide complete type definitions to support intelliSense in VS Code.

See the comparison table for more details.

Documents

Examples

Basic example

import React from 'react';
import ReactDOM from 'react-dom';
import { createStore, createModel } from '@ice/store';

const delay = (time) =>
  new Promise((resolve) => setTimeout(() => resolve(), time));

// 1️⃣ Use a model to define your store
const counter = createModel({
  state: 0,
  reducers: {
    increment: (prevState) => prevState + 1,
    decrement: (prevState) => prevState - 1,
  },
  effects: () => ({
    async asyncDecrement() {
      await delay(1000);
      this.decrement();
    },
  }),
});

const models = {
  counter,
};

// 2️⃣ Create the store
const store = createStore(models);

// 3️⃣ Consume model
const { useModel } = store;
function Counter() {
  const [count, dispatchers] = useModel('counter');
  const { increment, asyncDecrement } = dispatchers;
  return (
    <div>
      <span>{count}</span>
      <button type="button" onClick={increment}>
        +
      </button>
      <button type="button" onClick={asyncDecrement}>
        -
      </button>
    </div>
  );
}

// 4️⃣ Wrap your components with Provider
const { Provider } = store;
function App() {
  return (
    <Provider>
      <Counter />
    </Provider>
  );
}

const rootElement = document.getElementById('root');
ReactDOM.render(<App />, rootElement);

Installation

icestore requires React 16.8.0 or later.

npm install @ice/store --save

Inspiration

icestore refines and builds upon the ideas of rematch & constate.

Contributors

Feel free to report any questions as an issue, we'd love to have your helping hand on icestore.

Develop:

$ cd icestore/
$ npm install
$ npm run test
$ npm run watch

$ cd examples/counter
$ npm install
$ npm link ../../                    # link icestore
$ npm link ../../node_modules/react  # link react
$ npm start

License

MIT

2.0.4

9 months ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

2.0.0-4

3 years ago

2.0.0-3

3 years ago

2.0.0-2

3 years ago

2.0.0-0

3 years ago

1.4.3

3 years ago

1.4.3-6

3 years ago

1.4.3-5

3 years ago

1.4.3-2

3 years ago

1.4.3-1

3 years ago

1.4.3-4

3 years ago

1.4.3-3

3 years ago

1.4.3-0

3 years ago

1.4.2

4 years ago

1.4.1

4 years ago

1.4.1-beta-0

4 years ago

1.4.0

4 years ago

1.4.0-beta-1

4 years ago

1.4.0-beta-0

4 years ago

1.3.5

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.2-beta-0

4 years ago

1.3.0-beta-3

4 years ago

1.3.0-beta-4

4 years ago

1.3.0-beta-5

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.3.0-beta-2

4 years ago

1.3.0-beta-0

4 years ago

1.3.0-beta-1

4 years ago

1.2.0

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.1.0-beta-0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.0.0-beta-3

4 years ago

1.0.0-beta.2

4 years ago

1.0.0-beta.0

4 years ago

0.4.7

4 years ago

0.4.6

4 years ago

0.4.5

4 years ago

0.4.4

4 years ago

0.4.3

4 years ago

0.4.2

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.4.0-alpha.2

4 years ago

0.4.0-alpha.1

4 years ago

0.3.0

5 years ago

0.2.4

5 years ago

0.1.6

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago