Skip to content

Commit

Permalink
Define default value for config object (codex-team#441)
Browse files Browse the repository at this point in the history
* define default value for config object

* bump version

* redefine onReady function
  • Loading branch information
talyguryn authored Sep 3, 2018
1 parent f2f8bc0 commit 314cc6d
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 34 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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!

Expand Down
46 changes: 23 additions & 23 deletions build/codex-editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/codex-editor.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
24 changes: 17 additions & 7 deletions src/codex.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

onReady = onReady && typeof onReady === 'function' ? onReady : () => {};
constructor(configuration = {}) {
/**
* Set default onReady function
*/
let 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(() => {
Expand Down
8 changes: 7 additions & 1 deletion src/components/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down

0 comments on commit 314cc6d

Please sign in to comment.