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

the new type branching from text does not

how do I pass down the parent type functions?
Answers (1)
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.
Issue #2337
[BUG / QUESTION] Deleting default styles does not work
Hello, i'm trying to delete some of the default styles of the blocks. I wrote everything I changed in a plugin. I used this function to upd...
Issue #1568
List/Array Trait
Hello, I am trying to write up a trait that allows creating a list of forms and generates the respective in the model. So far I have this:...
Issue #2549
[QUESTION] Update component view on property change
Hi everyone, I'm trying to create a component that will update it's view based on a property value My approach is bassed on #1227 and on th...
Issue #3732
BUG: comment component type do not support adding traits
i am working on a script that add a trait on all the component type , but the comment type do not have the prototype object. code
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.