木偶事件聚合VS骨干路由器 [英] Marionette Event Aggregator vs Backbone Router

查看:90
本文介绍了木偶事件聚合VS骨干路由器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是pretty新的这个世界,所以我需要它的一些澄清。也许我可能是错的题目。因此,随时纠正我。

I'm pretty new to this world so I need some clarifications on it. Maybe I could be wrong on the subject. So, feel free to correct me.

我在研究如何木偶和骨干一起工作。哦耶。木偶给了我们扩展骨干。真是不错的东西。

I'm studying how Marionette and Backbone work together. Oh yeah. Marionette gives us extension to Backbone. Really nice stuff.

这不是明显对我的事情是,当使用由骨干提供的路由机制,当木偶使用发布/订阅模式。

The thing that is not obvious to me is when to use the routing mechanism provided by Backbone and when to use publisher/subscriber pattern by Marionette.

有经验的规则?

在这里,<一个href=\"http://stackoverflow.com/questions/16664740/where-to-use-event-aggregator-in-backbone-marionette\">Where使用事件聚合骨干木偶?,类似的讨论,但对于如何使用或不通知对方。

Here, Where to use event aggregator in backbone marionette?, a similar discussion but there is no advice on how using that or the other.

推荐答案

我的路由管理采取自由preVIEW解释我的书上的木偶(<一个href=\"http://samples.leanpub.com/marionette-gentle-introduction-sample.pdf\">http://samples.leanpub.com/marionette-gentle-introduction-sample.pdf)

My take on the route management is explained in the free preview to my book on Marionette (http://samples.leanpub.com/marionette-gentle-introduction-sample.pdf)

基本上,我的意见(别人不一定共用)是骨干的路由应用于配置应用状态,当用户输入通过URL的应用程序。换言之,它将解析参数,并调用适当的控制器的动作。

Basically, my opinion (others don't necessarily share it) is that Backbone's routing should be used to configure the application state when the user "enters" the application via a URL. In other words, it will parse parameters, and call proper controller actions.

但一旦初始状态设置,路由code不应该再被触发,即使用户浏览该应用程序。

But once that initial state is setup, routing code should no longer be triggered, even as the user navigates through the application.

下面是一个例子:


  1. 用户输入到达了人脉/ 2 /编辑。骨干路由code将提取 2 参数,并调用修改 ID 参数(取该联系人,显示正确的观点,等等)。换句话说,在初始应用程序状态被配置。

  2. 在显示所有联系人链接导致的人脉URL的用户点击。在这里,我相信这个修改应通过木偶事件(即指示用户希望看到所有联系人)进行处理。毕竟,我们知道用​​户想要做什么,哪些URL片段应显示。换句话说,没有理由为路由code涉足。

  1. The user enters arrives on the "contacts/2/edit". Backbone routing code will extract the 2 argument and call the edit controller action with that id parameter (which fetches that contact, displays the proper views, etc.). In other words, the initial application state is being configured.
  2. The user clicks on the "show all contacts" link leading to the "contacts" URL. Here, I believe this modification should be handled through Marionette events (i.e. indicating the user wants to see all contacts). After all, we know what the user wants to do, and which URL fragment should be displayed. In other words, there is no reason for the routing code to get involved.

请注意,这是我的看法,和其他开发人员能够轻松过关触发:真,当用户点击一个链接。但正如我在上面链接书中摘录解释,这往往导致开发人员能够创建在JavaScript无国籍应用程序(例如,通过在URL中大量的参数,即使它们应该被存储在应用程序的状态)。亚特一切是有原因的,默认情况下,骨干导航方法触发:假

Note that this is my opinion, and other developers simply pass trigger: true when the user clicks a link. But as I explain in the book extract linked above, this tends to lead developers to create "stateless applications in javascript" (e.g. passing lots of parameters in the URL, even though they should be stored in the application's state). Ater all there is a reason that by default, Backbone's navigate method has trigger: false.

德里克·贝利(木偶的创建者)也在这里讨论了这个问题:<一href=\"http://lostechies.com/derickbailey/2011/08/03/stop-using-backbone-as-if-it-were-a-stateless-web-server/\">http://lostechies.com/derickbailey/2011/08/03/stop-using-backbone-as-if-it-were-a-stateless-web-server/

Derick Bailey (Marionette's creator) also discussed the issue here: http://lostechies.com/derickbailey/2011/08/03/stop-using-backbone-as-if-it-were-a-stateless-web-server/

这篇关于木偶事件聚合VS骨干路由器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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