Socket
Socket
Sign inDemoInstall

cross-event

Package Overview
Dependencies
2
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    cross-event

Universal EventEmitter API for Node, Browsers and React Native


Version published
Weekly downloads
102
decreased by-50.96%
Maintainers
1
Install size
188 kB
Created
Weekly downloads
 

Readme

Source

CROSS-EVENT

Platform agnostic EventEmitter.

Installation

npm install --save cross-event

or

yarn add cross-event

Usage Example

import CrossEvent from 'cross-event';

/*
 * RECEIVER COMPONENT
 */
class Receiver extends PureComponent {
  constructor(props) {
    super(props);

    this.state = {
      data: 'no data',
    };

    this.handler = this.handler.bind(this);
  }

  handler(data) {
    this.setState({
      data,
    });
  }

  componentWillMount() {
    this.listener = CrossEvent.on('myCustomEvent', this.handler);
  }

  componentWillUnmount() {
    CrossEvent.rm(this.listener);
  }

  render() {
    return <Text> {this.state.data} </Text>
  }
}

/*
 * SENDER COMPONENT
 */
const Sender = (props) => (
  <TouchableHighlight onPress = {() => CrossEvent.emit('myCustomEvent', 'it works!!!')>
    <Text> Send Event </Text>
  </TouchableHighlight>
);

API

static methoddescription
onreturn value is the id of the event listener or false on error
rmtrue on success otherwise false
rmAlltrue on success otherwise false
emitno return value

Keywords

FAQs

Last updated on 09 Jul 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc