Skip to content

Commit

Permalink
Refactor #1884
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Mar 19, 2021
1 parent 12d6941 commit c6b1c58
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 64 deletions.
24 changes: 12 additions & 12 deletions src/components/chart/Chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ export class Chart extends Component {
className: PropTypes.string
};

async initChart() {
const chartModule = await import('chart.js');

if (chartModule && chartModule.default) {
this.chart = new chartModule.default(this.canvas, {
type: this.props.type,
data: this.props.data,
options: this.props.options
});
}
initChart() {
import('chart.js').then((module) => {
if (module && module.default) {
this.chart = new module.default(this.canvas, {
type: this.props.type,
data: this.props.data,
options: this.props.options
});
}
});
}

getCanvas() {
Expand All @@ -59,10 +59,10 @@ export class Chart extends Component {
}

reinit() {
if(this.chart) {
if (this.chart) {
this.chart.destroy();
this.initChart();
}
this.initChart();
}

shouldComponentUpdate(nextProps) {
Expand Down
84 changes: 42 additions & 42 deletions src/components/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,52 +34,52 @@ export class Editor extends Component {
onSelectionChange: PropTypes.func
};

async componentDidMount() {
const quillModule = await import('quill');
componentDidMount() {
import('quill').then((module) => {
if (module && module.default) {
this.quill = new module.default(this.editorElement, {
modules: {
toolbar: this.toolbarElement,
...this.props.modules
},
placeholder: this.props.placeholder,
readOnly: this.props.readOnly,
theme: this.props.theme,
formats: this.props.formats
});

if (quillModule && quillModule.default) {
this.quill = new quillModule.default(this.editorElement, {
modules: {
toolbar: this.toolbarElement,
...this.props.modules
},
placeholder: this.props.placeholder,
readOnly: this.props.readOnly,
theme: this.props.theme,
formats: this.props.formats
});

if (this.props.value) {
this.quill.pasteHTML(this.props.value);
}

this.quill.on('text-change', (delta, source) => {
let html = this.editorElement.children[0].innerHTML;
let text = this.quill.getText();
if (html === '<p><br></p>') {
html = null;
if (this.props.value) {
this.quill.pasteHTML(this.props.value);
}

if (this.props.onTextChange) {
this.props.onTextChange({
htmlValue: html,
textValue: text,
delta: delta,
source: source
});
}
});
this.quill.on('text-change', (delta, source) => {
let html = this.editorElement.children[0].innerHTML;
let text = this.quill.getText();
if (html === '<p><br></p>') {
html = null;
}

this.quill.on('selection-change', (range, oldRange, source) => {
if(this.props.onSelectionChange) {
this.props.onSelectionChange({
range: range,
oldRange: oldRange,
source: source
});
}
});
}
if (this.props.onTextChange) {
this.props.onTextChange({
htmlValue: html,
textValue: text,
delta: delta,
source: source
});
}
});

this.quill.on('selection-change', (range, oldRange, source) => {
if(this.props.onSelectionChange) {
this.props.onSelectionChange({
range: range,
oldRange: oldRange,
source: source
});
}
});
}
});
}

componentDidUpdate(prevProps) {
Expand Down
20 changes: 10 additions & 10 deletions src/components/fullcalendar/FullCalendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@ export class FullCalendar extends Component {
}
}

async initialize() {
const fullCalendarModule = await import('@fullcalendar/core');
initialize() {
import('@fullcalendar/core').then((module) => {
if (module && module.Calendar) {
this.calendar = new module.Calendar(this.element, this.config);
this.calendar.render();

if (fullCalendarModule && fullCalendarModule.Calendar) {
this.calendar = new fullCalendarModule.Calendar(this.element, this.config);
this.calendar.render();

if (this.props.events) {
this.calendar.removeAllEventSources();
this.calendar.addEventSource(this.props.events);
if (this.props.events) {
this.calendar.removeAllEventSources();
this.calendar.addEventSource(this.props.events);
}
}
}
});
}

componentWillUnmount() {
Expand Down

0 comments on commit c6b1c58

Please sign in to comment.