Skip to content
This repository was archived by the owner on Feb 11, 2020. It is now read-only.

Commit dd698f4

Browse files
author
Dr. Safi
committed
Changed children filter method to current insertion point.
1 parent 73ed4ea commit dd698f4

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

module/reusableNestedUnit/NestedUnit.class.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@ export default ({ Superclass }) => {
1919
return this
2020
}
2121

22+
/**
23+
* Get children corresponding to the current insertion point.
24+
*/
25+
async filterChildrenOfCurrentInsertionPoint({
26+
insertionPointKey,
27+
children = this.children
28+
} = {}) {
29+
// [1] get children immediate & relating to this insertion position.
30+
return await children.filter(child => { // filter children that correspont to the current insertionpoint.
31+
return (
32+
child.insertionPosition.insertionPoint == insertionPointKey &&
33+
child.insertionPosition.insertionPathPointer == null
34+
)
35+
})
36+
}
37+
2238
/**
2339
* @description gets document from database using documentKey and populates the data to the instance.
2440
*

module/reusableNestedUnit/implementation/middleware/NestedUnit.class.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ export default ({ Superclass }) => {
3838
// get callback from subtrees
3939
if(this.insertionPoint) {
4040
for (let insertionPoint of this.insertionPoint) {
41-
let subsequentArray = await this.initializeInsertionPoint({ insertionPoint })
41+
let children = await this.filterChildrenOfCurrentInsertionPoint({
42+
insertionPointKey: insertionPoint.key,
43+
children: this.children
44+
})
45+
let subsequentArray = await this.initializeInsertionPoint({ insertionPoint, children })
4246
if(array.length != 0) {
4347
await Array.prototype.push.apply(array, subsequentArray)
4448
} else {
@@ -49,25 +53,21 @@ export default ({ Superclass }) => {
4953
return array;
5054
}
5155

52-
async initializeInsertionPoint({insertionPoint}) {
53-
// [1] get children immediate & relating to this insertion position.
54-
let filteredChildren = this.children.filter(object => { // filter children that correspont to the current insertionpoint.
55-
return (object.insertionPosition.insertionPoint == insertionPoint.key && object.insertionPosition.insertionPathPointer == null)
56-
})
56+
async initializeInsertionPoint({ insertionPoint, children }) {
5757
// [2] check type of subtrees execution: race first, all ... .
58-
let executionTypeCallbackName;
59-
switch(insertionPoint.executionType) {
58+
let callback;
59+
switch(insertionPoint.executionType) { // execution type callback name
6060
case 'chronological':
61-
executionTypeCallbackName = 'initializeTreeInChronologicalSequence'
61+
callback = 'initializeTreeInChronologicalSequence'
6262
break;
6363
case 'middlewareArray':
64-
executionTypeCallbackName = 'returnMiddlewareArray'
64+
callback = 'returnMiddlewareArray'
6565
break;
6666
default:
6767
console.log(`"${insertionPoint.executionType}" executionType doesn\'t match any kind.`)
6868
}
6969
// [3] call handler on them.
70-
return await this[executionTypeCallbackName](filteredChildren)
70+
return await this[callback](children)
7171
}
7272

7373
async initializeTreeInChronologicalSequence(treeChildren) {

0 commit comments

Comments
 (0)