Define default value for config object (#441)

* define default value for config object

* bump version

* redefine onReady function
This commit is contained in:
Taly 2018-09-03 18:54:37 +03:00 committed by GitHub
parent f2f8bc0851
commit 314cc6de24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 34 deletions

View file

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

View file

@ -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": {

View file

@ -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(() => {

View file

@ -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);
});
}