PageRenderTime 88ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/public/js/backbone/collections/Faaks.js

https://bitbucket.org/boatkorachal/faak
JavaScript | 38 lines | 29 code | 5 blank | 4 comment | 2 complexity | 6f77de2168616defb1b6ad181bd2193e 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.Faaks = Backbone.Collection.extend({
  9. url: 'faaks',
  10. model: app.Faak,
  11. socket: window.socket,
  12. initialize: function(){
  13. _.bindAll(this, 'serverCreate', 'collectionCleanup');
  14. this.ioBind('create', this.serverCreate, this);
  15. },
  16. serverCreate: function(data){
  17. var exists = this.get(data._id);
  18. if( ! exists){
  19. this.add(data);
  20. }else{
  21. data.fromServer = true;
  22. exists.set(data);
  23. }
  24. },
  25. collectionCleanup: function(callback){
  26. this.ioUnBindAll();
  27. this.each(function(model){
  28. model.modelCleanup();
  29. });
  30. return this;
  31. }
  32. });
  33. }());