src/index.js
function mix(objs, deep) {
	const gobj = gawk(objs.shift());
	if (!isGawked(gobj) || Array.isArray(gobj)) {
		throw new TypeError('Expected destination to be a gawked object');
	}

	if (!objs.length) {
		return gobj;
	}

	// validate the objects are good
	for (const obj of objs) {
		if (!obj || typeof obj !== 'object' || Array.isArray(obj)) {
			throw new TypeError('Expected merge source to be an object');
		}
	}

	// we need to detach the parent and all listeners so that they will be notified after everything
	// has been merged
	gobj.__gawk__.pause();

	/**
	 * Mix an object or gawked object into a gawked object.
	 * @param {Object} gobj - The destination gawked object.
	 * @param {Object} src - The source object to copy from.
	 */
	const mixer = (gobj, src) => {
		for (const key of Object.getOwnPropertyNames(src)) {
			if (key === '__gawk__') {
				continue;
			}

			const srcValue = src[key];

			if (deep && srcValue !== null && typeof srcValue === 'object' && !Array.isArray(srcValue)) {
				if (!isGawked(gobj[key])) {
					gobj[key] = gawk({}, gobj);
				}
				mixer(gobj[key], srcValue);
			} else if (Array.isArray(gobj[key]) && Array.isArray(srcValue)) {
				// overwrite destination with new values
				gobj[key].splice(0, gobj[key].length, ...srcValue);
			} else {
				gobj[key] = gawk(srcValue, gobj);
			}
		}
	};

	for (const obj of objs) {
		mixer(gobj, obj);
	}

	gobj.__gawk__.resume();

	return gobj;
}
function mix(objs, deep) {
	const gobj = gawk(objs.shift());
	if (!isGawked(gobj) || Array.isArray(gobj)) {
		throw new TypeError('Expected destination to be a gawked object');
	}

	if (!objs.length) {
		return gobj;
	}

	// validate the objects are good
	for (const obj of objs) {
		if (!obj || typeof obj !== 'object' || Array.isArray(obj)) {
			throw new TypeError('Expected merge source to be an object');
		}
	}

	// we need to detach the parent and all listeners so that they will be notified after everything
	// has been merged
	gobj.__gawk__.pause();

	/**
	 * Mix an object or gawked object into a gawked object.
	 * @param {Object} gobj - The destination gawked object.
	 * @param {Object} src - The source object to copy from.
	 */
	const mixer = (gobj, src) => {
		for (const key of Object.getOwnPropertyNames(src)) {
			if (key === '__gawk__') {
				continue;
			}

			const srcValue = src[key];

			if (deep && srcValue !== null && typeof srcValue === 'object' && !Array.isArray(srcValue)) {
				if (!isGawked(gobj[key])) {
					gobj[key] = gawk({}, gobj);
				}
				mixer(gobj[key], srcValue);
			} else if (Array.isArray(gobj[key]) && Array.isArray(srcValue)) {
				// overwrite destination with new values
				gobj[key].splice(0, gobj[key].length, ...srcValue);
			} else {
				gobj[key] = gawk(srcValue, gobj);
			}
		}
	};

	for (const obj of objs) {
		mixer(gobj, obj);
	}

	gobj.__gawk__.resume();

	return gobj;
}
function mix ( objs , deep ) { const gobj = gawk ( objs . shift ( ) ) ; if ( ! isGawked ( gobj ) || Array . isArray ( gobj ) ) { throw new TypeError ( 'Expected destination to be a gawked object' ) ; } if ( ! objs . length ) { return gobj ; } // validate the objects are good for ( const obj of objs ) { if ( ! obj || typeof obj !== 'object' || Array . isArray ( obj ) ) { throw new TypeError ( 'Expected merge source to be an object' ) ; } } // we need to detach the parent and all listeners so that they will be notified after everything // has been merged gobj . __gawk__ . pause ( ) ; /**
	 * Mix an object or gawked object into a gawked object.
	 * @param {Object} gobj - The destination gawked object.
	 * @param {Object} src - The source object to copy from.
	 */ const mixer = ( gobj , src ) => { for ( const key of Object . getOwnPropertyNames ( src ) ) { if ( key === '__gawk__' ) { continue ; } const srcValue = src [ key ] ; if ( deep && srcValue !== null && typeof srcValue === 'object' && ! Array . isArray ( srcValue ) ) { if ( ! isGawked ( gobj [ key ] ) ) { gobj [ key ] = gawk ( { } , gobj ) ; } mixer ( gobj [ key ] , srcValue ) ; } else if ( Array . isArray ( gobj [ key ] ) && Array . isArray ( srcValue ) ) { // overwrite destination with new values gobj [ key ] . splice ( 0 , gobj [ key ] . length , ... srcValue ) ; } else { gobj [ key ] = gawk ( srcValue , gobj ) ; } } } ; for ( const obj of objs ) { mixer ( gobj , obj ) ; } gobj . __gawk__ . resume ( ) ; return gobj ; }
Mixes an array of objects or gawked objects into the specified gawked object.

@param {Array.<Object>} objs - An array of objects or gawked objects.
@param {Boolean} [deep=false] - When true, mixes subobjects into each other.
@returns {Object}
Mixes an array of objects or gawked objects into the specified gawked object .