Skip to content

Commit

Permalink
feat: support setting Marko template as a shared parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Jul 17, 2019
1 parent 7a82da8 commit 6a428af
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
31 changes: 18 additions & 13 deletions app/marko/src/client/preview/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ export default function renderMain({
selectedStory,
showMain,
showError,
parameters,
// forceRender,
}) {
const config = storyFn();

if (!config || !(config.appendTo || config.template)) {
if (!config || !(config.appendTo || config.template || parameters.template)) {
showError({
title: `Expecting an object with a template property to be returned from the story: "${selectedStory}" of "${selectedKind}".`,
description: stripIndents`
Expand All @@ -37,20 +38,24 @@ export default function renderMain({
}

activeComponent = config.appendTo(rootEl).getComponent();
} else if (activeTemplate === config.template) {
// When rendering the same template with new input, we reuse the same instance.
activeComponent.input = config.input;
activeComponent.update();
} else {
if (activeComponent) {
activeComponent.destroy();
const template = config.template || parameters.template;

if (activeTemplate === template) {
// When rendering the same template with new input, we reuse the same instance.
activeComponent.input = config.input;
activeComponent.update();
} else {
if (activeComponent) {
activeComponent.destroy();
}

activeTemplate = template;
activeComponent = activeTemplate
.renderSync(config.input)
.appendTo(rootEl)
.getComponent();
}

activeTemplate = config.template;
activeComponent = activeTemplate
.renderSync(config.input)
.appendTo(rootEl)
.getComponent();
}

showMain();
Expand Down
2 changes: 1 addition & 1 deletion examples/marko-cli/src/stories/addon-knobs.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ export default {
title: 'Addons|Knobs/Hello',
decorators: [withKnobs],
parameters: {
template: Hello,
options: { panelPosition: 'right' },
},
};

export const Simple = () => ({
template: Hello,
input: {
name: text('Name', 'John Doe'),
age: number('Age', 44),
Expand Down

0 comments on commit 6a428af

Please sign in to comment.