Issue #972💬 AnsweredOpened March 21, 2018by vrudikov0 reactions

Allow Trait API clients to override and use initlialize method of TraitView class

快速解答by artf

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: image

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)

artfMarch 24, 2018

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.

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...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

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.