This commit is contained in:
2025-06-26 03:35:15 +00:00
parent 56fa52fd80
commit 59f287112f
2193 changed files with 289518 additions and 3540 deletions

View File

@@ -0,0 +1,28 @@
# mutter
Mutter is a super-simple event emitter.
## Installation
$ npm install mutter --save
## Example
```js
var evt = require('mutter');
function foo(val) {
// ...
}
evt.on('foo', foo);
evt.one('foo', 'bar'); // emit one
evt.emit('foo', 'baz'); // emit all
evt.off('foo', foo)
```
## License
MIT

View File

@@ -0,0 +1,82 @@
/**
* Store
*/
var evt = {};
/**
* Expose
*/
module.exports = {
/**
* On
*
* @param {String} key
* @param {Function} fn
* @api public
*/
on: function(key, fn) {
evt[key] || (evt[key] = []);
evt[key].push(fn);
},
/**
* Off
*
* @param {String} key
* @param {Function} fn
* @api public
*/
off: function(key, fn) {
var val = evt[key];
if(!val) return;
var i = val.indexOf(fn);
if(-1 == i) return;
val.splice(i, 1);
},
/**
* One
*
* @param {String} key
* @param {Mixed} val
* @api public
*/
one: function(key, val) {
var ref = evt[key];
if(!ref || !ref.length) return;
ref[0](val);
},
/**
* Emit
*
* @param {String} key
* @param {Mixed} val
* @api public
*/
emit: function(key, val) {
if(!evt[key]) return;
evt[key].forEach(emit);
function emit(fn) {
fn(val);
}
}
};

View File

@@ -0,0 +1,21 @@
{
"name": "mutter",
"version": "1.0.1",
"description": "A rather simple event emitter",
"repository": "daryl/mutter",
"license": "MIT",
"author": {
"name": "Daryl Ginn",
"email": "hi@daryl.im",
"url": "daryl.im"
},
"files": [
"index.js"
],
"keywords": [
"emitter",
"events",
"event",
"bus"
]
}