Message from discussion
Adding routers to app after it has started
Received: by 10.68.230.68 with SMTP id sw4mr1310641pbc.7.1333399847608;
Mon, 02 Apr 2012 13:50:47 -0700 (PDT)
X-BeenThere: backbonejs@googlegroups.com
Received: by 10.68.237.40 with SMTP id uz8ls15584639pbc.2.gmail; Mon, 02 Apr
2012 13:50:21 -0700 (PDT)
Received: by 10.68.74.201 with SMTP id w9mr7288061pbv.0.1333399821317;
Mon, 02 Apr 2012 13:50:21 -0700 (PDT)
Received: by 10.68.74.201 with SMTP id w9mr7288060pbv.0.1333399821300;
Mon, 02 Apr 2012 13:50:21 -0700 (PDT)
Return-Path: <aidan.feld...@gmail.com>
Received: from mail-pb0-f47.google.com (mail-pb0-f47.google.com [209.85.160.47])
by gmr-mx.google.com with ESMTPS id g5si7844017pbk.2.2012.04.02.13.50.21
(version=TLSv1/SSLv3 cipher=OTHER);
Mon, 02 Apr 2012 13:50:21 -0700 (PDT)
Received-SPF: pass (google.com: domain of aidan.feld...@gmail.com designates 209.85.160.47 as permitted sender) client-ip=209.85.160.47;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of aidan.feld...@gmail.com designates 209.85.160.47 as permitted sender) smtp.mail=aidan.feld...@gmail.com; dkim=pass header...@gmail.com
Received: by mail-pb0-f47.google.com with SMTP id um15so4907593pbc.34
for <backbonejs@googlegroups.com>; Mon, 02 Apr 2012 13:50:21 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20120113;
h=mime-version:in-reply-to:references:date:message-id:subject:from:to
:content-type;
bh=pgLdhxi855IKBoyyS/TTTvOW62QfpIRJSzC7tAcyxh8=;
b=fJ1RVP7k6v6iP2MBRAAaRc1caH/iGADpS64++sLb1RUgYkmoDCOkdM/15mLrqyVpVS
mTI6Q/vXmInW07iwYqBWSCnjVGUL6RpQxTCz9EGEZKqE2GnvzLjsHlRoa2dgOFL3UNXV
iE5G1unSRsnVDc9HIbPIU6xPJIiZv3+TjGtMGH+J0oTNBDPLLtxHfoOKy5Z0JY70VvUn
D4mjzMZpAQOCXnAN5O4EJ8kk0eKOZ7DXnHMnbsjWbz4D8rNywYVlCoRbx0uxuL7SXJyJ
pkXEH5pWB7orSI0/wx67vXC/U1yCiIH64wDhZ8zX/Y4iRF3sb47eegsU/EBp6CUczvwF
ElSQ==
MIME-Version: 1.0
Received: by 10.68.197.164 with SMTP id iv4mr23664196pbc.11.1333399821204;
Mon, 02 Apr 2012 13:50:21 -0700 (PDT)
Received: by 10.68.129.70 with HTTP; Mon, 2 Apr 2012 13:50:21 -0700 (PDT)
In-Reply-To: <CACbAZ06=HJ17XKe0j4V4CP8pCghdmxBgPLRj6eG9qUUfnnw...@mail.gmail.com>
References: <CACbAZ06=HJ17XKe0j4V4CP8pCghdmxBgPLRj6eG9qUUfnnw...@mail.gmail.com>
Date: Mon, 2 Apr 2012 16:50:21 -0400
Message-ID: <CAPgiXS5RSprBZwKB71O8QoxJ1w8aMAORxEMdLEJ58H1MXw5...@mail.gmail.com>
Subject: Re: [backbonejs] Adding routers to app after it has started
From: Aidan Feldman <aidan.feld...@gmail.com>
To: backbonejs@googlegroups.com
Content-Type: multipart/alternative; boundary=e89a8ff1caeeafbb4c04bcb85601
--e89a8ff1caeeafbb4c04bcb85601
Content-Type: text/plain; charset=ISO-8859-1
I don't think this is a great approach - the nice thing about the router is
that having the routes statically defined makes it easy to read. I'd
personally do something like:
routes: {
...
"the/path/less/traveled": "thePathLessTraveled"
},
thePathLessTraveled: function() {
if ( this.extraFeatureLoaded ) {
// do stuff
} else {
// error?
}
}
On Mon, Apr 2, 2012 at 1:41 PM, Tauren Mills <tau...@groovee.com> wrote:
> Is there a way to add additional routers to an application after
> Backbone.history.start() has been executed?
>
> I have some rarely-used features of my application that are loaded
> on-demand after the application has already started. Some of those features
> need to add additional routes to the application. But since the feature and
> it's router hasn't been loaded at DOM ready, and Backbone.history.start()
> has already run, the routes aren't available.
>
> Would it be better to have one application level router instead of a
> router for each feature? If I did this, each feature would manually add its
> routes and callbacks to the main application router. Any thoughts on this
> approach?
>
> Thanks,
> Tauren
>
>
>
>
> --
> The Unofficial Backbone.js Group
>
--e89a8ff1caeeafbb4c04bcb85601
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
I don't think this is a great approach - the nice thing about the route=
r is that having the routes statically defined makes it easy to read. =A0I&=
#39;d personally do something like:<div><br></div><div><div><font face=3D"&=
#39;courier new', monospace">routes: {</font></div>
<div><font face=3D"'courier new', monospace">=A0 ...</font></div><d=
iv><font face=3D"'courier new', monospace">=A0 "the/path/less/=
traveled": "thePathLessTraveled"</font></div><div><font face=
=3D"'courier new', monospace">},</font></div>
<div><font face=3D"'courier new', monospace"><br></font></div><div>=
<font face=3D"'courier new', monospace">thePathLessTraveled: functi=
on() {</font></div><div><font face=3D"'courier new', monospace">=A0=
if ( this.extraFeatureLoaded ) {</font></div>
<div><font face=3D"'courier new', monospace">=A0 =A0 // do stuff</f=
ont></div><div><font face=3D"'courier new', monospace">=A0 } else {=
</font></div><div><font face=3D"'courier new', monospace">=A0 =A0 /=
/ error?</font></div>
<div><font face=3D"'courier new', monospace">=A0 }</font></div><div=
><font face=3D"'courier new', monospace">}</font></div><div><br></d=
iv><br><div class=3D"gmail_quote">On Mon, Apr 2, 2012 at 1:41 PM, Tauren Mi=
lls <span dir=3D"ltr"><<a href=3D"mailto:tau...@groovee.com">tauren@groo=
vee.com</a>></span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">Is there a way to add additional routers to =
an application after Backbone.history.start() has been executed?=A0<div><br=
></div>
<div>I have some rarely-used features of my application that are loaded on-=
demand after the application has already started. Some of those features ne=
ed to add additional routes to the application. But since the feature and i=
t's router hasn't been loaded at DOM ready, and Backbone.history.st=
art() has already run, the routes aren't available.<br>
<br>Would it be better to have one application level router instead of a ro=
uter for each feature? If I did this, each feature would manually add its r=
outes and callbacks to the main application router.=A0Any thoughts on this =
approach?</div>
<div><br></div><div>Thanks,<br>Tauren</div><span class=3D"HOEnZb"><font col=
or=3D"#888888"><div><br></div><div><br></div><div><br><br></div>
<p></p>
-- <br>
The Unofficial Backbone.js Group<br>
</font></span></blockquote></div><br></div>
--e89a8ff1caeeafbb4c04bcb85601--