PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/public/js/backbone/collections/Things.js

https://bitbucket.org/boatkorachal/faak
JavaScript | 42 lines | 32 code | 5 blank | 5 comment | 2 complexity | 5361f563b5ef09ac8b4adde0e1cd7d17 MD5 | raw file
  1. var app = app || {};
  2. (function() {
  3. 'use strict';
  4. // Todo Collection
  5. // ---------------
  6. // The collection of todos is backed by *localStorage* instead of a remote
  7. // server.
  8. app.Things = Backbone.Collection.extend({
  9. url: 'things',
  10. model: app.Thing,
  11. socket: window.socket,
  12. initialize: function(parentModel){
  13. this.parentModel = parentModel;
  14. _.bindAll(this, 'serverCreate', 'serverDelete', 'collectionCleanup');
  15. this.ioBind('create', this.serverCreate, this);
  16. //this.ioBind('delete', this.serverDelete, this);
  17. },
  18. serverCreate: function(data){
  19. var exists = this.get(data._id);
  20. if( ! exists){
  21. this.add(data);
  22. }else{
  23. data.fromServer = true;
  24. exists.set(data);
  25. }
  26. },
  27. serverDelete: function(data){
  28. },
  29. collectionCleanup: function(callback){
  30. this.ioUnBindAll();
  31. this.each(function(model){
  32. model.modelCleanup();
  33. });
  34. return this;
  35. }
  36. });
  37. }());