@@ -5,6 +5,7 @@ import createInstance from 'appscript/module/createInstance.staticMethod'
55import { usingGenericInstance as populateInstancePropertyFromJson , usingThis as populateInstancePropertyFromJson_this } from 'appscript/module/populateInstancePropertyFromJson.method'
66import addStaticSubclassToClassArray from 'appscript/module/addStaticSubclassToClassArray.staticMethod'
77import prototypeChainDebug from 'appscript/module/prototypeChainDebug'
8+ import { MultiplePrototypeChain } from 'appscript/module/multiplePrototypeChain'
89import assert from 'assert'
910
1011let debugExecuted = false
@@ -48,68 +49,19 @@ module.exports = ({
4849 let self = this // specific Controller that is a subclass of 'self' (ReusableController)
4950 let contextInstance = new self ( false , ...args )
5051
51- // create proxied refrence of subclasses
52+ // create a new list object for proxied refrence of subclasses
5253 contextInstance . instanceExtendedSubclass = Object . keys ( self . extendedSubclass . static )
5354 . reduce ( ( object , key ) => {
54- // add proxy to the subclass
55- object [ key ] = self . createPrototypeChainOnConstructor ( self . extendedSubclass . static [ key ] ) ;
55+ // add proxied subclass to the list
56+ object [ key ] = MultiplePrototypeChain . newChainOnInstanceCreation ( {
57+ Class : self . extendedSubclass . static [ key ] ,
58+ contextInstance
59+ } )
5660 return object
5761 } , { } )
5862 return contextInstance
5963 }
6064
61- static createPrototypeChainOnConstructor ( Class ) {
62- return new Proxy ( Class , {
63- construct : ( target , argumentsList , newConstructorFunc ) => {
64- let instance = Reflect . construct ( target , argumentsList )
65- Object . setPrototypeOf ( instance , self . createUniqueProtoChain ( Object . getPrototypeOf ( instance ) ) )
66- console . log ( instance . __proto__ . __proto__ )
67- return instance
68- } ,
69- // getPrototypeOf(target) {
70-
71- // }
72- } )
73- }
74-
75- static createUniqueProtoChain ( currentPrototype ) {
76- if ( currentPrototype == null ||
77- currentPrototype . constructor == Object ||
78- currentPrototype . constructor == Function
79- ) return currentPrototype
80-
81- let delegatedPrototype = Object . getPrototypeOf ( currentPrototype )
82- let pointerPrototype = Object . create ( self . createUniqueProtoChain ( delegatedPrototype ) )
83- pointerPrototype = new Proxy ( pointerPrototype , {
84- get : function ( target , property , receiver ) {
85- Object . defineProperty ( pointerPrototype , 'delegatedPrototype' , {
86- value : currentPrototype ,
87- writable : true ,
88- enumerable : true ,
89- configurable : true
90- } )
91- switch ( property ) {
92- case 'delegatedPrototype' :
93- return currentPrototype
94- break ;
95- case '__proto__' :
96- return Object . getPrototypeOf ( pointerPrototype )
97- break ;
98- default :
99- break ;
100- }
101- if ( currentPrototype . hasOwnProperty ( property ) ) {
102- return Reflect . get ( currentPrototype , property )
103- } else if ( Object . getPrototypeOf ( target ) ) {
104- return Reflect . get ( Object . getPrototypeOf ( target ) , property )
105- } else {
106- return undefined
107- }
108- }
109- } )
110- return pointerPrototype
111- }
112-
11365 static initializeStaticClass ( ) {
11466 if ( methodInstanceName && superclass && superclass . eventEmitter ) {
11567 superclass . eventEmitter . on ( 'initializationEnd' , ( ) => {
@@ -128,82 +80,32 @@ module.exports = ({
12880 return Reflect . construct ( contextInstance . instanceExtendedSubclass [ name ] , args )
12981 }
13082
131- async getNestedUnit ( { nestedUnitKey, controllerInstance = this , additionalChildNestedUnit = [ ] , pathPointerKey = null } ) {
83+ async getNestedUnit ( { nestedUnitKey, additionalChildNestedUnit = [ ] , pathPointerKey = null } ) {
13284 let nestedUnitInstance ;
133- if ( ! ( nestedUnitKey in controllerInstance . instance . nestedUnit ) ) {
134- if ( this . instanceExtendedSubclass ) {
135- nestedUnitInstance = await this . callSubclass ( 'NestedUnit' , [ nestedUnitKey ] )
136- if ( ! debugExecuted ) {
137- controllerInstance = this . __proto__
138- // console.log(controllerInstance)
139- // console.log(nestedUnitInstance.__proto__.__proto__.__proto__)
140- controllerInstance . AppInstance = this . AppInstance
141- controllerInstance . instance = this . instance
142- assert . strictEqual ( controllerInstance , nestedUnitInstance . __proto__ . __proto__ . __proto__ )
143- debugExecuted = true
144- }
145- nestedUnitInstance . __proto__ . __proto__ . __proto__ = controllerInstance
146- } else {
147- nestedUnitInstance = await self . callSubclass ( 'NestedUnit' , [ nestedUnitKey ] )
148- if ( ! debugExecuted ) {
149- controllerInstance = this . __proto__
150- // console.log(controllerInstance)
151- // console.log(nestedUnitInstance.__proto__.__proto__.__proto__)
152- controllerInstance . AppInstance = this . AppInstance
153- controllerInstance . instance = this . instance
154- assert . strictEqual ( controllerInstance , nestedUnitInstance . __proto__ . __proto__ . __proto__ )
155- debugExecuted = true
156- }
157- nestedUnitInstance . __proto__ . __proto__ . __proto__ = controllerInstance
158- }
85+ if ( ! ( nestedUnitKey in this . instance . nestedUnit ) ) {
86+ nestedUnitInstance = await this . callSubclass ( 'NestedUnit' , [ nestedUnitKey ] )
15987 await nestedUnitInstance . initializeInstance ( )
88+ console . log ( nestedUnitInstance )
16089 // add children trees:
16190 nestedUnitInstance . additionalChildNestedUnit = additionalChildNestedUnit
16291 // add pathPointerKey to allow applying additional corresponding additional children.
16392 nestedUnitInstance . pathPointerKey = pathPointerKey
16493 // add to class cache
165- controllerInstance . instance . nestedUnit [ nestedUnitKey ] = nestedUnitInstance
94+ this . instance . nestedUnit [ nestedUnitKey ] = nestedUnitInstance
16695 } else {
167- nestedUnitInstance = controllerInstance . instance . nestedUnit [ nestedUnitKey ]
96+ nestedUnitInstance = this . instance . nestedUnit [ nestedUnitKey ]
16897 }
16998 return nestedUnitInstance
17099 }
171100
172- async getUnit ( { unitKey, controllerInstance = this } ) {
101+ async getUnit ( { unitKey} ) {
173102 let unitInstance ;
174- if ( ! ( unitKey in controllerInstance . instance . unit ) ) {
175- if ( this . instanceExtendedSubclass ) {
176- unitInstance = await this . callSubclass ( 'Unit' , [ unitKey ] )
177- if ( ! debugEx2 ) {
178- controllerInstance = this . __proto__
179- // console.log(controllerInstance)
180- // console.log(nestedUnitInstance.__proto__.__proto__.__proto__)
181- controllerInstance . AppInstance = this . AppInstance
182- controllerInstance . instance = this . instance
183- assert . strictEqual ( controllerInstance , unitInstance . __proto__ . __proto__ . __proto__ )
184- debugEx2 = true
185- }
186- // assert.strictEqual(unitInstance.__proto__.__proto__.__proto__, controllerInstance)
187- unitInstance . __proto__ . __proto__ . __proto__ = controllerInstance
188- } else {
189- unitInstance = await self . callSubclass ( 'Unit' , [ unitKey ] )
190- if ( ! debugEx2 ) {
191- controllerInstance = this . __proto__
192- // console.log(controllerInstance)
193- // console.log(nestedUnitInstance.__proto__.__proto__.__proto__)
194- controllerInstance . AppInstance = this . AppInstance
195- controllerInstance . instance = this . instance
196- assert . strictEqual ( controllerInstance , unitInstance . __proto__ . __proto__ . __proto__ )
197- debugEx2 = true
198- }
199- // assert.strictEqual(unitInstance.__proto__.__proto__.__proto__, controllerInstance)
200- unitInstance . __proto__ . __proto__ . __proto__ = controllerInstance
201- }
202- // console.log(unitInstance)
103+ if ( ! ( unitKey in this . instance . unit ) ) {
104+ unitInstance = await this . callSubclass ( 'Unit' , [ unitKey ] )
203105 await unitInstance . initializeInstance ( )
204- controllerInstance . instance . unit [ unitKey ] = unitInstance
106+ this . instance . unit [ unitKey ] = unitInstance
205107 } else {
206- unitInstance = controllerInstance . instance . unit [ unitKey ]
108+ unitInstance = this . instance . unit [ unitKey ]
207109 }
208110 return unitInstance
209111 }
0 commit comments