1 | import { List } from 'immutable'; |
||
2 | |||
3 | import { findTreeNode } from './findTreeNode'; |
||
4 | |||
5 | export const moveTreeNode = ( |
||
6 | treeData, |
||
7 | currentIndex, |
||
8 | currentPath, |
||
9 | nextIndex, |
||
10 | nextPath, |
||
11 | childIdentifier = 'children', |
||
12 | rootIdentifier = 'root' |
||
13 | ) => { |
||
14 | |||
15 | const originalTreeData = treeData; |
||
16 | |||
17 | const { node: currentParent, indexPath: currentIndexPath } = findTreeNode( |
||
18 | treeData, |
||
19 | currentPath, |
||
20 | childIdentifier, |
||
21 | rootIdentifier |
||
22 | ); |
||
23 | |||
24 | if (!currentParent) { |
||
0 ignored issues
–
show
Best Practice
introduced
by
![]() |
|||
25 | return originalTreeData; |
||
26 | } |
||
27 | |||
28 | currentIndexPath.push(...[childIdentifier, currentIndex]); |
||
0 ignored issues
–
show
The variable
currentIndexPath seems to be never declared. If this is a global, consider adding a /** global: currentIndexPath */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
29 | |||
30 | let node = treeData.getIn(currentIndexPath); |
||
0 ignored issues
–
show
Comprehensibility
Naming
Best Practice
introduced
by
The variable
node already seems to be declared on line 17 . Consider using another variable name or omitting the var keyword.
This check looks for variables that are declared in multiple lines. There may be several reasons for this. In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs. If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared. ![]() |
|||
31 | treeData = treeData.deleteIn(currentIndexPath); |
||
32 | |||
33 | const { node: nextParent, indexPath: nextIndexPath } = findTreeNode( |
||
34 | treeData, |
||
35 | nextPath, |
||
36 | childIdentifier, |
||
37 | rootIdentifier |
||
38 | ); |
||
39 | |||
40 | if (!nextParent) { |
||
0 ignored issues
–
show
|
|||
41 | return originalTreeData; |
||
42 | } |
||
43 | |||
44 | nextIndexPath.push(childIdentifier); |
||
0 ignored issues
–
show
The variable
nextIndexPath seems to be never declared. If this is a global, consider adding a /** global: nextIndexPath */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
45 | |||
46 | if (!List.isList(treeData.getIn(nextIndexPath))) { |
||
47 | treeData = treeData.setIn(nextIndexPath, List()); |
||
48 | } |
||
49 | |||
50 | node = node.set('parentId', nextPath.last()); |
||
51 | |||
52 | treeData = treeData.setIn( |
||
53 | nextIndexPath, |
||
54 | treeData.getIn(nextIndexPath).insert(nextIndex, node) |
||
55 | ); |
||
56 | |||
57 | return treeData; |
||
58 | }; |
||
59 |