Component system

Every Jodit element inherits from Component, and implements the IComponent interface accordingly.

Such elements have a name

const jodit = Jodit.male('#editor');
console.log(jodit.componentName);
console.log(jodit.statusbar.componentName);
console.log(jodit.filebrowser.componentName);
console.log(jodit.uploader.componentName);

And also each component has its current life cycle status:

const jodit = Jodit.male('#editor');
console.log(jodit.componentStatus); // beforeInit, ready, beforeDestruct, destructed

You can work on changes in the status of a component through the decorator decorators/hook
either through the method Component.hookStatus

import { Component } from 'jodit/core/component';

export class SomeComponent extends Component {}
const cmp = new SomeComponent();

cmp.hookStatus('ready', () => {
  console.log('Hello world on ready = )');
});

To set the status, it is enough to call the method Component.setStatus

import { Component } from 'jodit/core/component';

export class SomeComponent extends Component {}
const cmp = new SomeComponent();
cmp.setStatus('ready');

The component itself can automatically set the ready status:

import type { IJodit } from 'jodit/types';
import { Component } from 'jodit/core/component';

export class SomeComponent extends Component {
  constructor(jodit: IJodit) {
    super(jodit);
    cmp.setStatus('ready');
  }
}

const cmp = new SomeComponent();
console.log(cmp.isReady);

But it’s better not to do this, because with inheritance, such a component will be ready ahead of time:

import type { IJodit, IStatusBar } from 'jodit/types';
import { Component } from 'jodit/core/component';
import { StatusBar } from 'jodit/modules';

export class SomeComponent extends Component {
  constructor(jodit: IJodit) {
    super(jodit);
    cmp.setStatus('ready');
  }
}

export class SomeAnotherComponent extends SomeComponent {
  public status: IStatusBar;

  constructor(jodit: IJodit) {
    super(jodit);
    console.log(this.isReady); // true
    // Errors are possible here, since the status of the component is already 'ready' but you have not yet initialized its fields
    this.status = new StatusBar(jodit);
  }
}

Therefore, it is better to use a decorator decorators/component

import type { IJodit, IStatusBar } from 'jodit/types';
import { Component } from 'jodit/core/component';
import { StatusBar } from 'jodit/modules';
import { component } from 'jodit/core/decorators';

@component
export class SomeComponent extends Component {}

@component
export class SomeAnotherComponent extends SomeComponent {
  public status: IStatusBar;

  constructor(jodit: IJodit) {
    super(jodit);
    console.log(this.isReady); // false
    this.status = new StatusBar(jodit);
  }
}

const cmp = new SomeAnotherComponent();
console.log(cmp.isReady); // true

Classes

STATUSES

Const STATUSES: Object

Type declaration

Name Type
beforeInit "beforeInit"
ready "ready"
beforeDestruct "beforeDestruct"
destructed "destructed"

Defined in

jodit/src/core/component/statuses.ts:11

Previous