vitaly-t / excellent

Basic DOM Component Framework
https://vitaly-t.github.io/excellent/
MIT License
57 stars 5 forks source link

ES6 classes as controllers #23

Closed vitaly-t closed 6 years ago

vitaly-t commented 6 years ago

It would be nice to optionally support ES6 classes as controllers, if you want to write components that require ES6 support in browsers, which becomes more of a commonplace these days.

Minimum Signature:

class MyES6Controller extends EController {
}

Full Signature:

class MyES6Controller extends EController {
    constructor(name, node) {
        super(name, node);

        // - set up public properties and methods;
        // - modify HTML, via this.node, if needed
    }

    onInit() {
    }

    onReady() {
    }

    onDestroy() {
    }
}

And so you can reuse the existing API:

app.addController('ctrlName', MyES6Controller);

I have started working on branch class that adds such support. See also Classes.

vitaly-t commented 6 years ago

Branch class now has a very solid implementation of this feature, which works both on the application level and inside modules, as per Classes.

UPDATE

The only problem remaining - TypeScript, a freaking nightmare to figure out how to make it work. Any help is much appreciated.

I got to a point where I just hate TypeScript, and wish I didn't add it to to this library, to begin with. Figuring out how to configure a library like this one to work with TypeScript is a major 💩

vitaly-t commented 6 years ago

In the end I decided not to focus too much on the TypeScript support, leaving the integration pain to developers. This feature is all about using native ES6 JavaScript, and that's what matters. I will revisit TypeScript later on.


Released the feature in version 1.6.0.