Skip to content

Instantly share code, notes, and snippets.

@bkeating bkeating/merge.js
Created Sep 1, 2017

Embed
What would you like to do?
// This works... (returns a merged object)
const combinedFormSchema = this.state.session && _.merge(
this.state.session.building_list[0].schema,
this.state.session.building_list[1].schema
);
// This does not (returns an array of objects, not a merged object)
const combinedFormSchema = this.state.session && _.merge(
_.map(this.state.session.building_list, building => building.schema)
);
@bkeating

This comment has been minimized.

Copy link
Owner Author

commented Sep 1, 2017

It's because the _.map approach above is only citing 1 argument. By spreading the mapped results out, we give merge the right argument shape:

const buildingUiSchemas = this.state.session && _.map(
  this.state.session.building_list, building => building.uischema
);
const combinedFormUiSchema = this.state.session && _.merge(...buildingUiSchemas);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.