1

I was reading through the source of todoapp-flux example, and in TodoStore.js I saw this:

function update(id, updates) {
  // original
  // _todos[id] = merge(_todos[id], updates);

  // my version
    _todos[id].complete = updates.complete;
}

I was wondering why facebook choose to merge two object, instead of just change the value of one property? Is there any benefit doing so?

4

1 回答 1

3

更新可用于更新完整以外的属性。例如在第 161 行,文本被更新。

update(action.id, {text: text});

这将更新文本,而不更改完整。使用您的版本,上述内容不会更改文本,并且会将 complete 设置为 undefined。

于 2014-05-23T00:36:18.510 回答