@dazn/kopytko-framework 1.3.1 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [1.3.2](https://github.com/getndazn/kopytko-framework/compare/v1.3.1...v1.3.2) (2022-09-01)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Ignoring Invalid elements when calculating elements' index in children array ([#31](https://github.com/getndazn/kopytko-framework/issues/31)) ([73aed6e](https://github.com/getndazn/kopytko-framework/commit/73aed6e2e7ba38b946c81fe18ceecf414f7bbcf2))
7
+
1
8
  ## [1.3.1](https://github.com/getndazn/kopytko-framework/compare/v1.3.0...v1.3.1) (2022-08-05)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dazn/kopytko-framework",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "A modern Roku's Brightscript framework",
5
5
  "keywords": [
6
6
  "brightscript",
@@ -69,21 +69,6 @@ function KopytkoDiffUtility() as Object
69
69
  m._diffElementChildren(currentElement.children, newElement.children, newElement.props.id)
70
70
  end sub
71
71
 
72
- ' @private
73
- prototype._markElementToBeRemoved = sub (element as Object)
74
- m._diffResult.elementsToRemove.push(element.props.id)
75
-
76
- if (element.children = Invalid OR element.children.count() = 0)
77
- return
78
- end if
79
-
80
- for each child in element.children
81
- if (child <> Invalid)
82
- m._markElementToBeRemoved(child)
83
- end if
84
- end for
85
- end sub
86
-
87
72
  ' @private
88
73
  prototype._diffElementProps = sub (elementId as String, currentProps as Object, newProps as Object)
89
74
  for each newProp in newProps
@@ -98,34 +83,49 @@ function KopytkoDiffUtility() as Object
98
83
  end for
99
84
  end sub
100
85
 
101
- ' @todo Make it not rerender the whole children tree if they were only reordered
86
+ ' @todo Support elements reordering
102
87
  ' @private
103
88
  prototype._diffElementChildren = sub (currentChildren as Object, newChildren as Object, parentElementId = Invalid as Dynamic)
104
- if (currentChildren = Invalid)
105
- currentChildren = []
106
- end if
89
+ if (newChildren = Invalid) then newChildren = []
107
90
 
108
- if (newChildren = Invalid)
109
- newChildren = []
91
+ currentChildrenMapped = {}
92
+ if (currentChildren <> Invalid)
93
+ for each currentChild in currentChildren
94
+ if (currentChild <> Invalid)
95
+ currentChildrenMapped[currentChild.props.id] = currentChild
96
+ end if
97
+ end for
110
98
  end if
111
99
 
112
- if (currentChildren.count() > newChildren.count())
113
- biggestArray = currentChildren
114
- else
115
- biggestArray = newChildren
116
- end if
100
+ nonInvalidNewChildIndex = 0
101
+ for each newChild in newChildren
102
+ if (newChild <> Invalid)
103
+ newChild.index = nonInvalidNewChildIndex
104
+ nonInvalidNewChildIndex++
105
+ newChild.parentId = parentElementId
117
106
 
118
- for i = 0 to biggestArray.count() - 1
119
- if (newChildren[i] <> Invalid)
120
- newChildren[i].index = i
121
- newChildren[i].parentId = parentElementId
107
+ m._diffElement(currentChildrenMapped[newChild.props.id], newChild)
108
+ currentChildrenMapped.delete(newChild.props.id)
122
109
  end if
110
+ end for
123
111
 
124
- if (currentChildren[i] <> Invalid)
125
- currentChildren[i].index = i
126
- end if
112
+ for each currentChildIdToRemove in currentChildrenMapped
113
+ m._markElementToBeRemoved(currentChildrenMapped[currentChildIdToRemove])
114
+ end for
115
+ end sub
116
+
117
+ ' @private
118
+ prototype._markElementToBeRemoved = sub (element as Object)
119
+ m._diffResult.elementsToRemove.push(element.props.id)
127
120
 
128
- m._diffElement(currentChildren[i], newChildren[i])
121
+ if (element.children = Invalid OR element.children.count() = 0)
122
+ return
123
+ end if
124
+
125
+ for each child in element.children
126
+ if (child <> Invalid)
127
+ m._markElementToBeRemoved(child)
128
+ end if
129
129
  end for
130
130
  end sub
131
131