按键,嵌套状态保存到redux存储

时间:2018-06-18 14:27:24

标签: javascript react-native redux

聊天应用

我想为每个会话ID保存不同的ChatMessages数组。

我想象州会看起来像这样:

def get_data_from_bq(product_ids):
    format_strings = ','.join([("\"" + str(_id) + "\"") for _id in product_ids])
    query = "select productId, eventType, count(*) as count from [xyz:xyz.abc] where productId in (" + format_strings + ") and eventTime > CAST(\"" + time_thresh +"\" as DATETIME) group by eventType, productId order by productId;"
    query_job = bigquery_client.query(query, job_config=QueryJobConfig())
    return query_job.result()

但我似乎无法保存嵌套状态,是否可能?

我的代码:(因为这行不能运行:chatMessage [conversationId]:payload.chatMessages)

state {
  messages: {
   isRequesting: false,
   messageByConversationId: {
    "23523534543": [messages],
    "64634523453": [messages],
   }
 }
}

1 个答案:

答案 0 :(得分:0)

不确定我完全理解你的问题。但您可以执行以下操作将已加载的消息添加到messageByConversationId对象,同时保留其他已加载的消息。

NB。这假设您以某种方式获得conversationId作为变量。例如,您可以将其设为payload

的一部分
export const loadChatMessagesSuccess: Reducer<ImmutableChatMessagesState> = (
  state: ImmutableChatMessagesState,
  { payload }: AnyAction & { payload?: LoadChatMessagesSuccessParams }
) =>
  payload
    ? {
        ...state,
        requesting: false,
        messageByConversationId: {
          ...state.messageByConversationId,
          [payload.conversationId]: payload.chatMessages
        }
      }
    : state;