1.2.0 • Published 5 years ago

react-state-modules v1.2.0

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

React State Modules

React State Modules mmakes it simple to connect your React Components to any of your State Modules easily. It provides a convenient mechanism that is meant to work similar to the react-redux connection pattern. state-modules is an Application State Manager which produces similar effects to using redux, redux-saga, reselect, seamless-immutable, and redux-saga-process. However, it is packaged into a very small package with no dependencies (other than those written by and for this project).

// store.js
import createState from "state-modules";
import connectReact from "react-state-modules";

const state = createState().component({
  config: { cid: "counter" },
  state: {
    counter: { value: 0 }
  },
  actions: {
    increment: ["by"],
    decrement: ["by"]
  },
  reducers: {
    INCREMENT({ by = 1 }, draft) {
      draft.counter.value += by;
    },
    DECREMENT({ by = 1 }, draft) {
      draft.counter.value -= by;
    }
  }
});

const connector = state.connect(connectReact);

export default connector;
// app.js
import React, { Component } from "react";

import connect from "./store";

class App extends Component {
  render() {
    const { value, increment, decrement } = this.props;
    return (
      <div>
        <p>Current Value: {value}</p>
        <button onClick={() => increment(1)}>Increment</button>
        <button onClick={() => decrement(1)}>Decrement</button>
      </div>
    );
  }
}

export default connect(
  () => ({ value: "counter.value" }),
  actions => actions
)(App);
1.2.0

5 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.0.17

6 years ago

0.0.16

6 years ago

0.0.15

6 years ago

0.0.14

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago