Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

FIX: correctly fetch() content for Backbone.Model Objects #48

Closed
wants to merge 1 commit into from

2 participants

@jDavidnet

This lib did not correctly fetch()/ 'read'/'GET'
from local storage for Backbone.Model objects after page refresh.

It does work in the tests however because the tests
do not refresh the page and load once again from localStorage.
The tests rely on the in memory version of the object to return the correct result.

In my personal test this worked for Backbone.Model, but I did
not test Backbone.Collection Objects.

@jDavidnet jDavidnet Now correctly fetches for Backbone.Model
This lib did not correctly fetch()/ 'read'/'GET'
from local storage for Backbone.Model objects.

It does work in the tests however because the tests
do not refresh the page and load once again from localStorage.

in my personal test this worked for Backbone.Model, but I did
not test Backbone.Collection Objects.
3a9fac7
@jeromegn
Owner

The tests need to pass before I can merge this in.

@jDavidnet

I'll have to look at this in the next few days. It's working for me right now.

There is another problem with destroy on Backbone.Modal

@jeromegn jeromegn closed this
@jDavidnet

I have been using this for months without issue. If you don't use this patch then you can only use this adapter on a collection, and it does not work on a model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 14, 2012
  1. @jDavidnet

    Now correctly fetches for Backbone.Model

    jDavidnet authored
    This lib did not correctly fetch()/ 'read'/'GET'
    from local storage for Backbone.Model objects.
    
    It does work in the tests however because the tests
    do not refresh the page and load once again from localStorage.
    
    in my personal test this worked for Backbone.Model, but I did
    not test Backbone.Collection Objects.
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 1 deletion.
  1. +6 −1 backbone.localStorage.js
View
7 backbone.localStorage.js
@@ -103,7 +103,12 @@ Backbone.LocalStorage.sync = window.Store.sync = Backbone.localSync = function(m
var resp, syncDfd = $.Deferred && $.Deferred(); //If $ is having Deferred - use it.
switch (method) {
- case "read": resp = model.id != undefined ? store.find(model) : store.findAll(); break;
+ case "read":
+ resp = model.id != undefined ? store.find(model) : store.findAll();
+ if(resp && resp.length >= 1 && (model instanceof Backbone.Model) ){
+ resp = resp[0];
+ }
+ break;
case "create": resp = store.create(model); break;
case "update": resp = store.update(model); break;
case "delete": resp = store.destroy(model); break;
Something went wrong with that request. Please try again.