Browse Source

Step 11.2: Add publish to server and subscribe to client.

Frederic G. MARAND 8 years ago
parent
commit
3120dc5ab8
1 changed files with 8 additions and 0 deletions
  1. 8 0
      simple-todos-react.jsx

+ 8 - 0
simple-todos-react.jsx

@@ -7,12 +7,20 @@ if (Meteor.isClient) {
     passwordSignupFields: "USERNAME_ONLY"
   });
 
+  Meteor.subscribe("tasks");
+
   Meteor.startup(function () {
     // Use this branch to render the component after the page is ready.
     ReactDOM.render(<App />, document.getElementById('render-target'));
   });
 }
 
+if (Meteor.isServer) {
+  Meteor.publish("tasks", function () {
+    return Tasks.find();
+  });
+}
+
 Meteor.methods({
   addTask(text) {
     // Make sure user is logged before inserting a task.