mirror of
https://github.com/fooflington/selfdefined.git
synced 2025-06-10 21:01:41 +00:00
update
This commit is contained in:
17
node_modules/emitter-mixin/History.md
generated
vendored
Normal file
17
node_modules/emitter-mixin/History.md
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
|
||||
0.0.3 / 2012-11-11
|
||||
==================
|
||||
|
||||
* add .off. closes #2
|
||||
* add more tests. closes #1
|
||||
|
||||
0.0.2 / 2012-11-10
|
||||
==================
|
||||
|
||||
* emitter() now returns the given `obj`
|
||||
|
||||
|
||||
0.0.1 / 2012-11-09
|
||||
==================
|
||||
|
||||
* initial release
|
7
node_modules/emitter-mixin/Makefile
generated
vendored
Normal file
7
node_modules/emitter-mixin/Makefile
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
test:
|
||||
@./node_modules/.bin/mocha \
|
||||
--reporter spec \
|
||||
--require should
|
||||
|
||||
.PHONY: test
|
42
node_modules/emitter-mixin/Readme.md
generated
vendored
Normal file
42
node_modules/emitter-mixin/Readme.md
generated
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
|
||||
[Node](https://nodejs.org) EventEmitter mixin.
|
||||
|
||||
## Example
|
||||
|
||||
```javascript
|
||||
|
||||
var emitter = require('emitter-mixin');
|
||||
|
||||
function Person () {}
|
||||
emitter(Person.prototype);
|
||||
|
||||
var person = new Person();
|
||||
person.on('foo', function (arg) {
|
||||
console.log(arg);
|
||||
}).emit('foo', 'bar');
|
||||
|
||||
// > bar
|
||||
```
|
||||
|
||||
You don't have to do `Emitter.call(this)` in your constructor
|
||||
anymore, the mixin defines an `_events` getter that does the
|
||||
magic for you.
|
||||
|
||||
```javascript
|
||||
emitter(Person.prototype);
|
||||
var person = new Person();
|
||||
person._events == person._events;
|
||||
// > true
|
||||
person._events == Person.prototype._events;
|
||||
// > false
|
||||
```
|
||||
|
||||
## Tests
|
||||
|
||||
```bash
|
||||
$ make test
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
(MIT)
|
78
node_modules/emitter-mixin/index.js
generated
vendored
Normal file
78
node_modules/emitter-mixin/index.js
generated
vendored
Normal file
@ -0,0 +1,78 @@
|
||||
|
||||
/**
|
||||
* dependencies.
|
||||
*/
|
||||
|
||||
var Emitter = require('events').EventEmitter
|
||||
, proto = Emitter.prototype;
|
||||
|
||||
/**
|
||||
* expsoe `mixin`
|
||||
*
|
||||
* @param {Object} obj
|
||||
*/
|
||||
|
||||
module.exports = function (obj) {
|
||||
|
||||
// mixin
|
||||
|
||||
for (var k in proto) {
|
||||
obj[k] = proto[k];
|
||||
}
|
||||
|
||||
// events getter.
|
||||
|
||||
obj.__defineGetter__('_events', function () {
|
||||
return this.__events || (this.__events = {});
|
||||
});
|
||||
|
||||
// events setter.
|
||||
|
||||
obj.__defineSetter__('_events', function (val) {
|
||||
this.__events = val;
|
||||
});
|
||||
|
||||
/**
|
||||
* Remove all listeners for `event`.
|
||||
*
|
||||
* if the method is executed without
|
||||
* arguments it will remove all listeners,
|
||||
* otherwise you can supply `event` or
|
||||
* `event` with `fn` for more specific stuff.
|
||||
*
|
||||
* example:
|
||||
*
|
||||
* obj.on('foo', console.log)._events;
|
||||
* // > { foo: fn, }
|
||||
* obj.on('foo', console.dir)._events;
|
||||
* // > { foo: [fn, fn] }
|
||||
* obj.off('foo', console.log)._events;
|
||||
* // > { foo: [fn] }
|
||||
* obj.off('foo');
|
||||
* // > {}
|
||||
* obj.off();
|
||||
* // > {}
|
||||
*
|
||||
* @param {String} event
|
||||
* @param {Function} fn
|
||||
* @return {self}
|
||||
*/
|
||||
|
||||
obj.off = function (event, fn) {
|
||||
switch (arguments.length) {
|
||||
case 2:
|
||||
this.removeListener(event, fn);
|
||||
return this;
|
||||
case 1:
|
||||
this.removeAllListeners(event);
|
||||
return this;
|
||||
case 0:
|
||||
this.removeAllListeners();
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// all done
|
||||
return obj;
|
||||
};
|
60
node_modules/emitter-mixin/package.json
generated
vendored
Normal file
60
node_modules/emitter-mixin/package.json
generated
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"emitter-mixin@0.0.3",
|
||||
"/Users/tatiana/selfdefined"
|
||||
]
|
||||
],
|
||||
"_from": "emitter-mixin@0.0.3",
|
||||
"_id": "emitter-mixin@0.0.3",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-WUjLKG8uSO3DslGnz8H3iDOW1lw=",
|
||||
"_location": "/emitter-mixin",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "emitter-mixin@0.0.3",
|
||||
"name": "emitter-mixin",
|
||||
"escapedName": "emitter-mixin",
|
||||
"rawSpec": "0.0.3",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "0.0.3"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/recursive-copy"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/emitter-mixin/-/emitter-mixin-0.0.3.tgz",
|
||||
"_spec": "0.0.3",
|
||||
"_where": "/Users/tatiana/selfdefined",
|
||||
"author": {
|
||||
"name": "Amir Abu Shareb",
|
||||
"email": "amir.abu.shareb@me.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/yields/emitter-mixin/issues"
|
||||
},
|
||||
"description": "Node's EventEmitter mixin",
|
||||
"devDependencies": {
|
||||
"mocha": "*",
|
||||
"should": "*"
|
||||
},
|
||||
"homepage": "https://github.com/yields/emitter-mixin#readme",
|
||||
"keywords": [
|
||||
"emitter",
|
||||
"mixin",
|
||||
"EventEmitter",
|
||||
"events"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "y",
|
||||
"name": "emitter-mixin",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/yields/emitter-mixin.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "make test"
|
||||
},
|
||||
"version": "0.0.3"
|
||||
}
|
126
node_modules/emitter-mixin/test/person.js
generated
vendored
Normal file
126
node_modules/emitter-mixin/test/person.js
generated
vendored
Normal file
@ -0,0 +1,126 @@
|
||||
|
||||
var emitter = require('../')
|
||||
, Person = function () {}
|
||||
, person = new Person;
|
||||
|
||||
emitter(Person.prototype);
|
||||
|
||||
describe('Person', function () {
|
||||
it('should mixin emitter', function () {
|
||||
person._events.should.equal(person._events);
|
||||
Person.prototype._events.should.not.equal(person._events);
|
||||
});
|
||||
|
||||
it('should emit properly', function () {
|
||||
person.on('foo', function (a) {
|
||||
a.should.eql('bar');
|
||||
}).emit('foo', 'bar');
|
||||
});
|
||||
|
||||
it('should register events properly', function () {
|
||||
person.on('say', console.log)._events.say.should.equal(console.log);
|
||||
})
|
||||
});
|
||||
|
||||
describe('Person constructor', function () {
|
||||
it('should eql `Person`', function () {
|
||||
person.constructor.should.equal(Person);
|
||||
})
|
||||
})
|
||||
|
||||
describe('emitter()', function () {
|
||||
it('should return the given `obj`', function () {
|
||||
var obj = new Person();
|
||||
emitter(obj).should.be.instanceOf(Person);
|
||||
})
|
||||
})
|
||||
|
||||
describe('emitter({})', function () {
|
||||
|
||||
var obj = emitter({});
|
||||
|
||||
describe('.on()', function () {
|
||||
it('should work', function () {
|
||||
obj.on('foo', console.log)
|
||||
._events['foo'].should.equal(console.log)
|
||||
})
|
||||
})
|
||||
|
||||
describe('.removeListener()', function () {
|
||||
it('should work', function () {
|
||||
obj.removeListener('foo', console.log)
|
||||
._events.should.eql({});
|
||||
})
|
||||
})
|
||||
|
||||
describe('.removeAllListeners()', function () {
|
||||
it('should work', function () {
|
||||
obj.on('foo', console.log)
|
||||
.removeAllListeners()
|
||||
._events.should.eql({});
|
||||
})
|
||||
})
|
||||
|
||||
describe('.once()', function () {
|
||||
it('should work', function () {
|
||||
obj.once('foo', console.log).emit('foo');
|
||||
obj._events
|
||||
.should
|
||||
.eql({});
|
||||
})
|
||||
})
|
||||
|
||||
describe('.setMaxListeners()', function () {
|
||||
it('should work', function () {
|
||||
obj.setMaxListeners(10);
|
||||
obj._maxListeners.should.eql(10);
|
||||
})
|
||||
})
|
||||
|
||||
describe('.listeners()', function () {
|
||||
it('should return all listeners for event', function () {
|
||||
obj.on('foo', console.log)
|
||||
.listeners('foo')[0]
|
||||
.should.equal(console.log);
|
||||
|
||||
obj.removeListener('foo', console.log);
|
||||
})
|
||||
})
|
||||
|
||||
describe('.emit()', function () {
|
||||
it('should emit the given event with `args`', function () {
|
||||
var args;
|
||||
|
||||
obj.on('foo', function () {
|
||||
args = [].slice.call(arguments);
|
||||
}).emit('foo', 'bar', 'baz');
|
||||
|
||||
args.should.eql(['bar', 'baz']);
|
||||
})
|
||||
})
|
||||
|
||||
describe('.off()', function () {
|
||||
it('should remove all listeners if arguments are omitted', function () {
|
||||
obj
|
||||
.on('foo', function () {})
|
||||
.on('bar', function () {})
|
||||
.off()
|
||||
._events
|
||||
.should
|
||||
.eql({});
|
||||
})
|
||||
|
||||
it('should remove all listeners for `event`', function () {
|
||||
obj.on('foo', function () {}).off('foo')
|
||||
._events.should.have.property('foo', null);
|
||||
})
|
||||
|
||||
it('should remove the given `listener` from `event`', function () {
|
||||
obj.on('foo', console.log).on('foo', console.dir)
|
||||
.off('foo', console.log)
|
||||
.listeners('foo')
|
||||
.should.not.include(console.log);
|
||||
})
|
||||
})
|
||||
|
||||
})
|
Reference in New Issue
Block a user