@mongodb-js/hadron-app-registry-redux-middleware
v1.0.1
Published
Redux middleware for interfacing with the Hadron App Registry
Downloads
6
Maintainers
Readme
hadron-app-registry-redux-middleware
Redux middleware which wraps the Hadron App Registry to facilitate the integration between Hadron App components which may use different state or store implementations (eg: Reflux, MobX).
The middleware listens to relevant Hadron App Registry events and dispatches them as Redux actions. It is also able to intercept relevant dispatched Redux actions and emit them as events in the Hadron App Registry.
Getting Started
$ npm install --save @mongodb-js/hadron-app-registry-redux-middleware
or
$ yarn add @mongodb-js/hadron-app-registry-redux-middleware
Alternatively, you may use the provided UMD builds directly in the <script>
tag of an HTML page.
Usage Example
Create and apply the middleware to the Redux store, passing an instance of the hadron-app-registry
as the first argument, along with any mappings for eventsToActions
and actionsToEvents
.
import { createStore, applyMiddleware } from 'redux';
import AppRegistry from 'hadron-app-registry';
import hadronAppRegistryReduxMiddleware from '@mongodb-js/hadron-app-registry-redux-middleware';
import reducers from './reducers';
const appRegistry = new AppRegistry();
// map appRegistry event names (key) to Redux action types (value)
const eventsToActions = {
'foo': 'BAR'
};
// map Redux action types (key) to appRegistry event names (value)
const actionsToEvents = {
'FIZZ': 'buzz'
};
let store = createStore(
reducers,
applyMiddleware(
hadronAppRegistryReduxMiddleware(
appRegistry,
eventsToActions,
actionsToEvents
)
)
);
Demo Example
This project also includes an example demonstrating the middleware in action:
To run the demo, clone this project and execute the following:
$: cd ./examples/react
$: npm install
$: npm start
Change Log
This project adheres to Semantic Versioning. Every release, along with the migration instructions, is documented on the Github Releases page.
License
Apache 2.0