# telegraph-events

> Minimal event emitter forked from smokesignals.js

Latest version **1.0.3** (published 2015-05-18) · 0 weekly downloads

## Install

```sh
npm install telegraph-events
pnpm add telegraph-events
yarn add telegraph-events
bun add telegraph-events
```

## 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.3 |
| Published | 2015-05-18 |
| First published | 2015-05-08 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 18 |
| Author | Dustin Brown |
| Maintainers | dubrowgn |
| Keywords | events, emitter, trigger |

## Links

- npm: https://www.npmjs.com/package/telegraph-events
- Repository: https://github.com/dubrowgn/telegraph
- Issues: https://github.com/dubrowgn/telegraph/issues
- npm.io page: https://npm.io/package/telegraph-events

## 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.3 (latest) — 2015-05-18
- 1.0.2 — 2015-05-08
- 1.0.1 — 2015-05-08
- 1.0.0 — 2015-05-08

## README

Telegraph
=============

![Build status](https://travis-ci.org/dubrowgn/telegraph.svg?branch=master)

A minimal event emitter for browsers, forked from Benjamin Thomas' [smokesignals.js][1].

This library has three goals:

1. Make it easy and intuitive to listen for and initiate events on an object.
2. Be as small as possible. Right now the minified version comes in at 528 bytes.
3. Capability for handlers to cancel the event process.

There are many other [wonderful libraries that do similar things][2], but none
of them worked exactly how I wanted them to work or met all the goals above.

Installing
----------

Just download `telegraph.js` and put it in a place you can access from your webpage.

Loading
-------

Just include the Telegraph script:

```html
<script src="telegraph.js"></script>
```

Using
-----

Make any object an event emitter:

```javascript
var jill = {};
telegraph(jill);

// or...
var jill = telegraph();
```

Or if you prefer constructors:

```javascript
function Person() {
    telegraph(this);
}
var jill = new Person();
```

Now you can listen for events:

```javascript
function listener(name) {
    window.alert('Hello ' + name + '!');
}
jill.on('say hello', listener);
```

And emit events:

```javascript
jill.emit('say hello', 'Jack');
// alerts: "Hello Jack!"
// returns: true
```

And remove a listener:

```javascript
jill.off('say hello', listener);
```

Or if you only want to listen for an event once:

```javascript
jill.once('another event', function() {
    window.alert("I'll only be called once!");
});
jill.emit('another event');
```

Or remove all listeners for an event:

```javascript
jill.off('say hello');
```

Or if you want to remove ALL listeners:

```javascript
// just call off() with no parameters
jill.off();

// or reconvert the object...
telegraph(jill);
```

Or if you want to cancel the event chain:

```javascript
// just return false from a handler
jill.on('event', function() { return false; });
jill.on('event', function() { console.log('event!'); });

// emit now returns false, and 'event!' is not printed
jill.emit('event');
```

That's it! One global object (`telegraph`) and when used it adds 4 methods to
your objects (`on`, `once`, `off` and `emit`).

By the way, all methods, except for `emit`, are chainable:

```javascript
var jill = telegraph()
    .on('event one', function() { ... })
    .on('event two', function() { ... })
    .once('event three', function() { ... })
    .off ('event one');
```

[1]: https://bitbucket.org/bentomas/smokesignals.js
[2]: http://microjs.com/#events

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