# change-emitter

> Listen for changes. Like an event emitter that only emits a single event type. Really tiny.

Latest version **0.1.6** (published 2017-04-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install change-emitter
pnpm add change-emitter
yarn add change-emitter
bun add change-emitter
```

## Health

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

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.6 |
| Published | 2017-04-17 |
| First published | 2016-05-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/change-emitter) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 58 |
| Author | Andrew Clark |
| Maintainers | acdlite, istarkov |
| Keywords | change, event, emitter |

## Links

- npm: https://www.npmjs.com/package/change-emitter
- Repository: https://github.com/acdlite/change-emitter
- Homepage: https://github.com/acdlite/change-emitter#readme
- Issues: https://github.com/acdlite/change-emitter/issues
- npm.io page: https://npm.io/package/change-emitter

## 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

- 0.1.6 (latest) — 2017-04-17
- 0.1.5 — 2017-04-17
- 0.1.4 — 2017-04-17
- 0.1.3 — 2017-02-28
- 0.1.2 — 2016-05-15
- 0.1.1 — 2016-05-15

## README

change-emitter
==============

[![build status](https://img.shields.io/travis/acdlite/change-emitter/master.svg?style=flat-square)](https://travis-ci.org/acdlite/change-emitter)
[![npm version](https://img.shields.io/npm/v/change-emitter.svg?style=flat-square)](https://www.npmjs.com/package/change-emitter)

Listen for changes. Like an event emitter that only emits a single event type. Really tiny.

I extracted this from Redux's `createStore()` because I found it to be useful in other contexts. Use it where you want the most minimal event subscription implementation possible.

## Usage

```js
import { createChangeEmitter } from 'change-emitter'

const emitter = createChangeEmitter()

// Called `listen` instead of `subscribe` to avoid confusion with observable spec
const unlisten = emitter.listen((...args) => {
  console.log(args)
})

emitter.emit(1, 2, 3) // logs `[1, 2, 3]`
unlisten()
emitter.emit(4, 5, 6) // doesn't log
```

## Larger example

Here's a (partial) implementation of Redux's `createStore`:

```js
const createStore = (reducer, initialState) => {
  let state = initialState
  const emitter = createChangeEmitter()

  function dispatch(action) {
    state = reducer(state, action)
    emitter.emit()
    return action
  }

  function getState() {
    return state
  }

  return {
    dispatch,
    getState,
    subscribe: emitter.listen
  }
}
```

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