2012-12-13 34 views
1

採取例如:是否將路由器狀態邏輯與模型耦合錯誤?

Ember.Model.reopen({ 
    show: Ember.observer(function(){ 
    var target = this.get('showPath'), 
     waypoint = Ember.Route.transitionTo('root'), 
     destination = Ember.Route.transitionTo(target), 
     router = App.get('router'); 

    waypoint(router); 
    destination(router, this); 
    }) 
}); 

App.Post.reopen({ 
    showPath: 'posts.show' 
}); 

在這裏,我們已經定義了在其上從當前狀態轉變到目的地的模型的顯示方法中,在根首先停止。

我發現這使得代碼與顯示對象的簡單的任務超簡單:

App.Post.find(1).show(); 

暫且不論這是否是有幫助的,我用它麻煩的是,我們有一些非常露骨的耦合模型類到路由器。

我的問題是...

這是一件值得擔心的事情嗎?

回答

3

我的直覺是這是錯誤的。當你思考一個Ember應用程序的依賴關係圖時,顯然路由器依賴於模型,因此如果模型不依賴於路由器,它會更好。