# cross-event

> Universal EventEmitter API for Node, Browsers and React Native

Latest version **1.0.6** (published 2018-07-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install cross-event
pnpm add cross-event
yarn add cross-event
bun add cross-event
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2018-07-09 |
| First published | 2018-07-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 7.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | João Marcus Fernandes |
| Maintainers | joaomarcuslf |
| Keywords | events, isomorphic, universal, node, react, native, browser, event-emitter |

## Links

- npm: https://www.npmjs.com/package/cross-event
- Repository: https://github.com/joaomarcuslf/cross-event
- Homepage: https://github.com/joaomarcuslf/cross-event#readme
- Issues: https://github.com/joaomarcuslf/cross-event/issues
- npm.io page: https://npm.io/package/cross-event

## Dependencies (1)

- [react-native-event-listeners](https://npm.io/package/react-native-event-listeners.md) 1.0.3

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 1.0.6 (latest) — 2018-07-09
- 1.0.5 — 2018-07-09
- 1.0.1 — 2018-07-09
- 1.0.0 — 2018-07-09

## README

# CROSS-EVENT

Platform agnostic EventEmitter.

## Installation

```
npm install --save cross-event
```

or

```
yarn add cross-event
```

## Usage Example

```javascript
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 method       | description                                                    |
| :------------------ | :------------------------------------------------------------- |
| on                  | return value is the id of the event listener or false on error |
| rm                  | true on success otherwise false                                |
| rmAll               | true on success otherwise false                                |
| emit                | no return value                                                |

---
_Source: https://npm.io/package/cross-event · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
