1.3.0 • Published 6 years ago

react-observable-store v1.3.0

Weekly downloads
66
License
MIT
Repository
github
Last release
6 years ago

React Observable Store

Code Climate Build Status

Why?

React Observable Store is a very simple state management store (HoC) for ReactJS applications.
This module uses the Observer Pattern: components subscribe to store updates.

Demo & Examples

To build the examples locally, run:

npm install
npm run dev

Then open localhost:8081 in a browser.

Installation

npm install react-observable-store --save

You can also use the standalone build by including dist/react-observable-store.js in your page. If you use this, make sure you have already included React, and it is available as a global variable.

Usage

Initialize (ES6) in top level component (or index.js)

import Store from 'react-observable-store';
Store.init({ namespace: {foo: 'bar' }});

Automatic updates

Attach the store to the component using withStore

import { withStore } from 'react-observable-store';
class MyComponent extends React.Component {};
export default withStore('namespace', MyComponent);

Access store data on component

<p>foo: { this.props.foo }</p>

Manual subscribe/unsubscribe

Load props on constructor

this.state = Store.get('namespace');

Subscribe on componentDidMount

this.observerId = Store.subscribe('namespace', (data) => {
    this.setState(data);
});

Unsubscribe on componentWillUnmount

Store.unsubscribe('namespace', this.observerId);

Update store from actions.js (redux alike)

import Store from 'react-observable-store';
export const updateFoo = (input) => {
    Store.update('namespace', { foo: input });
};

Development (src, lib and the build process)

NOTE: The source code for the component is in src. A transpiled CommonJS version (generated with Gulp+Babel) is available in lib for use with node.js, browserify and webpack. The example bundle is also built to dist.

To build, watch and serve the examples (which will also watch the component source), run npm run build. If you just want to watch changes to src and rebuild lib, run npm run watch.

License

MIT

Copyright (c) 2017 Marco Afonso.

1.3.0

6 years ago

1.2.4

6 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.6.2

7 years ago

0.6.1

7 years ago

0.6.0

7 years ago

0.5.2

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.1

7 years ago

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago