仅使用与先前嵌套键不匹配的新数据更新不可变列表?

Update Immutable List with only new data that doesn't match prior nested keys?

我有一个 immutableJS 列表,只有当新数据的 location.name 与我先前数据的 location.name.

不匹配时,我才想附加到该列表

我以这种格式将初始数据放入列表(新数据采用相同的格式,一个对象数组):

[  
  {  
    "location": {  
      "name":"A String"
    }
  },
  {  
    "location": {  
      "name":"A String 2"
    }
  }
]

但是,只有当位置名称与该州已存在的任何先前位置名称不匹配时,我才想将任何后续数据附加到此对象数组。

目前我正在返回状态,但这种方法有很多重复。

case RECEIVE_LOCATIONS:
  return state
    .set('stores', state.get('stores').update(fromJS(action.locations)))

您可以过滤掉重复的位置项

case RECEIVE_LOCATIONS:  {
  const newLocations = fromJS(action.locations).filter((newItem) => (
    !state.get('stores').find((oldItem) => (
      oldItem.location.name === newItem.location.name
    )
  );

  return state.set('stores', state.get('stores').update(newLocations));
}