Charilaos Skiadas
unread,Jul 9, 2013, 4:07:38 PM7/9/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to cuj...@googlegroups.com
Ok I dug in a little deeper into my connect problems, let's see if someone can help me clear it up completely. I suppose at the heart of it I might just need to understand better how the proxies and the magic of connections works. Perhaps I can summarize my question thusly:
If someone or something gets hold of a reference to an object's method during the create/configure/initialize lifecycle stages, would calling that method through this reference no longer activate any of the methods supposedly linked to it during the connect lifecycle stage?
If this is indeed the case, then using Backbone.history is going to be a major pain in the youknowwho.
Here's some more details of my setting:
Anyway, here is the situation, basically. I have one component, whose module is a somewhat standard Backbone.router, and roughly looks like this:
```js
define(['backbone'], function(Backbone) {
return Backbone.Router.extend({
routes: {
"structure/:id" : "getStructure",
...
},
getStructure: function(id) {
this.editStructure(id);
console.log("Structure: ", id);
},
editStructure: function(id) {
console.log("Calling edit")
},
...
startListening: function() {
console.log("Router starting to listen.")
Backbone.history.start();
}
});
});
```
I've omitted things irrelevant to my question. Here is how this is wired into the spec:
mainRouter: {
create: 'js/routers/main',
ready: 'startListening',
connect: {
'getStructure': 'sidebar.highlightActive'
},
},
So startListening is called on ready, and it starts up the history-tracking. When the location bar changes, getStructure is called, however, sidebar.highlightActive which was supposed to be linked to it does not trigger. However, if I change the connect to 'editStructure' instead of 'getStructure', then sidebar.highlightActive will in fact run.
So Backbone must be doing something behind the scenes in the way it is calling getStructure, that somehow bypasses the system wire uses to connect the two, so I think I need a better understanding of how that works.
I suspect that upon its creation, Backbone.router activates the routes method, which turns around and calls the route method for each route, which seems to add some callback function triggers in the Backbone.history object. This all seems to happen before the connect facet gets to run. Could this be the source of the failure to connect?
Haris Skiadas