blocking project loading for engines

This commit is contained in:
Val Erastov 2018-04-29 22:58:36 -07:00
parent d8e3a0a51b
commit 847f9d12a5
3 changed files with 38 additions and 2 deletions

View file

@ -24,12 +24,23 @@ export function activate({services}) {
engine.handler = handler;
console.info(`engine "${id}" is ready`);
}
services.lifecycle.loadProjectRequest();
}
function allEnginesReady() {
for (let e of engines) {
if (e.handler === NO_OP_HANDLER) {
return false;
}
}
return true;
}
services.craftEngines = {
registerEngine,
getRegisteredEngines: () => engines,
engineReady
engineReady,
allEnginesReady
};
engines.forEach(e => e.handler = NO_OP_HANDLER);
@ -37,6 +48,8 @@ export function activate({services}) {
}
function startEngine({id, url}) {
console.info(`starting engine "${id}"...`);
let engineScript = document.createElement('script');
engineScript.setAttribute('src', url);
document.head.appendChild(engineScript);

View file

@ -0,0 +1,20 @@
import {createToken} from '../../../../modules/bus';
export function activate({bus, services}) {
const startTime = performance.now();
bus.enableState(APP_READY_TOKEN, false);
bus.enableState(APP_PROJECT_LOADED, false);
services.lifecycle = {
loadProjectRequest: () => {
if (bus.state[APP_READY_TOKEN] && !bus.state[APP_PROJECT_LOADED] && services.craftEngines.allEnginesReady()) {
services.project.load();
bus.dispatch(APP_PROJECT_LOADED, true);
const onLoadTime = performance.now();
console.log("project loaded, took: " + ((onLoadTime - startTime) / 1000).toFixed(2) + ' sec');
}
}
}
}
export const APP_READY_TOKEN = createToken('app', 'ready');
export const APP_PROJECT_LOADED = createToken('app', 'projectLoaded');

View file

@ -1,4 +1,5 @@
import Bus from 'bus';
import * as LifecyclePlugin from './lifecyclePlugin';
import * as AppTabsPlugin from '../dom/appTabsPlugin';
import * as DomPlugin from '../dom/domPlugin';
import * as PickControlPlugin from '../scene/controls/pickControlPlugin';
@ -22,12 +23,14 @@ import * as tpiPlugin from '../tpi/tpiPlugin';
import * as PartModellerPlugin from '../part/partModellerPlugin';
import startReact from "../dom/startReact";
import {APP_READY_TOKEN} from './lifecyclePlugin';
export default function startApplication(callback) {
let applicationPlugins = [PartModellerPlugin];
let preUIPlugins = [
LifecyclePlugin,
ProjectPlugin,
StoragePlugin,
AppTabsPlugin,
@ -61,7 +64,7 @@ export default function startApplication(callback) {
startReact(context, () => {
activatePlugins(plugins, context);
context.services.project.load();
context.bus.dispatch(APP_READY_TOKEN, true);
context.services.viewer.render();
callback(context);
});