Skip to content

Instantly share code, notes, and snippets.

@kwelch
Created September 29, 2016 19:33
Show Gist options
  • Save kwelch/eadbf369d6fae7a983de87782ec712d2 to your computer and use it in GitHub Desktop.
Save kwelch/eadbf369d6fae7a983de87782ec712d2 to your computer and use it in GitHub Desktop.
const runDynamicFieldProperties = (field, excludeProps = []) => (
Object.keys(field).reduce((acc, curr) => {
const currVal = field[curr];
const isFunc = (typeof currVal === 'function');
const isExcluded = excludeProps.some(key => key === curr);
const isMatch = isFunc && !isExcluded;
return Object.assign({}, acc, {
[curr]: isMatch ?
currVal({
data: acc,
})
: currVal,
});
}, field) // start with the base field and overwrite fields as we process them
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment