<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rob Fyffe</title>
    <description>The latest articles on DEV Community by Rob Fyffe (@robertfyffe).</description>
    <link>https://dev.to/robertfyffe</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F646208%2F66c85df5-54e0-4d18-9161-421d603b1766.jpeg</url>
      <title>DEV Community: Rob Fyffe</title>
      <link>https://dev.to/robertfyffe</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/robertfyffe"/>
    <language>en</language>
    <item>
      <title>Architecture To Support Multiple Markets &amp; Flows</title>
      <dc:creator>Rob Fyffe</dc:creator>
      <pubDate>Tue, 08 Jun 2021 22:56:01 +0000</pubDate>
      <link>https://dev.to/robertfyffe/architecture-to-support-multiple-markets-flows-3ah2</link>
      <guid>https://dev.to/robertfyffe/architecture-to-support-multiple-markets-flows-3ah2</guid>
      <description>&lt;p&gt;Looking to get some opinions/suggestions on how to manage or improve an application that supports multiple markets and flows. As an example we can use a form. There is one base form that can potentially be different per flow &amp;amp; market.&lt;/p&gt;

&lt;p&gt;Current architecture is along these lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const ExampleTopLevel = ({ customSlots = {}, ...props }) =&amp;gt; {
  const newSlots = {
    ...exampleSlot1(),
    ...exampleSlot2(),
    ...exampleSlot3(),
    ...exampleSlot4(),
  };

  const combinedSlots = { ...customSlots, ...newSlots };

  switch (condition) {
    case "BRAND":
      return &amp;lt;ExampleBrandSecondLevel customSlots={combinedSlots} {...props} /&amp;gt;;
    default:
      return combinedSlots;
  }
};

const ExampleBrandSecondLevel = ({ customSlots, ...props }) =&amp;gt; {
  const newSlots = {};
  const combinedSlots = { ...customSlots, ...newSlots };

  switch (condition) {
    case "FLOW_1":
      return &amp;lt;ComponentFlow1 customSlots={combinedSlots} {...props} /&amp;gt;;
    default:
      return combinedSlots;
  }
};

const ComponentFlow1 = ({ customSlots = {}, ...props }) =&amp;gt; {
  const newSlots = {};
  const combinedSlots = { ...customSlots, ...newSlots };

  switch (config.market) {
    case "MARKET_1":
      return &amp;lt;ExampleMarket1 customSlots={combinedSlots} {...props} /&amp;gt;;
    default:
      return combinedSlots;
  }
};

const ExampleMarket1 = ({ customSlots = {} }) =&amp;gt; {
  const newSlots = {
    ...exampleSlot1({ readOnly: true }), // Overwrite top level
    ...newSlot1({
      inputRef: null,
    }),
  };

  const combinedSlots = { ...customSlots, ...newSlots };

  return combinedSlots;
};

// Final Result for Flow_1 &amp;amp; Market_1:
const slots = {
  ...exampleSlot1({ readOnly: true }),
  ...exampleSlot2(),
  ...exampleSlot3(),
  ...exampleSlot4(),
  ...newSlot1({
    inputRef: null,
  }),
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This works, however it is causing a lot of duplicate code as this is the same scaffolding for all components across the application. &lt;/p&gt;

&lt;p&gt;I have thought about a schema approach but that becomes difficult to read when there are 15+ slots with different customisations such as labels, onClicks etc. etc.&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
  </channel>
</rss>
