simonv3 / reading-list

A Hood.ie Powered Reading List
2 stars 1 forks source link

Move the UI to respond to the store (as in the hoodie example) #1

Open simonv3 opened 9 years ago

simonv3 commented 9 years ago

Right now data is sent to the store, rather then the store telling the client what's changed

// hoodie.store.on('add:book', readingList.add);
// hoodie.store.on('update:book', readingList.update);
// hoodie.store.on('remove:book', readingList.remove);
simonv3 commented 9 years ago

Look into https://github.com/hoodiehq/backbone-hoodie/

Backbone.sync = function(method, model, options) {
  var promise;
  switch (method) {
    case 'read':
    if (model.id) {
      promise = hoodie.store.find(model.type, model.id);
    } else {
      promise = hoodie.store.findAll(model.model.prototype.type);
    }
    break;
    case 'create':
    promise = hoodie.store.add(model.type, model.attributes);
    break;
    case 'update':
    promise = hoodie.store.update(model.type, model.id, model.attributes);
    break;
    case 'delete':
    promise = hoodie.store.remove(model.type, model.id);
    break;
    default:
    throw new Error("not implemented");
  }
  if (options.success) promise.done(options.success);
  if (options.error) promise.fail(options.error);
  return promise;
};