Our state of the art Gantt chart


Post by Jerther »

Hi!

I'm using https://www.bryntum.com/docs/gantt/api/Core/mixin/Override to apply new methods on existing classes. Works fine, but apparently I cannot add methods. Here's a use case:

class TemplateColumnOverride {
    static get target() {
        return {
            class      : TemplateColumn,
            product    : 'grid',
            minVersion : '1.0',
            maxVersion : '1.5'
        }
    }

    renderer(renderData) {
        // call overridden function (optional)
        const value = this._overridden.renderer.call(this, renderData);
        const colors = this._getUsedColors();  // this._getUsedColors is undefined
        const tables = this._getSquareTables();  // this._getSquareTables is undefined
        this._applyNewColorsToTables(colors, tables);  // this._applyNewColorsToTables is undefined
        return 'HELLO' + value;
    }

    _getUsedColors() {
        // 15 lines of code here
    }

    _getSquareTables() {
        // 10 lines of code here
    }

    _applyNewColorsToTables(colors, tables) {
        // 15 lines of code here
    }

}
Override.apply(TemplateColumnOverride);

What would be the best way to do this?


Post by alex.l »

To add new methods you need to extend the class and not override.

All the best,
Alex


Post by Jerther »

I see.

Suppose I need to do this for a base class:

class Base
class ChildA extends Base
class ChildB extends Base
class ChildC extends Base

If I override Base, then all three children get the new stuff.

However, if I extend:

class NewBase extends Base

Then the three children get nothing.

I suppose it'd be possible with some kind of mixin mechanism, but then again I'd have to extend all three children and set them as replacement everywhere, when possible. right?


Post by alex.l »

Yes, correct. Our Override class is created to simplify prototype overriding and make possible to use patch fixes that may be automatically disabled after you updated product version.
You still can use standard JavaScript mechanisms and change prototypes as you need https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain

All the best,
Alex


Post by Jerther »

Oh I understand! Override has a specific (and neat) use case, which is different than mine. Thanks alex for the explanation, and for pointing to the relevant documentation as well.


Post Reply