8000 GitHub - liyunsong/retalk: 🐤 Redux never so simple
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

liyunsong/retalk

 
 

Repository files navigation

Retalk

Retalk is a best practice for Redux. just simple, smooth, and smart.

Travis Codecov npm version npm downloads license

English | 简体中文


Features

  • Simplest Redux: Just state and actions, clear than ever before.
  • Two API totally: createStore and withStore, no more annoying concepts.
  • Async import model: Fully code splitting support for models.
  • Auto loading state: Send request, and loading state is ready to use.

Install

Yarn

yarn add retalk

npm

npm install retalk

Usage

1. Model

const model = {
  state: {
    value: 0,
  },
  actions: {
    add() {
      const { value } = this.state; // this.state -> Get state
      this.setState({ value: value + 1 }); // this.setState -> Set state
    },
    async asyncAdd() {
      await new Promise((resolve) => setTimeout(resolve, 1000));
      this.add(); // this[actionName] -> Call action
    },
  },
};

export default model;

2. Store

import { createStore } from 'retalk';
import demo from './demo/model';

const store = createStore({
  demo,
});

export default store;

3. View

import React from 'react';
import { connect } from 'react-redux';
import { withStore } from 'retalk';

const Demo = ({ value, add, asyncAdd, loading }) => (
  <div>
    <h4>Value: {value}</h4>
    <button onClick={add}>+1</button>
    <button onClick={asyncAdd}>Async +1 {loading.asyncAdd ? '...' : ''}</button>
  </div>
);
// loading[asyncAction] -> Async action's loading status

export default connect(...withStore('demo'))(Demo);

Well, only 3 steps, A simple Retalk demo is here. https://codesandbox.io/s/5l9mqnzvx

Documentation

See more details in the documentation.

Retalk uses Proxy, if old browsers not support, please try proxy-polyfill.

Changelog

See what's new in the changelog.

About

🐤 Redux never so simple

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%
0