vivy-subscription
v3.2.0
Published
A Vivy Plugin to handle subscriptions in Vivy model to watch history or something else.
Downloads
12
Maintainers
Readme
vivy-subscription
A Vivy plugin which extend Vivy model to watch history
or something else to update state by dispatching a
reducer or action.
Docs
Installation
Using npm:
$ npm install vivy vivy-subscription
Examples
Examples in repository
$ cd ./examples/[EXAMPLE_NAME]
$ npm run start
Example names:
Complete and real project example
Documentation
Basic usage
index.js
import React from 'react';
import {render} from 'react-dom';
import {Provider} from 'react-vivy';
// Import Vivy
import Vivy from 'vivy';
// Import Vivy subscription plugin
import vivySubscription from 'vivy-subscription';
// Import your component and model
import App from 'path_to_app_component';
import app from 'path_to_app_model';
// Create vivy
const vivy = Vivy();
// Apply subscription plugin
vivy.use(vivySubscription());
// Create store after configuration
const store = vivy.createStore();
// Register vivy model
store.registerModel(app);
render(
<Provider store={store}>
<App/>
</Provider>,
document.getElementById('app-container')
);
app.js
export default {
nameSpace: 'app',
state: null,
subscriptions: {
// Define a subscription
yourSubscription: ({history}) => (dispatch, getState) => {
// Bind history listening or do something else
}
}
};