The issue
Working with huge classes, it's hard to sort the methods and find what you need (class of thousands of line). Which method is useful ? Where to look at ? public, private and protected keywords, CTRL+F or plugins like minimap helps, but in long files it's still hard.
Soluce
Allow to split the definition of a class into multiple files. Which will allows the developer to separate the code in a logicial way.
For example : put the protected methods in one file and public methods in an other file.
Actual way to solve the issue
File Foo.js
import Root from './parts/Root.js';
import Part1 from './parts/Part1.js';
/**
* class Foo extends recursiveInterface(array)
*
* Is equivalent to :
*
* class Foo extends(
* class A extends (
* class B extends (
* class C extends (class ROOT)
* )
* )
* )
*/
function recursiveInterface(arr, i = 0) {
if (!arr[i]) {
return class { };
}
return arr[i](recursiveInterface(arr, i + 1));
}
export default class Foo extends recursiveInterface([
Part1,
// Keep Root at the end, this is the root class for the dependencies
Root,
]) { }
File Root.js or File Part1.js
export default function(superclass) {
return class Foo extends superclass {
};
}
To use it :
import Foo from 'Foo.js';
const obj = new Foo();
// Obj here contains all methods
// and attributes defined in all the files parts
Possible solution to integrate
We could add a new keyword called "complete" that will automatically merge the class definitions, like :
File Foo.js
import Part1 from './Part1.js';
import Part2 from './Part2.js';
export default class Foo complete Part1, Part2 {
// ...
}
File Part1.js / Part2.js / ...
export default class Foo {
// ...
}
Thank you for reading me :)