在Backbone.js的,为什么沉默变化引发更改事件最终? [英] In Backbone.js, why do silent changes trigger change events eventually?

查看:213
本文介绍了在Backbone.js的,为什么沉默变化引发更改事件最终?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我路过 {沉默:真正} 而在骨干模型设置一个属性,为什么不只是燮preSS的的变化:属性事件?什么是下一次的属性更改触发该事件的优势在哪里?

When I pass {"silent":true} while setting an attribute in a Backbone model, why doesn't that just suppress the change:attribute event? What is the advantage of firing that event the next time an attribute is changed?

更新

0.9.10骨干改变传递的行为 {沉默:真正} 。从更新日志:

Backbone 0.9.10 changed the behavior of passing { "silent": true }. From the changelog:

传递 {沉默:真正} 上的变化将不再拖延个人
  变化:ATTR事件,相反,他们是完全沉默

Passing {silent:true} on change will no longer delay individual "change:attr" events, instead they are silenced entirely.

这里浏览changelog的

Browse the changelog here

推荐答案

这混淆了我一段时间为好。

This has confused me for some time as well.

原因在于{沉默:真正}。做的不可以的意思是一切正常,但就是不触发事件

The reason is that {silent:true} does not mean "Do everything as normal, but just don't trigger the event".

从@jashkenas各种意见和答案,它似乎意味着是简单地改变属性值(并把它添加到changedAttributes哈希值),但延迟所有其他的更改相关的活动,直到后来的。

From various comments and answers by @jashkenas, what it seems to mean is "simply change the attribute value (and add it to the 'changedAttributes' hash), but defer all other "change-related" activities until later".

沉默没有的 prevent 的的变更事件为/这些属性,它只是排队的公告直到下一个变化时触发事件。

'silent' doesn't prevent the change event for that/those properties, it simply queues up the 'announcement' until the next change event is triggered.

因此​​,它可能是更好的名字类似延迟

So, its probably better named something like defer.

相关信息:

<一个href=\"https://github.com/documentcloud/backbone/pull/850\">https://github.com/documentcloud/backbone/pull/850

沉默变化的一点是,它不被认为是从视图的模型点的改变。后来,当变化实际发生,你得到充分的差别的一次。

the point of a "silent" change is that it isn't considered a change from the models point of view. Later, when the change actually occurs, you get the full difference all at once.

<一个href=\"https://github.com/documentcloud/backbone/issues/870\">https://github.com/documentcloud/backbone/issues/870

由于无声变化的一点是,你允许你的模型,暂时的内部状态来摆弄,实际上并没有做任何更改。后来,当属性实际上改变,验证运行和事件被发射。它不会让意会沉默改变时发出一个错误事件。

Because the point of silent changes is that you're allowed to twiddle with the internal state of your model, temporarily, without actually making a change. Later, when the attribute actually changes, the validation runs and events are emitted. It wouldn't make sense to emit an error event when making a silent change.

注:我没有测试此确认行为,这只是基于我释放的读书笔记...

为骨干0.9.10中,上述的行为发生了变化。在该版本(及更高版本),沉默:真正的燮presses的的变化:ATTR 事件完全 - 没有只是延迟它们。

As of Backbone 0.9.10, the behavior described above has changed. In that version (and newer), silent:true suppresses the change:attr events entirely - not just delays them.

http://backbonejs.org/#changelog

这篇关于在Backbone.js的,为什么沉默变化引发更改事件最终?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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