# smoke-signal

> Simple small functional event observer for the browser and node

Latest version **1.3.2** (published 2020-11-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install smoke-signal
pnpm add smoke-signal
yarn add smoke-signal
bun add smoke-signal
```

## Health

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

Positive: no vulnerabilities; high maintenance score.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.3.2 |
| Published | 2020-11-05 |
| First published | 2015-11-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 19 |
| Author | Stephan Hoyer |
| Maintainers | stephan.hoyer |
| Keywords | event, observer, pubsub |

## Links

- npm: https://www.npmjs.com/package/smoke-signal
- Repository: https://github.com/StephanHoyer/smoke-signal
- Issues: https://github.com/StephanHoyer/smoke-signal/issues
- npm.io page: https://npm.io/package/smoke-signal

## 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.3.2 (latest) — 2020-11-05
- 1.3.1 — 2020-11-03
- 1.3.0 — 2020-11-03
- 1.2.2 — 2020-11-02
- 1.2.1 — 2020-11-02
- 1.1.0 — 2016-04-22
- 1.0.0 — 2016-04-22
- 0.1.3 — 2016-03-22
- 0.1.2 — 2016-02-26
- 0.1.1 — 2015-11-22
- 0.1.0 — 2015-11-22

## README

[![Build Status](https://travis-ci.org/StephanHoyer/smoke-signal.svg)](https://travis-ci.org/StephanHoyer/smoke-signal)
[![rethink.js](https://img.shields.io/badge/rethink-js-yellow.svg)](https://github.com/rethinkjs/manifest)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![](https://badgen.net/bundlephobia/minzip/smoke-signal)](https://bundlephobia.com/result?p=index.js)

# smoke-signal

Simple small functional event observer for the browser and node

## Installation

```
npm install smoke-signal
```

## Usage

```javascript
const signal = require('smoke-signal')

const onMySignal = signal()

// attach listenerFn to event
const listenAll = onMySignal.push(listenerFn)

// allow to listen only once
const listenOnce = onMySignal.once(listenerFn)

// trigger event
onMySignal.trigger()

// unlisten to event
onMySignal.pull(listenerFn)

// pause listening (pretty much the same as `onMySignal.pull(listenerFn)`)
listenAll.pause()

// resume listening (pretty much the same as `onMySignal.push(listenerFn)`)
listenAll.resume()

// remove all listeners
onMySignal.clear()
```

It's also possible to listen and trigger with args

```javascript
const signal = require('smoke-signal')

const onMySignal = signal()

// attach listenerFn to event
onMySignal.push(function (arg) {
  // arg === 'foo'
})

// trigger event
onMySignal.trigger('foo')
```

### Async trigger

It's also possible to have async handlers and wait for all handlers to settle.

```javascript
const signal = require('smoke-signal')

const onMySignal = signal()

// attach async listenerFn to event
onMySignal.push(async function (arg) {
  // do async stuff
})

// trigger event and wait for all handlers to finish
// this resolves when all promises are settled, think `Promise.all`, no matter what outcome
await onMySignal.triggerAsync('foo')
```

Error handling is the same as in synchronous version.

### Error handling

There are three ways of handling errors in listener, ignore (default), log, handle

To log the errors initialize with option `logExceptions`.

```javascript
const signal = require('smoke-signal')

const onMySignal = signal({
  logExceptions: true,
})

// attach listenerFn to event
onMySignal.push(function () {
  throw new Error('BOOM!')
})

// trigger event
onMySignal.trigger()
// logs error to std.error
```

To handle errors initialize with option `onError`

```javascript
const signal = require('smoke-signal')

const onMySignal = signal({
  onError: function (err) {
    // do something about the error here
  },
})

// attach listenerFn to event
onMySignal.push(function () {
  throw new Error('BOOM!')
})

// trigger event
onMySignal.trigger()
```

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