Slide 11
Slide 11 text
Command pattern
const creatives = ['cr1', 'cr2', 'cr3'];
function SingleSelectionCommand() {
const idx = Math.floor(
Math.random() * creatives.length);
return creatives[idx];
}
function MultipleSelectionCommand(props) {
const selected = new Set();
for (let i = 0; i < props.count; i++) {
selected.add(SingleSelectionCommand());
}
return Array.from(selected);
}
/** define command executor */
function CreativeSelector(props) {}
CreativeSelector.prototype.execute = function(
command,
props,
) {
return command(props);
}
/** execute commands */
const selector = new CreativeSelector();
const single = selector.execute(SingleSelectionCommand, {});
const multi = selector.execute(MultipleSelectionCommand, {
count: 2,
});