# react-mflux

> Binding of React components to mflux

Latest version **0.5.1** (published 2017-08-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-mflux
pnpm add react-mflux
yarn add react-mflux
bun add react-mflux
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.1 |
| Published | 2017-08-13 |
| First published | 2017-08-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jorge Rivera Gonte |
| Maintainers | jgonte |
| Keywords | javascript, react, mflux |

## Links

- npm: https://www.npmjs.com/package/react-mflux
- Repository: https://github.com/jgonte/react-mflux
- Homepage: https://github.com/jgonte/react-mflux#readme
- Issues: https://github.com/jgonte/react-mflux/issues
- npm.io page: https://npm.io/package/react-mflux

## Dependencies (1)

- [mflux](https://npm.io/package/mflux.md) ^0.5.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.5.1 (latest) — 2017-08-13
- 0.5.0 — 2017-08-13
- 0.4.2 — 2017-08-13
- 0.4.0 — 2017-08-08
- 0.3.0 — 2017-08-08
- 0.2.0 — 2017-08-07
- 0.1.0 — 2017-08-01

## README

# React-Mflux

React binding for modflux state management

## Features

* It runs in different environments
* ES6 as a source.
* It is tiny

### Influences

React-Mflux evolves the ideas of Redux but favors an object oriented methodology that allows to build reusable stores that encapsulate the state of a specific component instead of the whole application, therefore coming back to some of the original Flux ideas

### Installation

To install the stable version:

```
npm install --save react-mflux
```

This assumes you are using [npm](https://www.npmjs.com/) as your package manager.

React-Mflux is available as a collection of [CommonJS](http://webpack.github.io/docs/commonjs.html) modules. These modules are what you get when you import `react-mflux` in a [Webpack](https://webpack.js.org/), [Browserify](http://browserify.org/), or a Node environment.


#### Complementary Packages

Most likely, you'll also need [the React bindings](https://github.com/reactjs/react-modflux)

```js
import {Store, storeManager} from 'mflux';


/**
 * This is a class that extends the abstract store provided by mflux
 * The actions and the reducer are encapsulated inside the store, so the client
 * does  not know about dispatch and the reducer, therefore encapsulating those inside the store
 */

 // Extend from mflux store
 class IncrementDecrementStore extends Store {
   // Initial state
   state = {
     value: 0
   };

   constructor(config) {
     super(config);

     this.increment = this.increment.bind(this);
     this.decrement = this.decrement.bind(this);
   }

   increment() {
     this.dispatch({
       type: 1
     });
   }

   decrement() {
     this.dispatch({
       type: 2
     });
   }

   reducer(action) {
     switch (action.type) {
       case 1: return { value: this.state.value + 1 };
       case 2: return { value: this.state.value - 1 };
       default: throw new Error(`Invalid action type: ${action.type}`);
     }
   }

 }

// Instantiate the store, if you want to track the store with the store manager provide a unique identifier for that store
 let store = new IncrementDecrementStore({ id: 'testStoreId' });

 console.log(store.state.value) // The initial state. It should log Object {value: 0}

// Subscribe to the store
 store.subscribe(state => console.log(state.value));

 store.increment(); // It should log Object {value: 1}

 store.decrement()  // It should log Object {value: 0}

```

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