Ember Data的commitDetails的创建/更新/删除的OrderedSets集在哪里? [英] Where are Ember Data's commitDetails' created/updated/deleted OrderedSets set?

查看:71
本文介绍了Ember Data的commitDetails的创建/更新/删除的OrderedSets集在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ember Data的适配器将编辑的记录保存在 Ember.OrderedSets 的不同组中,即: commitDetails.created commitDetails.updated commitDetails.deleted

Ember Data's Adapter saves edited records in different groups of Ember.OrderedSets, namely: commitDetails.created, commitDetails.updated, and commitDetails.deleted.

model.save()来自模型控制器的 createRecord()将放置在 commitDetails.created 组中。来自模型控制器的 acceptChanges model.save()将放置在 commitDetails.updated 组。但是我找不到在代码中发生位置关联的地方。

model.save() from model controller's createRecord() will be placed in the commitDetails.created group. model.save() from model controller's acceptChanges will placed be in the commitDetails.updated group. But I can't find in code where the placement association happens.

我知道它们是已在Ember Transaction的实例中提交函数(该函数称为适配器的 commit ,依次调用Adapter的 保存 )。在整个过程中,我无法确定根据创建/更新/删除的条件对记录进行了精确排序。

I know that they are instantiated in Ember Transaction's commit function (which calls Adapter's commit, in turn calling Adapter's save). Throughout this process, I can't figure out where exactly the records are sorted according to the created/updated/deleted criteria.

推荐答案

我不清楚您要问的是什么,但是如果您要查找将记录添加到适当的 commitDetails 集中的位置,我相信是您要查找的行例如,在 commitDetails 属性本身中。

I'm not quite clear what you're asking, but if you're looking for where records get added to their appropriate commitDetails set, I believe this is the line you're looking for, in the commitDetails property itself.

以下是相关代码。

forEach(records, function(record) {
  if(!get(record, 'isDirty')) return;
  record.send('willCommit');
  var adapter = store.adapterForType(record.constructor);
  commitDetails.get(adapter)[get(record, 'dirtyType')].add(record);
});

我们来看看它。

forEach(records, function(record) {
  if(!get(record, 'isDirty')) return;

上面说,对于交易中的每条记录,如果记录不脏,则将其忽略。

The above says, for each record in the transaction, if it's not dirty, ignore it.

record.send('willCommit');

否则,更新其状态

var adapter = store.adapterForType(record.constructor);

获取记录的适配器。

commitDetails.get(adapter)

查找适配器的创建/更新/删除的三重对象,该对象在顶部实例化此方法的此处。它只是一个具有创建,更新和删除3个属性的对象,其val ues是空的OrderedSets。

Look up the adapter's created/updated/deleted trio object, which was instantiated at the top of this method here. It's simply an object with the 3 properties created, updated, and deleted, whose values are empty OrderedSets.

[get(record, 'dirtyType')]

从刚刚获得的对象中获取适当的OrderedSet。例如,如果我们所在的记录已更新,则 get(record,'dirtyType')将返回字符串 updated 。括号只是标准的JavaScript属性查找,因此在上一步中它将从我们的三重对象中获取更新的OrderedSet。

Get the appropriate OrderedSet from the object we just obtained. For example, if the record we're on has been updated, get(record, 'dirtyType') will return the string updated. The brackets are just standard JavaScript property lookup, and so it grabs the updated OrderedSet from our trio object in the previous step.

.add(record);

最后,将记录添加到OrderedSet中。在循环的后续迭代中,我们将添加相同类型的其他记录,以便将所有创建的记录添加到一个集合中,所有更新的记录添加到另一个集合中,所有已删除的记录添加到第三集合中。

Finally, add the record to the OrderedSet. On subsequent iterations of the loop, we'll add other records of the same type, so all created records get added to one set, all updated records get added to another set, and all deleted records get added to the third set.

在整个方法的最后,从属性返回的结果是一个Map,其键是适配器,其值是创建了3个属性的这些对象,更新和删除。依次,每个记录分别是为该适配器创建,为该适配器更新和为该适配器删除的事务中所有记录的OrderedSet。

What we end up with at the end of the entire method and return from the property is a Map whose keys are adapters, and whose values are these objects with the 3 properties created, updated, and deleted. Each of those, in turn, are OrderedSets of all the records in the transaction that have been created for that adapter, updated for that adapter, and deleted for that adapter, respectively.

请注意,此计算属性标记为 volatile ,因此,每当有人获得 commitDetails 属性时,它将重新计算该属性。

Notice that this computed property is marked volatile, so it will get recomputed each time that someone gets the commitDetails property.

这篇关于Ember Data的commitDetails的创建/更新/删除的OrderedSets集在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆