This is a pub/sub package for react. It provides the following functionalities:
A). publish a topic in two ways:
a). publish from javascript. To publish a topic in javascript,
you need to do the following:
//Import
import CommunicationManager from 'CommunicationManager'
//Create an singleton
const communicationManager = new CommunicationManager();
class MyComponent extends Component {
myHandler() {
communicationManager.publish("/MyTopic1", {"data":{"name":"John"}});
}
//...
}
b). publish from jsx. To publish a topic in jsx,
you need to do the following:
render() {
return (
<div>
<Publisher topic="/left/button"><button>Left</button></Publisher>
<Publisher topic="/left/Publish"><a href="#" className="ddd">aaaa</a></Publisher>
<Publisher topic="/left/Publish" event="Change">
<select>
<option value="a">A</option>
<option value="b">B</option>
</select>
</Publisher>
<Publisher topic="/MyTopic2" event="Change"><MyComponentB/></Publisher>
</div>
);
}
B). subscribe a topic
To subscribe a topic, you need to do the following:
//Import
import CommunicationManager from 'CommunicationManager'
//Create an singleton
const communicationManager = new CommunicationManager();
class MyComponent extends Component {
componentWillMount() {
communicationManager.subscribe("/MyTopic1", function(options) {
//handle the topic here
);
}
//...
}
To run the sample code, simply use "npm start" from the package root directory.