data-oriented-programming icon indicating copy to clipboard operation
data-oriented-programming copied to clipboard

havePathsInCommon will always return false for nested objects

Open itsramiel opened this issue 3 years ago • 0 comments

the havePathInCommon function of chapter 5 uses lodash intersection which will always return false.

https://github.com/viebel/data-oriented-programming/blob/07bf95b4f4bedeb5cd9cdaa04e59b96efdf2727b/src/chapter05/paths-in-common.js#L1-L4

havePathInCommon uses informationPaths which returns an array of the paths, where each path is an array with keys as values of the array.

A return value example of informationPaths would be:

[
  ['library', 'catalog', 'authorsById', '1', 'name'] ,
  ['library', 'userManagement', 'userssById', '1', 'name'] 
]

but lodash's intersection will not deeply check this nested array, so if the above path was compared with

[
  ['library', 'catalog', 'authorsById', '1', 'name'] ,
]

It will return false because arrays are reference type.

itsramiel avatar Nov 22 '22 15:11 itsramiel