# mako-event-emitter

> browserify module for emitting/registering to custom events in the browser

Latest version **0.0.0** (published 2014-07-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install mako-event-emitter
pnpm add mako-event-emitter
yarn add mako-event-emitter
bun add mako-event-emitter
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.0 |
| Published | 2014-07-20 |
| First published | 2014-07-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jake Scott |
| Maintainers | mako-taco |

## Links

- npm: https://www.npmjs.com/package/mako-event-emitter
- npm.io page: https://npm.io/package/mako-event-emitter

## Dependencies (3)

- [dox](https://npm.io/package/dox.md) ^0.4.6
- [browserify](https://npm.io/package/browserify.md) ~4.2.3
- [dox-github](https://npm.io/package/dox-github.md) 0.0.2

## Recent versions

- 0.0.0 (latest) — 2014-07-20

## README

##API

###EventEmitter.prototype.on(type, fn)
 - `type` *string* - message type
 - `fn` *function* - handler to add

Add a handler for a message type 

```javascript
EventEmitter.prototype.on = function (type, fn, ctx) {
	var wrapped;

	ctx = ctx || this;	
	wrapped = function () {
		fn.apply(ctx, Array.prototype.slice.call(arguments, 0));
	};

	fn.wrapped = wrapped;

	if(!this.listeners[type]) {
		this.listeners[type] = [wrapped];
	}
	else {
		this.listeners[type].push(wrapped);
	}
};
```

###EventEmitter.prototype.once(type, fn)
 - `type` *string* - message type
 - `fn` *function* - handler to add

Add a handler for a message type which removes itself after a single execution

```javascript
EventEmitter.prototype.once = function (type, fn, ctx) {
	var wrapped;

	ctx = ctx || this;

	wrapped = function () {
		ctx.off(type, fn);
		fn.apply(ctx, Array.prototype.slice(arguments, 0));
	};

	fn.wrapped = wrapped;

	if(!this.listeners[type]) {
		this.listeners[type] = [wrapped];
	}
	else {
		this.listeners[type].push(wrapped);
	}	
};
```

###EventEmitter.prototype.off(type, fn)
 - `type` *string* - message type
 - `fn` *function* - handler to remove

Remove a handler for a message type 

```javascript
EventEmitter.prototype.off = function (type, fn) {
	var index, index2;

	if(this.listeners[type]) {
		index = this.listeners[type].indexOf(fn);
		index2 = this.listeners[type].indexOf(fn.wrapped);
		if(index > -1) {
			this.listeners[type].splice(index, 1);
			return true;
		}
		else if(index2 > -1) {
			this.listeners[type].splice(index2, 1);
			return true;
		}
		else {
			return false;
		}
	}
	else {
		return false;
	}
};
```

###EventEmitter.prototype.emit(type, payload)
 - `type` *string* - the type of event to emit
 - `payload` *...(object,number,string)* - Any additional arguments 	will be sent to the handlers for this event

Triggers an event of a specific type, with any additional payload passed.

```javascript
EventEmitter.prototype.emit = function (type) {
	var payload = Array.prototype.slice.call(arguments, 1),
		fns = this.listeners[type] || [],
		i;

	for(i=0; i<fns.length; i++) {
		fns[i](payload);
	}
};

module.exports = EventEmitter;
},{}]},{},[1])
```

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