File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ const cloneDeep = require('lodash.clonedeep')
8
8
import localforage from 'localforage'
9
9
10
10
//we have to do a search because undo/redo saves payloads as deep clones so passing a memory ref would be detrimental
11
+ // This will find you the actual object by ID
11
12
const breadthFirstSearch = ( array , id ) => {
12
13
let queue = [ ...array . filter ( el => typeof el === 'object' ) ] ;
13
14
while ( queue . length ) {
@@ -24,6 +25,23 @@ const breadthFirstSearch = (array,id) => {
24
25
console . log ( "We shouldn't be ever getting here, how did you even search an id that didn't exist?" )
25
26
}
26
27
28
+ //this would find you the parent of a given id
29
+ const breadthFirstSearchParent = ( array , id ) => {
30
+ let queue = [ ...array . filter ( el => typeof el === 'object' ) ] ;
31
+ while ( queue . length ) {
32
+ let evaluated = queue . shift ( )
33
+ for ( let i = 0 ; i < evaluated . children . length ; i ++ ) {
34
+ if ( evaluated . children [ i ] === id ) {
35
+ return evaluated
36
+ }
37
+ }
38
+ if ( evaluated . children . length ) {
39
+ queue . push ( ...evaluated . children )
40
+ }
41
+ }
42
+ console . log ( "We shouldn't be ever getting here, how did you even search an id that didn't exist?" )
43
+ }
44
+
27
45
const mutations = {
28
46
// pushs new component to componentMap
29
47
[ types . ADD_COMPONENT_TO_COMPONENT_MAP ] : ( state , payload ) => {
You can’t perform that action at this time.
0 commit comments