Skip to content
Snippets Groups Projects
Commit 90be9b8d authored by chris's avatar chris
Browse files

boot services only once

parent e9761678
No related branches found
No related tags found
1 merge request!298Multiple configs
......@@ -5,6 +5,7 @@ import { Wax } from 'wax-prosemirror-core';
import { EditoriaLayout, EditoriaMobileLayout } from './layout';
import { config, configMobile } from './config';
import { demo } from './demo';
import HHMI from '../HHMI/HHMI';
const renderImage = file => {
const reader = new FileReader();
......
......@@ -13,25 +13,28 @@ export default class Application {
registerServices() {
let count = 0;
while (count < this.config.get('config.services').length) {
const allServices = this.config.get('config.services');
const service = this.config.get('config.services')[count];
/*
console.log(this.config);
if (this.config) {
while (count < this.config.get('config.services').length) {
const allServices = this.config.get('config.services');
const service = this.config.get('config.services')[count];
/*
set App to every service
so services can have access to containers and config
*/
service.setApp(this);
service.setApp(this);
if (service.dependencies) {
const servicePos = count;
allServices.splice(servicePos + 1, 0, ...service.dependencies);
}
if (service.dependencies) {
const servicePos = count;
allServices.splice(servicePos + 1, 0, ...service.dependencies);
}
if (service.register) {
service.register();
}
if (service.register) {
service.register();
}
count += 1;
count += 1;
}
}
}
......
......@@ -4,6 +4,7 @@ import React, {
useCallback,
useMemo,
useEffect,
useState,
} from 'react';
import applyDevTools from 'prosemirror-dev-tools';
......@@ -21,11 +22,12 @@ import WaxOptions from './WaxOptions';
const WaxPortals = ComponentPlugin('waxPortals');
let previousDoc;
let view;
export default props => {
const { readonly, onBlur, debug, autoFocus, user, targetFormat } = props;
const editorRef = useRef();
let view;
const [mounted, setMounted] = useState(false);
const context = useContext(WaxContext);
const { createPortal } = useContext(PortalContext);
......@@ -33,7 +35,7 @@ export default props => {
const schema = context.app.getSchema();
if (!view) {
if (!mounted) {
context.app.bootServices();
}
......@@ -78,6 +80,8 @@ export default props => {
},
);
setMounted(true);
context.updateView(
{
main: view,
......
......@@ -9,16 +9,23 @@ export default class ShortCutsService extends Service {
shortCuts.createShortCuts();
}
// TODO start ShortCuts as Schema is initiated
register() {
const { PmPlugins } = this.app;
this.container
.bind('ShortCuts')
.toDynamicValue(() => {
const {
schema: { schema },
} = this.app;
if (this.app.schema) {
return new ShortCuts(
PmPlugins,
this.container.get('Schema').getSchema(),
);
}
return new ShortCuts(PmPlugins, schema);
return new ShortCuts(
PmPlugins,
this.container.get('Schema').getSchema(),
);
})
.inSingletonScope();
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment