Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON Preprocess function for things like nested props #71

Merged
merged 7 commits into from
Dec 16, 2016

Conversation

micahgodbolt
Copy link
Contributor

Still need to write up tests/docs, but wanted to make sure the placement and name of this function works for you. I was able to get my nested props function working just fine with this.

      jsonPreProcess: function (json) {
        let resolveNestedProps = function (props, parent = "") {
          let flatProps = {};
          _.forEach(props, (value, key) => {
            if (typeof value !== 'string') {
              let propName = (parent === "" ? "" : parent + "_") + key
              flatProps = Object.assign(flatProps, resolveNestedProps(value, propName))
              flatProps[propName] = value
            }
          })
          return flatProps;
        }
        json.props = resolveNestedProps(json.props);
        return json;
      }

Might consider dropping this into a small NPM module if others would like to easily use it.

@micahgodbolt micahgodbolt changed the title Init commit of json preprocess option JSON Preprocess function for things like nested props Dec 15, 2016
.pipe(theo.plugins.transform('web', { includeRawValue: true }))
.pipe(theo.plugins.transform('web', {
includeRawValue: true,
jsonPreProcess: function (json) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we could use a fat arrow function? We're using ES6 throughout the examples so it might make sense to be consistent.

jsonPreProcess: (json) => {

@kaelig
Copy link
Contributor

kaelig commented Dec 15, 2016

This is brilliant, thanks a lot!! I just had one comment and we're good to go

@kaelig kaelig merged commit d11081c into salesforce-ux:master Dec 16, 2016
@micahgodbolt
Copy link
Contributor Author

micahgodbolt commented Dec 16, 2016

Forgot that this closes issues #64

@kaelig kaelig modified the milestone: v5.0.0 Dec 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants