Skip to content

Commit

Permalink
implement isInitialized flag
Browse files Browse the repository at this point in the history
  • Loading branch information
suren-atoyan committed Apr 23, 2022
1 parent 2474628 commit eb0a6b1
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/loader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import makeCancelable from '../utils/makeCancelable';
/** the local state of the module */
const [getState, setState] = state.create({
config: defaultConfig,
isInitialized: false,
resolve: null,
reject: null,
monaco: null,
Expand All @@ -43,9 +44,15 @@ function config(globalConfig) {
* @return {Promise} - returns an instance of monaco (with a cancelable promise)
*/
function init() {
const state = getState(({ monaco }) => ({ monaco }));
const state = getState(({ monaco, isInitialized }) => ({ monaco, isInitialized }));

if (!state.isInitialized) {
setState({ isInitialized: true });

if (state.monaco) {
return makeCancelable(Promise.resolve(state.monaco));
}

if (!state.monaco) {
if (window.monaco && window.monaco.editor) {
storeMonacoInstance(window.monaco);
return makeCancelable(Promise.resolve(window.monaco));
Expand All @@ -55,8 +62,6 @@ function init() {
injectScripts,
getMonacoLoaderScript,
)(configureLoader);
} else if (state.monaco) {
return makeCancelable(Promise.resolve(state.monaco));
}

return makeCancelable(wrapperPromise);
Expand Down

0 comments on commit eb0a6b1

Please sign in to comment.