-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
/
render.js
35 lines (30 loc) · 971 Bytes
/
render.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { document } from 'global';
import { stripIndents } from 'common-tags';
const rootEl = document.getElementById('root');
let currLoadedComponent = null; // currently loaded marko widget!
export default function renderMain({
storyFn,
selectedKind,
selectedStory,
showMain,
showError,
// forceRender,
}) {
const element = storyFn();
// We need to unmount the existing set of components in the DOM node.
if (currLoadedComponent) {
currLoadedComponent.destroy();
}
if (!element || !element.out) {
showError({
title: `Expecting a Marko element from the story: "${selectedStory}" of "${selectedKind}".`,
description: stripIndents`
Did you forget to return the Marko element from the story?
Use "() => MyComp.renderSync({})" or "() => { return MyComp.renderSync({}); }" when defining the story.
`,
});
return;
}
showMain();
currLoadedComponent = element.appendTo(rootEl).getComponent();
}