All files / src index.js

50% Statements 5/10
0% Branches 0/4
50% Functions 2/4
50% Lines 5/10
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 36 37 38 39 40 41 42 43 44 45              1x                     1x         1x               1x             1x            
import ReactQuerystringRouter from 'react-querystring-router';
import ComponentPlayground from 'react-component-playground';
import { loadComponents, loadFixtures } from './load-modules';
import createLinkedList from './linked-list';
import PreviewLoader from './proxies/PreviewLoader';
import createStateProxy from './proxies/StateProxy';
 
const getTitleForFixture = (params) => {
  let title = 'React Cosmos';
 
  // Set document title to the name of the selected fixture
  if (params.component && params.fixture) {
    title = `${params.component}:${params.fixture} – ${title}`;
  }
 
  return title;
};
 
module.exports = ({
  proxies,
  components,
  fixtures,
}) => {
  const firstProxy = createLinkedList([
    ...proxies,
    // Loaded by default in all configs
    createStateProxy(),
    // The final proxy in the chain simply renders the preview component
    PreviewLoader,
  ]);
 
  return new ReactQuerystringRouter.Router({
    container: document.body.appendChild(document.createElement('div')),
    defaultProps: {
      firstProxy,
      components: loadComponents(components),
      fixtures: loadFixtures(fixtures),
    },
    getComponentClass: () => ComponentPlayground,
    onChange: (params) => {
      document.title = getTitleForFixture(params);
    },
  });
};