浏览代码

Optim: subscriptions managed by router

febbweiss 10 年之前
父节点
当前提交
8e66b1a767
共有 3 个文件被更改,包括 12 次插入5 次删除
  1. 3 0
      client/loading.html
  2. 0 4
      client/projects.js
  3. 9 1
      lib/routes.js

+ 3 - 0
client/loading.html

@@ -0,0 +1,3 @@
+<template name="loading">
+  <h1>Please wait...</h1>
+</template>

+ 0 - 4
client/projects.js

@@ -1,7 +1,3 @@
-Template.management.onCreated(function(){
-  Meteor.subscribe('projects');
-});
-
 Template.management.helpers({
 Template.management.helpers({
   projects: function () {
   projects: function () {
     return ProjectService.list();
     return ProjectService.list();

+ 9 - 1
lib/routes.js

@@ -7,5 +7,13 @@ Router.map(function () {
   this.route('home', {
   this.route('home', {
     path: '/',
     path: '/',
   });
   });
-  this.route('management');
+  this.route('management', function() {
+        this.subscribe('projects').wait();
+        
+        if (this.ready()) {
+            this.render();
+        } else {
+            this.render('Loading');
+        }
+  });
 });
 });