'use strict';

var defineProperty = Object.defineProperty
  , remove         = require('es5-ext/lib/Array/prototype/remove')
  , d              = require('es5-ext/lib/Object/descriptor')
  , value          = require('es5-ext/lib/Object/valid-value')
  , emit           = require('./core').methods.emit

  , id = '- ee -'
  , pipeTag = '\u0001pipes';

module.exports = function (emitter1, emitter2) {
	var desc, pipes, pipe;

	value(emitter1) && value(emitter2);
	if (!emitter1.emit) {
		throw new TypeError(emitter + ' is not emitter');
	}

	pipe = {
		close: function () {
			remove.call(pipes, emitter2);
		}
	};
	if (!emitter1.hasOwnProperty(id)) {
		defineProperty(emitter1, id, d({}));
	}
	if (emitter1[id][pipeTag]) {
		(pipes = emitter1[id][pipeTag]).push(emitter2);
		return pipe;
	}
	pipes = emitter1[id][pipeTag] = [emitter2];
	defineProperty(emitter1, 'emit', d(function () {
		var i, emitter, data;
		emit.apply(this, arguments);
		for (i = 0; emitter = pipes[i]; ++i) {
			emit.apply(emitter, arguments);
		}
	}));

	return pipe;
};

@@ -51,16 +51,81 @@
 roperty%0A
+  , copy           = require('es5-ext/lib/Array/prototype/copy')%0A
   , remo
@@ -851,16 +851,17 @@
 pe;%0A%09%7D%0A%09
+(
 pipes = 
@@ -894,16 +894,29 @@
 mitter2%5D
+).copy = copy
 ;%0A%09defin
@@ -981,16 +981,31 @@
 er, data
+ = pipes.copy()
 ;%0A%09%09emit
@@ -1053,21 +1053,20 @@
 itter = 
-pipes
+data
 %5Bi%5D; ++i

Copy pipes before emit