Browse Source

Update loadOnStart for headless

pull/4282/head
Artur Arseniev 4 years ago
parent
commit
e115a8bf2f
  1. 8
      src/dom_components/index.js
  2. 40
      src/editor/model/Editor.ts

8
src/dom_components/index.js

@ -278,7 +278,13 @@ export default () => {
load(data) {
return this.loadProjectData(data, {
onResult: result => {
const wrapper = this.getWrapper();
let wrapper = this.getWrapper();
if (!wrapper) {
this.em.get('PageManager').add({}, { select: true });
wrapper = this.getWrapper();
}
if (isArray(result)) {
result.length && wrapper.components(result);
} else {

40
src/editor/model/Editor.ts

@ -83,15 +83,15 @@ timedInterval?: number;
get storables(): any[]{
return this.get("storables")
return this.get('storables')
}
get modules(): IModule[]{
return this.get("modules")
return this.get('modules')
}
get toLoad(): any[]{
return this.get("toLoad")
return this.get('toLoad')
}
constructor(conf = {}) {
@ -178,6 +178,9 @@ timedInterval?: number;
* @private
*/
loadOnStart() {
const { projectData, headless } = this.config;
const sm = this.get('StorageManager');
// In `onLoad`, the module will try to load the data from its configurations.
this.toLoad.forEach(mdl => mdl.onLoad());
@ -187,21 +190,24 @@ timedInterval?: number;
this.set('readyLoad', 1);
};
// Defer for storage load events.
setTimeout(async () => {
const projectData = this.getConfig().projectData;
if (projectData) {
this.loadData(projectData);
} else if (this.get('StorageManager').canAutoload()) {
try {
await this.load();
} catch (error) {
this.logError(error as string);
}
}
if (headless) {
projectData && this.loadData(projectData);
postLoad();
});
} else {
// Defer for storage load events.
setTimeout(async () => {
if (projectData) {
this.loadData(projectData);
} else if (sm?.canAutoload()) {
try {
await this.load();
} catch (error) {
this.logError(error as string);
}
}
postLoad();
});
}
// Create shallow editor.
// Here we can create components/styles without altering/triggering the main EditorModel

Loading…
Cancel
Save