Issue #3174Opened December 9, 2020by ThetripGr1 reactions

Creating a new component type does not inherit the functions of it's parent type

Question

Hello, I am trying to create a new common trait shared among all components by creating the following plugin

function backgroundColors(editor) {
    editor.DomComponents.getTypes().map(type => {
        var model = type.model;

        editor.DomComponents.addType(type.id, {
            model: {
                defaults: {
                    traits: [{
                        type: 'select',
                        options: [
                            { value: 'gjs_bgColor_teal', name: 'Teal' }
                        ],
                        label: 'Background Color',
                        name: 'bgColor',
                        changeProp: 1
                    }].concat(model.prototype.defaults.traits),
                },
                init() {
                    this.listenTo(this, 'change:bgColor', this.handleBgColorChange);
                },
                handleBgColorChange() {
                    alert('background color changed');
                }
            },

        });
    })
}

on another plugin file I am also creating a new component type same way following the docs, called extendedText which uses the text type as it's basis. While the text type has the handleBgColorChange() as shown below

image

the new type branching from text does not

image

how do I pass down the parent type functions?

Answers (1)

ThetripGrDecember 9, 20201 reactions

nvm , I revisited the docs more carefully, I somehow missed this about extending parent functions

domc.addType('new-type', {
  extend: 'parent-type',
  extendFn: ['init'], // array of model functions to extend from `parent-type`
  model: {
    init() {
      // do something
    },
  }
});

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.