Allow Trait API clients to override and use initlialize method of TraitView class
Hi @vrudikov I didn't get what do you suggest. Would you like to have some kind of init() method which acts as a callback after the initialization?
Read full answer below ↓Question
Current behaviour:
When traits get added with TraitView.addType method they are extend TraitsViewer.itemView(which is TraitView). When TraitSelectView class extends TraitView it overrides initialize(o) method and calls TraitView.prototype.initialize.apply(this, arguments); to initialize parent class(as i understand). This allows TraitSelectView to override some initializing logic. For example override this.tmpl and use custom template for a trait
For a custom trait with overridden initialize method there we gonna see an error:

editor.TraitManager.addType('attrNoVal', {
initialize (o) { console.log('TEST') },
})
But with the following code everything works perfect and i can override a this.tmpl and do other things dirty :) things:
editor.TraitManager.addType('attrNoVal', {
initialize (o) {
// Dirty hack :) But it works
editor.TraitManager.getTraitsViewer().itemView.prototype.initialize.apply(this, arguments)
},
})
Expected behaviour: Allow Trait API clients to override and use initlialize method of TraitView class so we can easily customize initializing logic of a trait
Answers (1)
Hi @vrudikov I didn't get what do you suggest. Would you like to have some kind of init() method which acts as a callback after the initialization?
Related Questions and Answers
Continue research with similar issue discussions.
Issue #2405
[QUESTIONS] ckeditor is not initialized when replace trait text
why when i change the ckeditor trait text it is not initialized my trait <pre> domComps.addType('text',{ model: dModel.extend({ defaults: O...
Issue #3732
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
Issue #3309
TextNodes interfere when changing content on element
Version: 0.16.44 Hi @artf I have a custom block with a custom button component, which its content is similar to this one. <a data-gjs-type=...
Issue #2188
[QUESTION] How to change tagName using traits.
Hello, I want to achieve this: When user clicks on a heading tag H1, H2, H3 ... I want a trait to appear (of a select / dropdown type) whic...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.
Browse premium plugins →Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.