# weakmap-event

> > Associate [geval](https://github.com/Raynos/geval) events with a given object.

Latest version **2.0.7** (published 2017-03-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install weakmap-event
pnpm add weakmap-event
yarn add weakmap-event
bun add weakmap-event
```

## 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 | 2.0.7 |
| Published | 2017-03-27 |
| First published | 2015-07-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Andrew Joslin |
| Maintainers | andytjoslin, bendrucker |
| Keywords | weakmap, event, geval, functional |

## Links

- npm: https://www.npmjs.com/package/weakmap-event
- Repository: https://github.com/eaze/weakmap-event
- Homepage: https://github.com/eaze/weakmap-event#readme
- Issues: https://github.com/eaze/weakmap-event/issues
- npm.io page: https://npm.io/package/weakmap-event

## Dependencies (4)

- [geval](https://npm.io/package/geval.md) ~2.2.0
- [xtend](https://npm.io/package/xtend.md) ~4.0.0
- [weakmap-shim](https://npm.io/package/weakmap-shim.md) ~1.1.0
- [key-difference](https://npm.io/package/key-difference.md) ~1.0.0

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

- 2.0.7 (latest) — 2017-03-27
- 2.0.6 — 2015-08-31
- 2.0.5 — 2015-08-18
- 2.0.4 — 2015-08-18
- 2.0.3 — 2015-08-17
- 2.0.2 — 2015-08-11
- 2.0.1 — 2015-08-10
- 2.0.0 — 2015-08-10
- 1.0.0 — 2015-07-29
- 0.0.2 — 2015-07-12
- 0.0.1 — 2015-07-12

## README

# weakmap-event [![Build Status](https://travis-ci.org/eaze/weakmap-event.svg)](https://travis-ci.org/eaze/weakmap-event)

> Associate [geval](https://github.com/Raynos/geval) events with a given object.

Adapted from code in [Mercury](https://github.com/Raynos/mercury)'s examples.


## Install

```
$ npm install --save weakmap-event
```


## Usage

```js
var WeakmapEvent = require('weakmap-event')

var onClick = WeakmapEvent()

var obj1 = {}
var obj2 = {}

onClick.listen(obj1, function(data) {
  assert.equal(data, 'hello')
})
onClick.listen(obj2, function(data) {
  assert.equal(data, 'goodbye')
})

onClick.broadcast(obj1, 'hello')
onClick.broadcast(obj2, 'goodbye')
```

## API

#### `WeakmapEvent()` -> `event`

Creates a new weak-mapped event interface.

#### `event.broadcast(obj, value)` -> `undefined`

Broadcasts the value for listeners mapped to the object

##### obj

*Required*  
Type: `object`

The object to limit the broadcast to. Listeners on other objects will not be called.

##### value

*Required*  
Type: `any`

The value to broadcast to matched listeners.

#### `event.listen(obj, listener)` -> `function`

Listen on values emitted for a given object. Returns an `unlisten` function that will disable the listener when called.

##### obj

*Required*  
Type: `object`

The object to listen on.

##### listener

*Required*  
Type: `function`  
Arguments: `value`

A listener function to be called when a value is broadcasted matching the object.

#### `event.listen.toHash(observable, listener)` -> `undefined`

Listen on an observable hash.

##### observable

*Required*  
Type: `function`

An observable hash like [observ-struct](https://github.com/raynos/observ-struct) or [observ-varhash](https://github.com/nrw/observ-varhash).

##### listener

*Required*  
Type: `function`  
Arguments: `value`

A listener function to be called when a value is broadcasted matching a value from within the hash.


#### `event.listen.toArray(observable, listener)` -> `undefined`

Listen on an observable array.

##### observable

*Required*  
Type: `function`

An observable array from [observ-array](https://github.com/raynos/observ-array).

##### listener

*Required*  
Type: `function`  
Arguments: `value`

A listener function to be called when a value is broadcasted matching a value from within the array.

## License

MIT © [Eaze Solutions](http://eazeup.com)

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