Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postal-react-mixin

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postal-react-mixin

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

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 06 Dec 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc