Created
September 29, 2016 19:33
-
-
Save kwelch/eadbf369d6fae7a983de87782ec712d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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