src/index.js
function copyListeners(dest, src, compareFn) {
	if (isGawked(src) && src.__gawk__.listeners) {
		if (dest.__gawk__.listeners) {
			for (const [ listener, filter ] of src.__gawk__.listeners) {
				dest.__gawk__.listeners.set(listener, filter);
			}
		} else {
			dest.__gawk__.listeners = new Map(src.__gawk__.listeners);
		}
	}

	if (!compareFn) {
		return;
	}

	if (Array.isArray(dest)) {
		const visited = [];
		for (let i = 0, len = dest.length; i < len; i++) {
			if (dest[i] !== null && typeof dest[i] === 'object') {
				// try to find a match in src
				for (let j = 0, len2 = src.length; j < len2; j++) {
					if (!visited[j] && src[j] !== null && typeof src[j] === 'object' && compareFn(dest[i], src[j])) {
						visited[j] = 1;
						copyListeners(dest[i], src[j], compareFn);
						break;
					}
				}
			}
		}
		return;
	}

	for (const key of Object.getOwnPropertyNames(dest)) {
		if (key === '__gawk__') {
			continue;
		}

		if (dest[key] && typeof dest[key] === 'object') {
			copyListeners(dest[key], src[key], compareFn);
		}
	}
}
function copyListeners(dest, src, compareFn) {
	if (isGawked(src) && src.__gawk__.listeners) {
		if (dest.__gawk__.listeners) {
			for (const [ listener, filter ] of src.__gawk__.listeners) {
				dest.__gawk__.listeners.set(listener, filter);
			}
		} else {
			dest.__gawk__.listeners = new Map(src.__gawk__.listeners);
		}
	}

	if (!compareFn) {
		return;
	}

	if (Array.isArray(dest)) {
		const visited = [];
		for (let i = 0, len = dest.length; i < len; i++) {
			if (dest[i] !== null && typeof dest[i] === 'object') {
				// try to find a match in src
				for (let j = 0, len2 = src.length; j < len2; j++) {
					if (!visited[j] && src[j] !== null && typeof src[j] === 'object' && compareFn(dest[i], src[j])) {
						visited[j] = 1;
						copyListeners(dest[i], src[j], compareFn);
						break;
					}
				}
			}
		}
		return;
	}

	for (const key of Object.getOwnPropertyNames(dest)) {
		if (key === '__gawk__') {
			continue;
		}

		if (dest[key] && typeof dest[key] === 'object') {
			copyListeners(dest[key], src[key], compareFn);
		}
	}
}
function copyListeners ( dest , src , compareFn ) { if ( isGawked ( src ) && src . __gawk__ . listeners ) { if ( dest . __gawk__ . listeners ) { for ( const [ listener , filter ] of src . __gawk__ . listeners ) { dest . __gawk__ . listeners . set ( listener , filter ) ; } } else { dest . __gawk__ . listeners = new Map ( src . __gawk__ . listeners ) ; } } if ( ! compareFn ) { return ; } if ( Array . isArray ( dest ) ) { const visited = [ ] ; for ( let i = 0 , len = dest . length ; i < len ; i ++ ) { if ( dest [ i ] !== null && typeof dest [ i ] === 'object' ) { // try to find a match in src for ( let j = 0 , len2 = src . length ; j < len2 ; j ++ ) { if ( ! visited [ j ] && src [ j ] !== null && typeof src [ j ] === 'object' && compareFn ( dest [ i ] , src [ j ] ) ) { visited [ j ] = 1 ; copyListeners ( dest [ i ] , src [ j ] , compareFn ) ; break ; } } } } return ; } for ( const key of Object . getOwnPropertyNames ( dest ) ) { if ( key === '__gawk__' ) { continue ; } if ( dest [ key ] && typeof dest [ key ] === 'object' ) { copyListeners ( dest [ key ] , src [ key ] , compareFn ) ; } } }
Copies listeners from a source gawked object ot a destination gawked object. Note that the
arguments must both be objects and only the `dest` is required to already be gawked.

@param {Object|Array} dest - A gawked object to copy the listeners to.
@param {Object|Array} src - An object to copy the listeners from.
@param {Function} [compareFn] - Doubles up as a deep copy flag and a function to call to compare
a source and destination array elements to check if they are the same.
Copies listeners from a source gawked object ot a destination gawked object . Note that the arguments must both be objects and only the dest is required to already be gawked .