npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

coolshare_react_pupsub

v0.1.0

Published

A package/service to provide publish/subscribe pattern for communication in React

Downloads

29

Readme

Coolshare Pub/Sub for React

By Mark Qian 3/25/2017 ([email protected]) Go http://MarkQian.com to see more.

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"}});
  		}
		//...
    }
    
    where the second parameter of the "publish" method is "options" which contains the 
    data you like to pass with the topic.
    
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" options="{'name':'Mark', 'address':'123 Main Ave San Jose, CA'}">
             <select>
               <option value="a">A</option>
               <option value="b">B</option>
             </select>
           </Publisher>
      	   <Publisher topic="/left/Publish">
      	     <MyComponentC/>
      	   </Publisher>
      </div>  
    );
  }
  
  where the attribute "options", optional, contains the data you want to pass with the topic.
  The content contained by "options" needs to be in a JSON format which will be evaluated into a javascript object.
  
  The "event" attribute is optional and the default is "Click".
  
  Please also pay attention to the Case of your "event". You should use "MouseOver" instead of "mouseover", "Mouseover" or
  "mouseOver" and "Change" instead of "change".
  
  Note:
  *****
  
  When "publish" tag/component contains regular DOM elements such as "div", "a", "button" and "select", the specified 
  "event" is bound directly to the contained elements but the contained elements are not regular DOm elements (such as
  the last "Publish" element above) the specified event will be bound to a "div" element containing the contained elements.
  
  
    
           

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
            );
  		}
		//...
    }

C). To run the sample code, you need to

	1). download it from 
	
	    https://github.com/coolshare/CoolshareReactPubSub/archive/master.zip
	    
	    and unzip it to, say c:\CoolshareReactPubSub
	    
	    
	2). Prepare required environment
	
	    - install node.js
	    - install required lib by running
	       cd  c:\CoolshareReactPubSub
	       npm install
	       
	3). Start the server and browser by
	
	    npm start
	         
	
	    You should see a browser page is opened at http://localhost:3000
	    
	Click each component on the page and the result will be shown in the console.
	
	Have fun!

D). To install it into your React application, you need to

 1). n