/テスト用にマージする良い方法:、我々はこれを現在は深い更新lodashとES6内のオブジェクトまたは深い更新する方法を探して他のライブラリ
をやっている:
{
..._companies,
['c124']: {
..._companies.c124,
['fields']: {
..._companies.c124.fields,
['f4']: {
..._companies.c124.fields.f4,
value: 'white'
}
}
}
理想的に我々はこれを行うだろうというとき:それは完全にC124キーを置き換えるよう
update_merge(_companies, {
c124: {
fields: {
f4: {
value:'white'
}
}
}
})
シンプル深いマージは、この場合には動作しません。
元_companiesはスニペット:
const companies = {
c123: {
id: 123,
name: 'Company one',
fields: {...} // fields
},
c124: {
id: 124,
name: 'Company two',
fields: {
f1: {...}, //...fields
f2: {...}, //...fields
f3: {...}, //...fields
f4: {
id: 4,
fieldType: "shortText",longText
title: "favorite color",
value: 'green', // <==== only this will change
},
},
}
}
この期待される結果:我々はimmutability-helperを使用している私たちのプロジェクトで
const companies = {
c123: {
id: 123,
name: 'Company one',
fields: {...} // fields
},
c124: {
id: 124,
name: 'Company two',
fields: {
f1: {...}, //...fields
f2: {...}, //...fields
f3: {...}, //...fields
f4: {
id: 4,
fieldType: "shortText",longText
title: "favorite color",
value: 'white', // <==== this changed
},
},
}
}
元の「企業」オブジェクトを追加しますか? –
...と予想される結果です。 –
@OriDroriリクエストに応じて追加 – Guy