# event-factory

> A pluggable event broker for Browser and Node.JS

Latest version **1.1.1** (published 2022-01-13) · ISC license · 0 weekly downloads

## Install

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

## 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.1.1 |
| Published | 2022-01-13 |
| First published | 2021-10-20 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Shrihari Prakash |
| Maintainers | shrihariprakash |
| Keywords | events, event, event bus, event emitter, browser events, message passing, event factory |

## Links

- npm: https://www.npmjs.com/package/event-factory
- Repository: https://github.com/Shrihari-Prakash/event-factory
- Issues: https://github.com/Shrihari-Prakash/event-factory/issues
- npm.io page: https://npm.io/package/event-factory

## 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.1.1 (latest) — 2022-01-13
- 1.1.0 — 2022-01-13
- 1.0.3 — 2021-10-20

## README

## Event Factory

##### A pluggable event broker for Browser

This package provides a event broker similar to Node JS's `EventEmitter` API on the browser.

EventFactory opens a wide number of possibilities for frontend modules to interact with each other.

#### Installation

`npm i event-factory --save`

#### Usage

```
import EventFactory from 'event-factory';

const eventFactory = new EventFactory();
eventFactory.on("message", function (payload) {
    console.log(payload);
});

eventFactory.emit(
    "message",
    { messsage: "Hello, world!" }
)
```

You can turn off events using the `off` function:

```
import EventFactory from 'event-factory';

const eventFactory = new EventFactory();
const handler = function (payload) {
    console.log(payload);
};

eventFactory.on("message", handler);

eventFactory.emit(
    "message",
    { messsage: "Hello, world!" }
)

// Turns off the event associated only with the handler
eventFactory.off("message", handler);

// Turns off all callbacks associated with the event
eventFactory.off("message", eventFactory.ALL_LISTENERS);
```

It is also possible to chain functions together:

```
const eventFactory = new EventFactory();
eventFactory.on("message", function (payload) {
    console.log(payload);
});

eventFactory
    .emit("message", { messsage: "Hello, world!" }).emit("message",{ messsage: "Hello, world!" });
)
```

Or extend an existing object to add event factory capabilities to it:

```
const myObj = {};
const eventFactory = new EventFactory();

eventFactory.enable(obj);

myObj
  .on("message", function (payload) {
    console.log(payload);
  })

myObj
  .emit("message", { messsage: "Hello, world!" });
```

#### Usage with vanilla JavaScript

```
<body>
  <script src="/path-to-ef/event-facroty.js"></script>
  <script>
    const eventFactory = new window.EventFactory();

    eventFactory
      .on("message", function (payload) {
        console.log(payload);
    })

    eventFactory
      .emit("message", { messsage: "Hello, world!");
  </script>
</body>
```

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