# decx

> Super simple React.js state management

Latest version **1.0.9** (published 2019-02-21) · ISC license · 0 weekly downloads

## Install

```sh
npm install decx
pnpm add decx
yarn add decx
bun add decx
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.9 |
| Published | 2019-02-21 |
| First published | 2019-02-21 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 204.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Sungmin Yi |
| Maintainers | tjdalsvndn9 |
| Keywords | redux, reducer, state, predictable, functional, immutable, hot, live, replay, flux, elm |

## Links

- npm: https://www.npmjs.com/package/decx
- Repository: https://github.com/tjdalsvndn9/Decx
- Homepage: https://github.com/tjdalsvndn9/Decx#readme
- Issues: https://github.com/tjdalsvndn9/Decx/issues
- npm.io page: https://npm.io/package/decx

## Dependencies (4)

- [react](https://npm.io/package/react.md) 16.8.2
- [react-dom](https://npm.io/package/react-dom.md) 16.8.2
- [lodash.isequal](https://npm.io/package/lodash.isequal.md) 4.5.0
- [regenerator-runtime](https://npm.io/package/regenerator-runtime.md) 0.13.1

## Alternatives

- [@reckona/mreact-store](https://npm.io/package/@reckona/mreact-store.md) — 976 weekly downloads
- [regular-state](https://npm.io/package/regular-state.md) — 410 weekly downloads
- [@pacote/flux-actions](https://npm.io/package/@pacote/flux-actions.md) — 65 weekly downloads
- [@pilotlab/lux-debug](https://npm.io/package/@pilotlab/lux-debug.md) — 39 weekly downloads
- [vue-persist-state](https://npm.io/package/vue-persist-state.md) — 19 weekly downloads

## Recent versions

- 1.0.9 (latest) — 2019-02-21
- 1.0.8 — 2019-02-21
- 1.0.7 — 2019-02-21
- 1.0.6 — 2019-02-21
- 1.0.5 — 2019-02-21
- 1.0.4 — 2019-02-21
- 1.0.3 — 2019-02-21
- 1.0.2 — 2019-02-21
- 1.0.1 — 2019-02-21
- 1.0.0 — 2019-02-21

## README

## The simplest React.js state management library which coexists with Redux
### Decorator + Reducer

### ALERT
> You need to download babel plugin @babel/plugin-proposal-decorators

```javascript
//in webpack.config.js

//the order should be identical
 [ "@babel/plugin-proposal-decorators", {"legacy":true}],
 ["@babel/plugin-proposal-class-properties", { "loose": true }]

    module: {
        rules: [
            {
                test: /\.(js|jsx)$/,
                exclude: /(node_modules|bower_components)/,
                use: {
                  loader: 'babel-loader',
                  options: {
                    presets: ['@babel/preset-env',"@babel/preset-react"],
                    plugins:["@babel/plugin-proposal-object-rest-spread",
                    [
                      "@babel/plugin-transform-runtime",
                      {
                        "helpers": true
                      }
                    ],
                    "babel-plugin-styled-components",
                    [ "@babel/plugin-proposal-decorators", {"legacy":true}],
                    ["@babel/plugin-proposal-class-properties", { "loose": true }],
                    "@babel/plugin-syntax-jsx",
                    "@babel/plugin-transform-classes"
                    ],
                  }
                }
            }
        ]
      }
```

```javascript
//in index.js
import {Store, DecxProvider,combinereducers} from "decx";

//custom reducers
const firstReducer = (state = 0, action) => {
    switch(action.type){
        case "INC":
        return state + payload;
        default:
        return state;
    }
}

const secondReducer = (state = "", action) => {
       switch(action.type){
        case "SCREAM":
        return `${state}!!!!`;
        default:
        return state;
    }
}

const reducers = combinereducers({
    number:firstReducer,
    text:secondReducer
})

const store = Store(reducers)

ReactDOM.render(
    <DecxProvider store={store}>
        <App/>
     </DecxProvider>
, document.getElementById('root'));

```


```javascript
//in App.jsx
import React, {Component} from 'react';
import {listen,event,connect} from 'decx';
import AppChild from '..////'

@connect()
class AppContainer extends Component{
    //dispatch an action
    @event
    onClick = () => {
        //pass an object like redux action creator
        return {type:"INC",payload:5}
    }
    //listen a state change which happens in child component
    @listen
    renderText = (state) => {
      //if state is empty, render nothing
     if(Object.keys(state).length === 0) return   
     const {text} = state;
     return <p>{text}</p>
    }

    render(){
        return(
            <div>
                <button onClick={this.onClick}>Click to increase number</button>
                <AppChild/>
                {this.renderText()}
            </div>
        )
    }
}

```

```javascript
//in AppChild.jsx
import React, {Component} from 'react';
import {listen,event,connect} from 'decx';

@connect()
class AppChild extends Component{
    //dispatch an action
    @event
    onClick = () => {
        //pass an object like redux action creator
        return {type:"SCREAM"}
    }
    //listen a state change which happens in parent component
    @listen
    rederNumber = (state) => {
      //if state is empty, render nothing
     if(Object.keys(state).length === 0) return   
     const {number} = state;
     return <p>{number}</p>
    }

    render(){
        return(
            <div>
                <button onClick={this.onClick}>Click to change text</button>
                {this.rederNumber()}
            </div>
        )
    }
}

export default AppChild

```

---
_Source: https://npm.io/package/decx · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
