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

Commit f5cec4a

Browse files
author
Dr. Safi
committed
Fixed default superclass to extend in nestedUnit controller.
The default superclass cannot be Object/Function because it breaks the prototype for new instances for some reason, therefore EventEmitter is used instead.
1 parent 1ce7aa6 commit f5cec4a

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

module/prototypeChainDebug/entrypoint.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Returns a proxy with traps to add meta information.
44
*/
55
function prototypeChainDebug(Class) {
6+
67
// Static class
78
Class.meta = {
89
Class: `${Class.name}`,

module/reusableNestedUnit/Controller.class.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const EventEmitter = require('events');
12
import commonMethod from './commonMethod.mixin'
23
import createInstance from 'appscript/module/createInstance.staticMethod'
34
import { usingGenericInstance as populateInstancePropertyFromJson, usingThis as populateInstancePropertyFromJson_this } from 'appscript/module/populateInstancePropertyFromJson.method'
@@ -14,12 +15,11 @@ import { mix } from 'mixwith'
1415
*/
1516
export default ({
1617
methodInstanceName,
17-
Superclass = Object,
18+
Superclass = EventEmitter, // defaulting to EventEmitter and not Object / Function because extending Object/Function manipulates this prototype in new calls for some reason.
1819
mixin
1920
}) => {
2021
let mixinArray = [/*commonMethod*/]
2122
let self =
22-
@conditional({ decorator: prototypeChainDebug, condition: process.env.SZN_DEBUG })
2323
@add({ to: 'static'}, {
2424
createInstance,
2525
populateInstancePropertyFromJson,
@@ -28,12 +28,13 @@ export default ({
2828
@add({ to: 'prototype'}, {
2929
populateInstancePropertyFromJson_this
3030
})
31-
@conditional({ condition: mixin, decorator: applyMixin({ mixin }) })
31+
@conditional({ decorator: prototypeChainDebug, condition: process.env.SZN_DEBUG })
3232
@extendedSubclassPattern.Superclass()
33-
@superclassInstanceContextPattern()
3433
@conditional({ decorator: extendedSubclassPattern.Subclass(), condition: (methodInstanceName && Superclass && Superclass.addSubclass != undefined ) })
34+
@conditional({ condition: mixin, decorator: applyMixin({ mixin }) })
35+
@superclassInstanceContextPattern() // applied on the mixin i.e. specific controller.
3536
class ReusableController extends mix(Superclass).with(...mixinArray) {
36-
37+
3738
@cacheInstance({
3839
cacheArrayName: 'nestedUnit',
3940
keyArgumentName: 'nestedUnitKey'

module/reusableNestedUnit/entrypoint.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ let counter = [] // allows to have a unique set of relations among different nes
2323
* @return {Object} Related Classes
2424
*/
2525
function createStaticInstanceClasses({
26-
Superclass = Object, /* Usually the higher Application class */
26+
Superclass, /* Usually the higher Application class */
2727
implementationType,
2828
cacheName = false /* {Boolean || String} */
29-
}) {
29+
} = {}) {
3030
// Used as caching key.
3131
let automaticCacheNaming;
3232
if(cacheName && typeof cacheName == 'boolean') {

0 commit comments

Comments
 (0)