simple-todos-react.jsx 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Define a collection to hold our tasks.
  2. Tasks = new Mongo.Collection('tasks');
  3. if (Meteor.isClient) {
  4. // This code is executed on the client only.
  5. Accounts.ui.config({
  6. passwordSignupFields: "USERNAME_ONLY"
  7. });
  8. Meteor.startup(function () {
  9. // Use this branch to render the component after the page is ready.
  10. ReactDOM.render(<App />, document.getElementById('render-target'));
  11. });
  12. }
  13. Meteor.methods({
  14. addTask(text) {
  15. // Make sure user is logged before inserting a task.
  16. if (!Meteor.userId()) {
  17. throw new Meteor.error("not-authorized");
  18. }
  19. Tasks.insert({
  20. text: text,
  21. createdAt: new Date(),
  22. owner: Meteor.userId(),
  23. username: Meteor.user().username
  24. });
  25. },
  26. removeTask(taskId) {
  27. // Without checking user ?
  28. Meteor._debug("removing", taskId);
  29. Tasks.remove(taskId);
  30. },
  31. setChecked(taskId, setChecked) {
  32. // Without checking user ?
  33. Meteor._debug("setCheck", taskId, setChecked);
  34. Tasks.update(taskId, { $set: { checked: setChecked }});
  35. }
  36. });