Skip to content

Instantly share code, notes, and snippets.

@0xch4z
Last active June 1, 2018 14:34
Show Gist options
  • Select an option

  • Save 0xch4z/3c733f1d97c4ff996c33c8ad42270273 to your computer and use it in GitHub Desktop.

Select an option

Save 0xch4z/3c733f1d97c4ff996c33c8ad42270273 to your computer and use it in GitHub Desktop.

plain object with variant data

const variants = [
	{
	  name: 'california_only',
	  bannerImageUri: '/beach.jpg',
	  bannerHeadline: 'Wooo Califronia!!!'
	},
	{
	  name: 'north_carolina_only',
	  bannerImageUri: '/pine_tree.jpg',
	  bannerHeadline: 'Wooo Carolina!!!'
	}
];

const markupTemplate = ({ bannerImageUri, bannerHeadline }) =>   `
	<div id="bbLocalizedOffer">
		<img src="${bannerImageUri}" />
		<h1>${bannerHeadline}</h1>
	</div>
`;

// if you only need one variant's markup
const ncMarkup = markupTemplate(
	  variants.find({ name: 'north_carolina_only' })
);

// if you need all the markup in an array
const allVariantMarkup = variants.map(markupTemplate);

// if you need all the markup in an object instance
const variantMarkupMap = variants
	  .map(variant => ({
	  	[variant.name]: markupTemplate(variant)
	  }))
	  .reduce((acc, curr) => Object.assign(acc, curr), {});
// => { california_only: ..., north_carolina_only: ... }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment