app/marko/src/client/preview/render.js
// template for the currently loaded component.
template for the currently loaded component.
template for the currently loaded component .
function renderMain({
  storyFn,
  selectedKind,
  selectedStory,
  showMain,
  showError,
  parameters,
}) {
  const config = storyFn();
  if (!config || !(config.appendTo || config.component || parameters.component)) {
    showError({
      title: `Expecting an object with a component property to be returned from the story: "${selectedStory}" of "${selectedKind}".`,
      description: dedent`
        Did you forget to return the component from the story?
        Use "() => ({ component: MyComponent, input: { hello: 'world' } })" when defining the story.
      `,
    });
    return;
  }
  if (config.appendTo) {
    logger.warn(
      '@storybook/marko: returning a rendered component for a story is deprecated, return an object with `{ component, input }` instead.'
    );
    if (activeComponent) {
      activeComponent.destroy();
    }
    activeComponent = config.appendTo(rootEl).getComponent();
  } else {
    const template = config.component || parameters.component;
    if (activeTemplate === template) {
      activeComponent.input = config.input;
      activeComponent.update();
    } else {
      if (activeComponent) {
        activeComponent.destroy();
      }
      activeTemplate = template;
      activeComponent = activeTemplate
        .renderSync(config.input)
        .appendTo(rootEl)
        .getComponent();
    }
  }
  showMain();
}
function renderMain ( { storyFn , selectedKind , selectedStory , showMain , showError , parameters , } ) { const config = storyFn ( ) ; if ( ! config || ! ( config . appendTo || config . component || parameters . component ) ) { showError ( { title : ` ${ selectedStory } ${ selectedKind } ` , description : dedent ` ` , } ) ; return ; } if ( config . appendTo ) { logger . warn ( '@storybook/marko: returning a rendered component for a story is deprecated, return an object with `{ component, input }` instead.' ) ; if ( activeComponent ) { activeComponent . destroy ( ) ; } activeComponent = config . appendTo ( rootEl ) . getComponent ( ) ; } else { const template = config . component || parameters . component ; if ( activeTemplate === template ) { activeComponent . input = config . input ; activeComponent . update ( ) ; } else { if ( activeComponent ) { activeComponent . destroy ( ) ; } activeTemplate = template ; activeComponent = activeTemplate . renderSync ( config . input ) . appendTo ( rootEl ) . getComponent ( ) ; } } showMain ( ) ; }
template for the currently loaded component.
template for the currently loaded component .
// forceRender, // The deprecated API always destroys the previous component instance. // When rendering the same template with new input, we reuse the same instance.