From 6f005fd91a1c3e8ec461b298350dccd337f7a8da Mon Sep 17 00:00:00 2001 From: Richard Lai Date: Fri, 5 Jun 2015 07:51:27 -0400 Subject: [PATCH 1/2] Use proper reactive route detection --- react-todos/client/routes.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react-todos/client/routes.jsx b/react-todos/client/routes.jsx index 87d76ce7..bcbe3863 100644 --- a/react-todos/client/routes.jsx +++ b/react-todos/client/routes.jsx @@ -34,7 +34,7 @@ Tracker.autorun(function (computation) { }); // If they are, and we are at the root route, we should go to a valid list - if (subsReady && FlowRouter.current().name === "root") { + if (subsReady && FlowRouter.getRouteName() === "root") { FlowRouter.go("todoList", { listId: Lists.findOne()._id }); computation.stop(); } From 180a1e5e4f9d5280a97aab030af3e26be725625a Mon Sep 17 00:00:00 2001 From: Richard Lai Date: Fri, 5 Jun 2015 08:12:19 -0400 Subject: [PATCH 2/2] Let Flow Router handle global subscriptions By registering them with a name (as first param), you can listen to the readiness of specific subscriptions using FlowRouter.subsReady('privateLists')` or all subscriptions without passing a name. --- react-todos/client/routes.jsx | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/react-todos/client/routes.jsx b/react-todos/client/routes.jsx index bcbe3863..c81aa060 100644 --- a/react-todos/client/routes.jsx +++ b/react-todos/client/routes.jsx @@ -1,10 +1,9 @@ // This data is used on every page; also we want to make sure we route to the // first list instead of no list at all -var handles = [ - Meteor.subscribe("publicLists"), - Meteor.subscribe("privateLists") -]; -var subsReady; +FlowRouter.subscriptions = function () { + this.register('publicLists', Meteor.subscribe('publicLists')); + this.register('privateLists', Meteor.subscribe('privateLists')); +}; FlowRouter.route("/", { name: "root", @@ -28,13 +27,8 @@ FlowRouter.route("/lists/:listId", { // XXX this should be replaced by promises, probably... Tracker.autorun(function (computation) { - // Are all of the subscriptions done yet? - subsReady = _.all(handles, function (handle) { - return handle.ready(); - }); - - // If they are, and we are at the root route, we should go to a valid list - if (subsReady && FlowRouter.getRouteName() === "root") { + // If the data's ready, and we are at the root route, we should go to a valid list + if (FlowRouter.subsReady() && FlowRouter.getRouteName() === "root") { FlowRouter.go("todoList", { listId: Lists.findOne()._id }); computation.stop(); }