simple-todos-react.jsx 952 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. Tasks.remove(taskId);
  29. },
  30. setChecked(taskId, setChecked) {
  31. // Without checking user ?
  32. Tasks.update(taskId, { $set: { checked: setChecked }});
  33. }
  34. });