PageRenderTime 32ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/components/Todo/Store.js

https://gitlab.com/devlocker/frontend
JavaScript | 59 lines | 47 code | 12 blank | 0 comment | 0 complexity | a52f4e3d9cd305aab00b8172c98862dc MD5 | raw file
  1. var Actions = require("./Actions");
  2. var Store = Reflux.createStore({
  3. listenables: [Actions],
  4. load() {
  5. var TodoItemsCollection = Backbone.Collection.extend({
  6. url: window.location.pathname + "/todo/items"
  7. });
  8. var collection = new TodoItemsCollection;
  9. collection.fetch({
  10. success: (collection, response, options) => {
  11. this.list = collection;
  12. this.updateList();
  13. }
  14. });
  15. },
  16. fetch() {
  17. this.list.fetch({
  18. success: (collection, response, options) => {
  19. this.list = collection;
  20. this.updateList();
  21. }
  22. });
  23. },
  24. addItem(text) {
  25. this.list.create({ content: text, completed: false });
  26. this.updateList();
  27. },
  28. toggleItem(model) {
  29. model.save({ completed: !model.get("completed") });
  30. this.updateList();
  31. },
  32. editItem(model, content) {
  33. model.save({ content: content });
  34. this.updateList();
  35. },
  36. deleteItem(model) {
  37. model.destroy();
  38. this.updateList();
  39. },
  40. updateList() {
  41. this.trigger(this.list);
  42. },
  43. changeColor(color) {
  44. this.trigger({ color: color });
  45. }
  46. });
  47. module.exports = Store;