Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: asyncly/EventEmitter2
base: master
...
head fork: Siedrix/EventEmitter2
compare: master
Checking mergeability… Don't worry, you can still create the pull request.
  • 1 commit
  • 3 files changed
  • 0 commit comments
  • 1 contributor
View
28 examples/unique/index.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Diner Tests</title>
+ <script>
+ window.Loki = {};
+ </script>
+ <script src="../../lib/eventemitter2.js" type="text/javascript"></script>
+ <script>
+ var ee = new EventEmitter2();
+
+ ee.on('foo',function(e) {
+ console.log('Foooo!!!!', e);
+ });
+
+ ee.unique('foo',{value : 'bar'});
+
+ setTimeout(function () {
+ ee.on('foo',function(e) {
+ console.log('Delaye Foo!',e);
+ });
+ });
+ </script>
+</head>
+<body>
+ <h1>EventEmitter2</h1>
+</body>
+</html>
View
19 lib/eventemitter2.js
@@ -7,6 +7,7 @@
function init() {
this._events = new Object;
+ this._unique = new Object;
}
function configure(conf) {
@@ -23,7 +24,17 @@
function EventEmitter(conf) {
this._events = new Object;
+ this._unique = new Object;
configure.call(this, conf);
+
+ this.on('newListener',function() {
+ var type = arguments[0];
+ var handler = arguments[1];
+
+ if(this._unique[type]){
+ handler.call(this,this._unique[type])
+ }
+ });
}
function searchListenerTree(handlers, type, tree, i) {
@@ -314,6 +325,14 @@
};
+ EventEmitter.prototype.unique = function () {
+ this.emit.apply(this,arguments);
+
+ var type = arguments[0];
+ var value = arguments[0];
+ this._unique[type] = {value : value};
+ }
+
EventEmitter.prototype.on = function(type, listener) {
this._events || init.call(this);
View
53 test/simple/unique.js
@@ -0,0 +1,53 @@
+var uniqueEvents = require('nodeunit').testCase;
+
+var file = '../../lib/eventemitter2';
+
+module.exports = uniqueEvents({
+
+ setUp: function (callback) {
+ var EventEmitter2;
+
+ if(typeof require !== 'undefined') {
+ EventEmitter2 = require(file).EventEmitter2;
+ }
+ else {
+ EventEmitter2 = window.EventEmitter2;
+ }
+
+ this.emitter = new EventEmitter2({ verbose: true });
+ callback();
+ },
+
+ tearDown: function (callback) {
+ //clean up?
+ callback();
+ },
+
+ '1. Trigger unique event.': function (test) {
+ var emitter = this.emitter;
+
+ function functionA() { test.ok(true, 'The event was raised'); }
+
+ emitter.unique('test2');
+
+ emitter.on('test2', functionA);
+
+ test.expect(1);
+ test.done();
+ },
+
+ '2. Trigger unique event with values.': function (test) {
+ var emitter = this.emitter;
+
+ function functionA(e) { test.ok('value', e.value); }
+
+ emitter.unique('test2',{value : 'value'});
+
+ emitter.on('test2', functionA);
+
+ test.expect(1);
+ test.done();
+ },
+
+
+});

No commit comments for this range

Something went wrong with that request. Please try again.