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

postal-react-mixin

v1.0.3

Published

A ReactJS component mixin adding postal.js message bus behaviors to components, including declarative subscriptions.

Downloads

8

Readme

Postal.js + React

Seamlessly bringing postal.js's message bus into your React components.

Build Status npm version

Overview

PostalReactMixin is a React component mixin that provides simplified usage of postal.js. It lets React components specify their channel and subscriptions declaratively, and provides simplified acces to subscribe(topic, callback) and publish(topic, data) functions.

In the background, these subscriptions are managed in lifecycle methods.

This mixin is a thin wrapper around postal.js and allows for easy messaging between components. It was created as a reaction to the React documentation stating

For communication between two components that don't have a parent-child relationship, you can set up your own global event system. — Facebook React Docs

Whether a global event system/message bus is a smart architectural choice for your particular application remains a decision to be made at your descretion.

Example

To add PostalReactMixin to a component, you simply add it to your components mixins. This adds a subscribe(topic, callback) and a publish(topic, data) method to your component. You can also declare your component's subscriptions in an object:

let MessageCreator = React.createClass({
  mixins: [PostalReactMixin],

  subscriptions: {
    // subscribe to the topic "messageSuggestion"
    messageSuggestion: function(data) {
      this.setState({ text: data.text });
    }
  },

  render: function() {
    return (
      <Input type="text" value={this.state.text)} />
    );
  }
});

This MessageCreator will now receive messages from other components that publish on the messageSuggestion topic:


let MessageSuggestion = React.createClass({
  mixins: [PostalReactMixin],

  _someCallback: function() {
    this.publish('messageSuggestion', {
      text: "Hi, this is a message Suggestion!"
    });
  },
  
// ...

Whenever this component mounts, it will subscribe to the given topics.

Getting Started

PostalReactMixin is available from npm.

I recommend to use a tool like Webpack or Browserify to include the 'postal-react-mixin' npm package in your dependencies.

import PostalReactMixin from 'postal-react-mixin';

// ...

Contributing

I'm new to React and Javascript in general, so I welcome any comments or suggestions as Github Issues.