Last active
November 9, 2017 14:21
-
-
Save malexandre/3802ed64f6f37e72d954e91da1541ade to your computer and use it in GitHub Desktop.
Solutions to manage big classes through multiple files for modularity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export defaut MyBigClass extends MyParent { | |
constructor() { | |
super() | |
} | |
method1() { | |
// ... | |
} | |
method2() { | |
// Link to method1 in logic | |
} | |
method3() { | |
// ... | |
} | |
method4() { | |
// ... | |
} | |
// More big methods | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export MyFragment1 { | |
method1: () => { | |
// ... | |
}, | |
method2: () => { | |
// Link to method1 in logic | |
} | |
} | |
export MyFragment2 { | |
method3: () => { | |
// ... | |
} | |
} | |
export MyFragment3 { | |
method4: () => { | |
// ... | |
} | |
} | |
export defaut class MyBigClass extends MyParent { | |
constructor() { | |
super() | |
const fragments = { ...MyFragment1, ...MyFragment2, ...MyFragment3 } | |
Object.keys(fragments).forEach((k) => { | |
this[k] = (...args) => fragments[k].call(this, ...args) | |
}) | |
} | |
// More big methods | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class MyFragment1 { | |
constructor(bigClass) { | |
super() | |
this.bigClass = bigClass | |
} | |
method1() { | |
// ... | |
} | |
method2() { | |
// Link to method1 in logic | |
} | |
} | |
export class MyFragment2 { | |
constructor(bigClass) { | |
super() | |
this.bigClass = bigClass | |
} | |
method3() { | |
// ... | |
} | |
} | |
export class MyFragment3 { | |
constructor(bigClass) { | |
super() | |
this.bigClass = bigClass | |
} | |
method4() { | |
// ... | |
} | |
} | |
export defaut class MyBigClass extends MyParent { | |
constructor() { | |
super() | |
MyFragment1.call(this) | |
MyFragment2.call(this) | |
MyFragment3.call(this) | |
} | |
// More big methods | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export MyFragment1 (self) => { | |
method1: () => { | |
// ... | |
}, | |
method2: () => { | |
// Link to method1 in logic | |
} | |
} | |
export MyFragment2 (self) => { | |
method3: () => { | |
// ... | |
} | |
} | |
export MyFragment3 (self) => { | |
method4: () => { | |
// ... | |
} | |
} | |
export defaut class MyBigClass extends MyParent { | |
constructor() { | |
super() | |
} | |
MyFragment1 = MyFragment1(this) | |
MyFragment2 = MyFragment2(this) | |
MyFragment3 = MyFragment3(this) | |
// More big methods | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export MyFragment1 = (Parent) => class MyFragment1 extends (Parent || Object) { | |
constructor() { | |
super() | |
} | |
method1() { | |
// ... | |
} | |
method2() { | |
// Link to method1 in logic | |
} | |
} | |
export MyFragment2 = (Parent) => class MyFragment2 extends (Parent || Object) { | |
constructor() { | |
super() | |
} | |
method3() { | |
// ... | |
} | |
} | |
export MyFragment3 = (Parent) => class MyFragment3 extends (Parent || Object) { | |
constructor() { | |
super() | |
} | |
method4() { | |
// ... | |
} | |
} | |
export defaut class MyBigClass extends EXTENDED_MODELS.reduce((extended, model) => model(extended), MyParent) { | |
constructor() { | |
super() | |
} | |
// More big methods | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class MyFragment1 { | |
constructor(bigClass) { | |
super() | |
this.bigClass = bigClass | |
} | |
method1() { | |
// ... | |
} | |
method2() { | |
// Link to method1 in logic | |
} | |
} | |
export class MyFragment2 { | |
constructor(bigClass) { | |
super() | |
this.bigClass = bigClass | |
} | |
method3() { | |
// ... | |
} | |
} | |
export class MyFragment3 { | |
constructor(bigClass) { | |
super() | |
this.bigClass = bigClass | |
} | |
method4() { | |
// ... | |
} | |
} | |
export defaut class MyBigClass extends MyParent { | |
constructor() { | |
super() | |
} | |
MyFragment1 = MyFragment1(this) | |
MyFragment2 = MyFragment2(this) | |
MyFragment3 = MyFragment3(this) | |
// More big methods | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment