lib/replicant/shared.js
function proxyRecursive(replicant, value, path) {
	if (typeof value === 'object' && value !== null) {
		let p;

		assertSingleOwner(replicant, value);

		// If "value" is already a Proxy, don't re-proxy it.
		if (proxySet.has(value)) {
			p = value;
			const metadata = proxyMetadataMap.get(value);
			metadata.path = path; // Update the path, as it may have changed.
		} else if (metadataMap.has(value)) {
			const metadata = metadataMap.get(value);
			p = metadata.proxy;
			metadata.path = path; // Update the path, as it may have changed.
		} else {
			const handler = Array.isArray(value) ? CHILD_ARRAY_HANDLER : CHILD_OBJECT_HANDLER;
			p = new Proxy(value, handler);
			proxySet.add(p);
			const metadata = {
				replicant,
				path,
				proxy: p
			};
			metadataMap.set(value, metadata);
			proxyMetadataMap.set(p, metadata);
		}

		for (const key in value) {
			/* istanbul ignore if */
			if (!{}.hasOwnProperty.call(value, key)) {
				continue;
			}

			const escapedKey = key.replace(/\//g, '~1');
			if (path) {
				const joinedPath = joinPathParts(path, escapedKey);
				value[key] = proxyRecursive(replicant, value[key], joinedPath);
			} else {
				value[key] = proxyRecursive(replicant, value[key], escapedKey);
			}
		}

		return p;
	}

	return value;
}
function proxyRecursive(replicant, value, path) {
	if (typeof value === 'object' && value !== null) {
		let p;

		assertSingleOwner(replicant, value);

		// If "value" is already a Proxy, don't re-proxy it.
		if (proxySet.has(value)) {
			p = value;
			const metadata = proxyMetadataMap.get(value);
			metadata.path = path; // Update the path, as it may have changed.
		} else if (metadataMap.has(value)) {
			const metadata = metadataMap.get(value);
			p = metadata.proxy;
			metadata.path = path; // Update the path, as it may have changed.
		} else {
			const handler = Array.isArray(value) ? CHILD_ARRAY_HANDLER : CHILD_OBJECT_HANDLER;
			p = new Proxy(value, handler);
			proxySet.add(p);
			const metadata = {
				replicant,
				path,
				proxy: p
			};
			metadataMap.set(value, metadata);
			proxyMetadataMap.set(p, metadata);
		}

		for (const key in value) {
			/* istanbul ignore if */
			if (!{}.hasOwnProperty.call(value, key)) {
				continue;
			}

			const escapedKey = key.replace(/\//g, '~1');
			if (path) {
				const joinedPath = joinPathParts(path, escapedKey);
				value[key] = proxyRecursive(replicant, value[key], joinedPath);
			} else {
				value[key] = proxyRecursive(replicant, value[key], escapedKey);
			}
		}

		return p;
	}

	return value;
}
function proxyRecursive ( replicant , value , path ) { if ( typeof value === 'object' && value !== null ) { let p ; assertSingleOwner ( replicant , value ) ; // If "value" is already a Proxy, don't re-proxy it. if ( proxySet . has ( value ) ) { p = value ; const metadata = proxyMetadataMap . get ( value ) ; metadata . path = path ; // Update the path, as it may have changed. } else if ( metadataMap . has ( value ) ) { const metadata = metadataMap . get ( value ) ; p = metadata . proxy ; metadata . path = path ; // Update the path, as it may have changed. } else { const handler = Array . isArray ( value ) ? CHILD_ARRAY_HANDLER : CHILD_OBJECT_HANDLER ; p = new Proxy ( value , handler ) ; proxySet . add ( p ) ; const metadata = { replicant , path , proxy : p } ; metadataMap . set ( value , metadata ) ; proxyMetadataMap . set ( p , metadata ) ; } for ( const key in value ) { /* istanbul ignore if */ if ( ! { } . hasOwnProperty . call ( value , key ) ) { continue ; } const escapedKey = key . replace ( / \/ / g , '~1' ) ; if ( path ) { const joinedPath = joinPathParts ( path , escapedKey ) ; value [ key ] = proxyRecursive ( replicant , value [ key ] , joinedPath ) ; } else { value [ key ] = proxyRecursive ( replicant , value [ key ] , escapedKey ) ; } } return p ; } return value ; }
Recursively Proxies an Array or Object. Does nothing to primitive values.
@param replicant {object} - The Replicant in which to do the work.
@param value {*} - The value to recursively Proxy.
@param path {string} - The objectPath to this value.
@returns {*} - The recursively Proxied value (or just `value` unchanged, if `value` is a primitive)
@private
Recursively Proxies an Array or Object . Does nothing to primitive values .