mirror of
https://github.com/codex-team/editor.js
synced 2024-06-10 09:52:36 +02:00
Define default value for config object (#441)
* define default value for config object * bump version * redefine onReady function
This commit is contained in:
parent
f2f8bc0851
commit
314cc6de24
|
@ -1,6 +1,6 @@
|
|||
<p align="center"><img src="https://capella.pics/3c0b525b-50d9-4720-8aad-9148114cfa6e.jpg"></p>
|
||||
|
||||
![](https://flat.badgen.net/badge/CodeX%20Editor/v2.0.3/blue?icon=npm)
|
||||
![](https://flat.badgen.net/badge/CodeX%20Editor/v2.0.8/blue?icon=npm)
|
||||
|
||||
## Version 2.0-beta is here!
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "codex.editor",
|
||||
"version": "2.0.7",
|
||||
"version": "2.0.8",
|
||||
"description": "Codex Editor. Native JS, based on API and Open Source",
|
||||
"main": "build/codex-editor.js",
|
||||
"scripts": {
|
||||
|
|
24
src/codex.js
24
src/codex.js
|
@ -25,19 +25,29 @@ export default class CodexEditor {
|
|||
/**
|
||||
* @constructor
|
||||
*
|
||||
* @param {EditorConfig} configuration - user configuration
|
||||
* @param {EditorConfig|Object} configuration - user configuration
|
||||
*/
|
||||
constructor(configuration) {
|
||||
let {onReady} = configuration;
|
||||
constructor(configuration = {}) {
|
||||
/**
|
||||
* Set default onReady function
|
||||
*/
|
||||
let onReady = () => {};
|
||||
|
||||
onReady = onReady && typeof onReady === 'function' ? onReady : () => {};
|
||||
|
||||
configuration.onReady = () => {};
|
||||
/**
|
||||
* If `onReady` was passed in `configuration` then redefine onReady function
|
||||
*/
|
||||
if (typeof configuration === 'object' && typeof configuration.onReady === 'function') {
|
||||
onReady = configuration.onReady;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a CodeX Editor instance
|
||||
*/
|
||||
const editor = new Core(configuration);
|
||||
|
||||
/**
|
||||
* We need to export isReady promise in the constructor as it can be used before other API methods are exported
|
||||
* We need to export isReady promise in the constructor
|
||||
* as it can be used before other API methods are exported
|
||||
* @type {Promise<any | never>}
|
||||
*/
|
||||
this.isReady = editor.isReady.then(() => {
|
||||
|
|
|
@ -72,12 +72,18 @@ export default class Core {
|
|||
_.log('I\'m ready! (ノ◕ヮ◕)ノ*:・゚✧');
|
||||
|
||||
setTimeout(() => {
|
||||
this.config.onReady.call();
|
||||
/**
|
||||
* Resolve this.isReady promise
|
||||
*/
|
||||
onReady();
|
||||
}, 500);
|
||||
})
|
||||
.catch(error => {
|
||||
_.log(`CodeX Editor does not ready because of ${error}`, 'error');
|
||||
|
||||
/**
|
||||
* Reject this.isReady promise
|
||||
*/
|
||||
onFail(error);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue