2018-01-12 11:49:45 +00:00
|
|
|
/**
|
|
|
|
* @flow
|
|
|
|
*/
|
|
|
|
|
|
|
|
const buildFieldPathData = (segments: string[], value: any): Object => {
|
|
|
|
if (segments.length === 1) {
|
|
|
|
return {
|
|
|
|
[segments[0]]: value,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
[segments[0]]: buildFieldPathData(segments.slice(1), value),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-01-25 18:25:39 +00:00
|
|
|
// eslint-disable-next-line import/prefer-default-export
|
|
|
|
export const mergeFieldPathData = (
|
|
|
|
data: Object,
|
|
|
|
segments: string[],
|
|
|
|
value: any
|
|
|
|
): Object => {
|
2018-01-12 11:49:45 +00:00
|
|
|
if (segments.length === 1) {
|
|
|
|
return {
|
|
|
|
...data,
|
|
|
|
[segments[0]]: value,
|
|
|
|
};
|
|
|
|
} else if (data[segments[0]]) {
|
|
|
|
return {
|
|
|
|
...data,
|
2018-01-25 18:25:39 +00:00
|
|
|
[segments[0]]: mergeFieldPathData(
|
|
|
|
data[segments[0]],
|
|
|
|
segments.slice(1),
|
|
|
|
value
|
|
|
|
),
|
2018-01-12 11:49:45 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
...data,
|
|
|
|
[segments[0]]: buildFieldPathData(segments.slice(1), value),
|
|
|
|
};
|
|
|
|
};
|