|
|
@@ -12,16 +12,18 @@ import getSubNodes from './getsubnodes';
|
|
|
/**
|
|
|
* Traverses both structures to find out whether there is a reference that is shared between both structures.
|
|
|
*
|
|
|
- * @param {Object|Array} obj1
|
|
|
- * @param {Object|Array} obj2
|
|
|
+ * @param {Object|Array} target1
|
|
|
+ * @param {Object|Array} target2
|
|
|
*/
|
|
|
-export default function areConnectedThroughProperties( obj1, obj2, excludedProperties = new Set() ) {
|
|
|
- if ( obj1 === obj2 && isObject( obj1 ) ) {
|
|
|
+export default function areConnectedThroughProperties( target1, target2, excludedNodes = new Set() ) {
|
|
|
+ if ( target1 === target2 && isObject( target1 ) ) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- const subNodes1 = getSubNodes( obj1, excludedProperties );
|
|
|
- const subNodes2 = getSubNodes( obj2, excludedProperties );
|
|
|
+ // @if CK_DEBUG_WATCHDOG // return checkConnectionBetweenProps( target1, target2, excludedNodes );
|
|
|
+
|
|
|
+ const subNodes1 = getSubNodes( target1, excludedNodes );
|
|
|
+ const subNodes2 = getSubNodes( target2, excludedNodes );
|
|
|
|
|
|
for ( const node of subNodes1 ) {
|
|
|
if ( subNodes2.has( node ) ) {
|
|
|
@@ -32,6 +34,45 @@ export default function areConnectedThroughProperties( obj1, obj2, excludedPrope
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+/* istanbul ignore next */
|
|
|
+// eslint-disable-next-line
|
|
|
+function checkConnectionBetweenProps( target1, target2, excludedNodes ) {
|
|
|
+ const { subNodes: subNodes1, prevNodeMap: prevNodeMap1 } = getSubNodes( target1, excludedNodes.subNodes );
|
|
|
+ const { subNodes: subNodes2, prevNodeMap: prevNodeMap2 } = getSubNodes( target2, excludedNodes.subNodes );
|
|
|
+
|
|
|
+ for ( const sharedNode of subNodes1 ) {
|
|
|
+ if ( subNodes2.has( sharedNode ) ) {
|
|
|
+ const connection = [];
|
|
|
+
|
|
|
+ connection.push( sharedNode );
|
|
|
+
|
|
|
+ let node = prevNodeMap1.get( sharedNode );
|
|
|
+
|
|
|
+ while ( node && node !== target1 ) {
|
|
|
+ connection.push( node );
|
|
|
+ node = prevNodeMap1.get( node );
|
|
|
+ }
|
|
|
+
|
|
|
+ node = prevNodeMap2.get( sharedNode );
|
|
|
+
|
|
|
+ while ( node && node !== target2 ) {
|
|
|
+ connection.unshift( node );
|
|
|
+ node = prevNodeMap2.get( node );
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log( '--------' );
|
|
|
+ console.log( { target1 } );
|
|
|
+ console.log( { sharedNode } );
|
|
|
+ console.log( { target2 } );
|
|
|
+ console.log( { connection } );
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
function isObject( structure ) {
|
|
|
return typeof structure === 'object' && structure !== null;
|
|
|
}
|