# actionr

> A simple lightweight eventbus.

Latest version **1.0.2** (published 2022-01-04) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install actionr
pnpm add actionr
yarn add actionr
bun add actionr
```

## 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.2 |
| Published | 2022-01-04 |
| First published | 2022-01-01 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 15.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Jakob Lilliemarck |
| Maintainers | m3rtzi |
| Keywords | functional, events, eventbus, actions, dispatch, tiny |

## Links

- npm: https://www.npmjs.com/package/actionr
- Repository: https://github.com/jakob-lilliemarck/actionr
- Homepage: https://github.com/jakob-lilliemarck/actionr#readme
- Issues: https://github.com/jakob-lilliemarck/actionr/issues
- npm.io page: https://npm.io/package/actionr

## 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.2 (latest) — 2022-01-04
- 1.0.1 — 2022-01-02
- 1.0.0 — 2022-01-01

## README

A simple lightweight eventbus.

Subscribe action handlers to Actioneer
```js
const { subscribe, dispatch } = useActioneer()

const myActionHandler = {
  action: 'my:action',
  handler: ({ dispatch }) => (...args) => {
    // Will print ["Yay, our first action!"], given that the action is dispatched as shown below.
    console.log(args)
  }
}

const subscribedActionSymbols = subscribe(myActionHandler)

dispatch('my:action', 'Yay, our first action!')

unsubscribe(...subscribedActionSymbols)
```

`subscribe()` return an array of javascript `Symbol` that may be used to
unsubscribe individual handlers from the eventbus, even when many handlers
subscribe to the same action.

Action handlers recieve an object with `dispatch()`, and may dispatch further
actions.
```js
const { subscribe, dispatch } = useActioneer()

const foo = {
  action: 'foo',
  handler: ({ dispatch }) => () => {
    console.log('Running foo')
  }
}

const bar = {
  action: 'bar',
  handler: ({ dispatch }) => () => {
    // this handler dispatches the action "foo"
    dispatch('foo')
  }
}

subscribe(foo, bar)

// Will log "Running foo"
dispatch('foo')
```

`actioneer()` also returns a readonly `Proxy` of it's current `state` including:
- `actions`
- `symbols`
- `handlers`

Assigning to the state or any of it's keys will throw an error, use `subscribe()`
and `unsubscribe()` instead.
```js
const { state } = useActioneer()

// An array of symbols per action
console.log(state.actions)

// A key-value store of { [Symbol]: action }
console.log(state.symbols)

// A key-value store of { [Symbol]: handler }
console.log(state.handlers)
```

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