Skip to content

Commit

Permalink
Merge pull request #1 from yousfiSaad/pipe-feature
Browse files Browse the repository at this point in the history
Pipe feature
  • Loading branch information
yousfiSaad committed Nov 23, 2015
2 parents ad09d36 + 07ca840 commit d121eef
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/multi-event-es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class MultiEvent {

let multiNamesMatches = allMultiNames.filter(helpers.matches(infos.splited));

// get multiCallBacks
let multiCallBacks = [];
for (let multiNamesMatch of multiNamesMatches) {
Array.prototype.push.apply(multiCallBacks, [...this._mapMulti.get(multiNamesMatch)]);
Expand All @@ -110,6 +111,11 @@ class MultiEvent {
return this;
}

pipe(subEventPatternAsString, eventEmitter){
this.on(subEventPatternAsString, function (...args){
eventEmitter.emit(this.eventName, ...args);
});
}
}

export default MultiEvent;
31 changes: 30 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,38 @@ describe('EventEmitter', () => {
});
});


});

describe('Pipe EventsSubSet', ()=>{
let mtOne = new EventEmitter();
let mtTwo = new EventEmitter();

mtOne.pipe('subSet.*', mtTwo);

it('#on event in the sub set (basic test)', (done)=>{
mtTwo.on('subSet.pipeEventOk', (...arg)=>{
if(arg.length === 2 && arg[0] === 'an argument' && arg[1] === 'another'){
done();
}
});
mtOne.emit('subSet.pipeEventOk', 'an argument', 'another');
});

it('#on event in the wrong sub set', (done)=>{
mtTwo.on('subSet.pipeEventOk2', (...arg)=>{
if(arg.length === 2 && arg[0] === 'an argument' && arg[1] === 'another'){
done();
}
});
mtTwo.on('subSet2.pipeEventOk2', (...arg)=>{
if(arg.length === 2 && arg[0] === 'an argument' && arg[1] === 'another'){
done("error");
}
});
mtOne.emit('subSet2.pipeEventOk2', 'an argument', 'another');
mtOne.emit('subSet.pipeEventOk2', 'an argument', 'another');
});
});

describe('MultiEventEmitter', () => {
it('#on() and #emit() multi', (done) => {
Expand Down

0 comments on commit d121eef

Please sign in to comment.