# @stephendltg/e-bus

> Message Queuing & memory data store

Latest version **1.0.8** (published 2021-06-17) · ISC license · 0 weekly downloads

## Install

```sh
npm install @stephendltg/e-bus
pnpm add @stephendltg/e-bus
yarn add @stephendltg/e-bus
bun add @stephendltg/e-bus
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2021-06-17 |
| First published | 2021-04-06 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 14.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Stephen Deletang |
| Maintainers | stephendltg |

## Links

- npm: https://www.npmjs.com/package/@stephendltg/e-bus
- npm.io page: https://npm.io/package/@stephendltg/e-bus

## Recent versions

- 1.0.8 (latest) — 2021-06-17
- 1.0.7 — 2021-06-16
- 1.0.6 — 2021-06-16
- 1.0.5 — 2021-06-16
- 1.0.4 — 2021-06-16
- 1.0.3-revision.1 — 2021-06-16
- 1.0.2 — 2021-04-06
- 1.0.1 — 2021-04-06
- 1.0.0 — 2021-04-06

## README

---
order: 1
title: E-bus
---

# E-BUS

Message Queuing & memory data store

E-bus was made for the browser and nodejs

## INSTALL

```
npm install --save @stephendltg/e-bus
```

For browser hhen with a module bundler like rollup or webpack, use as you would anything else:

```
// using ES6 modules
import emitter from '@stephendltg/e-bus'
 
// using CommonJS modules
var emitter = require('@stephendltg/e-bus/dist/module.esm')

// HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="http://unpkg.com/@stephendltg/e-bus"></script>
  <title>Document</title>
</head>
<body>
  <script>
    console.log(mitt)
  </script>
  
</body>
</html>
```

## USAGE

```
const mitt = emitter()
```

or add mutate (store) func && init store

```
const mutate = (key, value) => console.log(key + ': ' + value)
const init = new Map([['title', {value: 'Hello world', expiration: 0}]])
const mitt = emitter( mutate, init)
```

### PUB/SUB

```
 
// subscribe to an event
mitt.sub('foo', e => console.log('foo', e) )
 
// subscribe to all events
mitt.sub('*', (type, e) => console.log(type, e) )
 
// publish an event
mitt.pub('foo', { a: 'b' })
 
// working with handler references:
function onFoo() {}
mitt.sub('foo', onFoo)   // listen
mitt.unsub('foo', onFoo)  // unlisten function onFoo
mitt.unsub('foo') // unlisten all functions

// working with bus function
mitt.sub('test', e => typeof e === 'function' ? e() : null )
mitt.pub('test', ()=> console.log(678))

// Remove sub
mitt.unsub('foo')

```

### STORE

```
// Store Set
mitt.set('stub', 78)

// Store with expiration in millisecondes
mitt.set('stub', 89, 4000)

// Store get
mitt.get('stub')

// Store delete
mitt.del('stub')

// clearing all data
mitt.all.clear()

// Export store to json
let export = mitt.json()

```

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