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

Commit f94de8b

Browse files
author
Dr. Safi
committed
Updated working version using multiple prototype chain implementation.
1 parent 5d8806a commit f94de8b

File tree

8 files changed

+19
-14
lines changed

8 files changed

+19
-14
lines changed

module/multiplePrototypeChain/entrypoint.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ let self = class MultiplePrototypeChain {
6666
return Reflect.set(delegatedPrototype, property, value)
6767
break;
6868
}
69-
}
69+
},
70+
has: function(target, prop) {
71+
return prop in delegatedPrototype
72+
}
7073
}
7174
}
7275

module/multiplePrototypeChain/entrypoint.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ describe('Multiple Prototype Chain creation', () => {
2929
assert.strictEqual(newInstance.t, 't')
3030
assert.strictEqual(newInstance.delegatedPrototype.t, 't')
3131
})
32+
33+
it('In operator should check in the delegatedPrototype', () => {
34+
newInstance.b = 'b'
35+
assert.strictEqual('b' in newInstance, true)
36+
})
3237

3338
it('create new prototypes with corresponding delegatedPrototypes values equal to original proto chain', () => {
3439
// Subclass

module/reusableNestedUnit/Controller.class.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ module.exports = ({
8585
if(!(nestedUnitKey in this.instance.nestedUnit)) {
8686
nestedUnitInstance = await this.callSubclass('NestedUnit', [nestedUnitKey])
8787
await nestedUnitInstance.initializeInstance()
88-
console.log(nestedUnitInstance)
8988
// add children trees:
9089
nestedUnitInstance.additionalChildNestedUnit = additionalChildNestedUnit
9190
// add pathPointerKey to allow applying additional corresponding additional children.

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ module.exports = ({ superclass }) => {
6161
let promiseArray = []
6262
promiseArray = conditionTreeChildren.map(conditionTreeChild => {
6363
return new Promise(async (resolve, reject) => {
64-
let controllerInstancePrototype = this.__proto__.__proto__.__proto__
6564
// Add the rest of the immediate children to the next tree as additional children. propagate children to the next tree.
6665

6766
if(this.children.length != 0) {
@@ -72,7 +71,6 @@ module.exports = ({ superclass }) => {
7271

7372
let callback = await this.initializeConditionTree({
7473
nestedUnitKey: conditionTreeChild.nestedUnit,
75-
controllerInstance: controllerInstancePrototype,
7674
additionalChildNestedUnit: this.children,
7775
pathPointerKey: conditionTreeChild.pathPointerKey
7876
})

module/reusableNestedUnit/implementation/condition/controllerMixin.mixin.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@ export default Mixin(({ superclass }) => {
1010
/**
1111
* @description when first called "this" context is assigned to the AppInstance for the comming request. And on subsequest calls it is assigned to the nestedUnit instance.
1212
*
13-
* @param {any} {nestedUnitKey, controllerInstance = this}
13+
* @param {any} {nestedUnitKey}
1414
* @returns
1515
*/
16-
async initializeConditionTree({ nestedUnitKey, controllerInstance = this, additionalChildNestedUnit = [], pathPointerKey = null}) { // Entrypoint Instance
16+
async initializeConditionTree({ nestedUnitKey, additionalChildNestedUnit = [], pathPointerKey = null}) { // Entrypoint Instance
1717
// self.debug.push(nestedUnitKey)
1818
// let nestedUnitInstance = await ConditionTree.createInstance(this.instance.nestedUnit, nestedUnitKey, ConditionTree.getDocumentQuery)
1919

2020
// [1] get nestedUnit
21-
let nestedUnitInstance = await this.getNestedUnit({ nestedUnitKey, controllerInstance, additionalChildNestedUnit, pathPointerKey })
21+
let nestedUnitInstance = await this.getNestedUnit({ nestedUnitKey, additionalChildNestedUnit, pathPointerKey })
22+
2223
// [2] Check condition.
2324
let {conditionImplementation:unitKey} = nestedUnitInstance
24-
let unitInstance = await this.getUnit({unitKey, controllerInstance})
25+
let unitInstance = await this.getUnit({unitKey})
2526

2627
let conditionMet = await unitInstance.checkCondition()
2728

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ module.exports = ({ superclass }) => {
6161
let renderedStringArray = []
6262
for (var index = 0; index < treeChildren.length; index++) {
6363
let treeChild = treeChildren[index]
64-
let controllerInstancePrototype = this.__proto__.__proto__.__proto__
6564
// Add the rest of the immediate children to the next tree as additional children. propagate children to the next tree.
6665
if(this.children.length != 0) {
6766
await Array.prototype.push.apply(this.children, this.additionalChildNestedUnit)
@@ -71,7 +70,6 @@ module.exports = ({ superclass }) => {
7170
let subsequentRenderedTemplate = [
7271
await this.initializeNestedUnit({
7372
nestedUnitKey: treeChild.nestedUnit,
74-
controllerInstance: controllerInstancePrototype,
7573
additionalChildNestedUnit: this.children,
7674
pathPointerKey: treeChild.pathPointerKey
7775
})

module/reusableNestedUnit/implementation/template/controllerMixin.mixin.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ export default Mixin(({ superclass }) => {
1717
}
1818
}
1919

20-
async initializeNestedUnit({ nestedUnitKey, controllerInstance = this, additionalChildNestedUnit = [], pathPointerKey = null }) { // Entrypoint Instance
20+
async initializeNestedUnit({ nestedUnitKey, additionalChildNestedUnit = [], pathPointerKey = null }) { // Entrypoint Instance
2121
// [1] get nestedUnit
22-
let nestedUnitInstance = await this.getNestedUnit({ nestedUnitKey, controllerInstance, additionalChildNestedUnit, pathPointerKey })
22+
let nestedUnitInstance = await this.getNestedUnit({ nestedUnitKey, additionalChildNestedUnit, pathPointerKey })
2323
// [2] get unit.
2424
let { viewImplementation: unitKey } = nestedUnitInstance
25-
let unitInstance = await this.getUnit({ unitKey, controllerInstance })
25+
let unitInstance = await this.getUnit({ unitKey })
2626
await unitInstance.pupolateTemplateFile()
2727

2828
// views argument that will be initiallized inside templates:

utilityFunction/middleware/implementConditionActionOnModuleUsingJson.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ let MiddlewareController = createStaticInstanceClasses({
1414
export default ({setting}) => {
1515
return async (context, next) => {
1616
let isCalledNext = false
17+
// console.log(setting)
1718
switch(setting.type) {
1819
case 'middlewareNestedUnit':
1920
// await context.instance.handleMiddlewareNestedUnit(setting.name) // another way is to create a method in the instance class.
2021
const nestedUnitKey = setting.name
2122
const portAppInstance = context.instance
2223
let middlewareArray;
23-
let middlewareController = await new MiddlewareController(false, { portAppInstance: portAppInstance })
24+
let middlewareController = await MiddlewareController.createContext({ portAppInstance: portAppInstance })
2425
middlewareArray = await middlewareController.initializeNestedUnit({ nestedUnitKey: nestedUnitKey })
2526
await implementMiddlewareOnModuleUsingJson(middlewareArray)(context, next)
2627
isCalledNext = true

0 commit comments

Comments
 (0)