GithubHelp home page GithubHelp logo

tangchang / icestore Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ice-lab/icestore

0.0 1.0 0.0 370 KB

🌩 Simple and friendly state for React

License: MIT License

JavaScript 0.45% TypeScript 99.55%

icestore's Introduction

English | įŽ€äŊ“中文

icestore

Simple and friendly state for React.

NPM version Package Quality build status NPM downloads Known Vulnerabilities David deps codecov

🕹 CodeSandbox demos 🕹
Counter Todos

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.

Basic example

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

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

// 1ī¸âƒŖ Use a model to define your store
const counter = {
  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

Documents

Examples

Browser Compatibility

Chrome Firefox Edge IE Safari Opera UC
✔ ✔ ✔ 9+ ✔ ✔ ✔ ✔

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.

If you're interested in icestore, see CONTRIBUTING.md for more information to learn how to get started.

ICE Ecosystem

Project Version Docs Description
icejs icejs-status docs A universal framework based on react.js
icestark icestark-status docs Micro Frontends solution for large application
icestore icestore-status docs Simple and friendly state for React
iceworks iceworks-status docs Universal Application Development Pack for VS Code

Community

DingTalk community GitHub issues Gitter
issues gitter

License

MIT

icestore's People

Contributors

alvinhui avatar temper357 avatar imsobear avatar luhc228 avatar lucifer1004 avatar phobal avatar beizhedenglong avatar namepain avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤ī¸ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.