Skip to content

Commit

Permalink
Sample .into(target) implementation for #3
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanve committed May 3, 2014
1 parent 7b7fe11 commit 35e821c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
22 changes: 20 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,29 @@
}

/**
* @return {Energy}
* @return {Energy} emitter instance
*/
function energy(o) {
return o instanceof Energy ? o[init]() : new Energy(o);
}
}

/**
* @this {Function} wrapper that constructs the source instance
* @param {Object|Function} target to convert into emitter
* @return {Object|Function} target converted into emitter
*/
energy['into'] = function(target) {
return defaults(target, this.call());
};

/**
* @this {Energy|Object|Function} source emitter
* @param {Object|Function} target to convert into emitter
* @return {Object|Function} target converted into emitter
*/
emitter['into'] = function(target) {
return defaults(target, this);

This comment has been minimized.

Copy link
@ryanve

ryanve May 3, 2014

Author Owner

It might be better to return this for chaining consistent with most of the other emitter methods.

};

/**
* @param {{length:number}} fns
Expand Down
14 changes: 13 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,19 @@
function yes() { return true; }

aok('instance', emitter instanceof energy);
aok('listeners', typeof emitter.listeners(key).length == 'number');
aok('listeners', typeof emitter.listeners(key).length == 'number');

aok('into', function() {
function wannabe() {
wannabe.emit('called');
}

var bool = wannabe === energy.into(wannabe) && typeof wannabe.emit == 'function';
bool && wannabe.once('called', function() {
bool = this === wannabe;
}) && wannabe();
return bool;
});

(function(id) {
var bool = true, gone = indexOf ? function(what) {
Expand Down

0 comments on commit 35e821c

Please sign in to comment.