Giter Club home page Giter Club logo

Comments (6)

Rovanion avatar Rovanion commented on August 15, 2024

Neither this variant seems to be working:

var Favourites = Backbone.Model.extend({
    local: true, //Only sync against LocalStorage                                                                             
    url: 'favourites',
    initialize: function(){
        var self = this;
        this.fetch({
            success: function(){
                console.debug(self);
            }
        });
    },
});

from backbone.dualstorage.

lucian1900 avatar lucian1900 commented on August 15, 2024

I would expect the second to work. If it doesn't, that's a bug.

from backbone.dualstorage.

nilbus avatar nilbus commented on August 15, 2024

Since for localstorage there's no XMLHttpRequest to pass back, you're not going to be able to hook in complete() like in your first example. The success callback is what you want.

I'm surprised that your second example didn't work. I have several tests in my fork that test both the local: true option and the success callback. This spec relies on the fetch success callback for the test to pass. I tried it with local: true on the model instead of remote: false in the fetch call, which also worked. I also rely on this fetch success callback in one of my apps that uses this plugin.

from backbone.dualstorage.

nilbus avatar nilbus commented on August 15, 2024

I put together a jsfiddle with your code, and it seems to work. Run this, and you see the debug output in the console:

http://jsfiddle.net/nilbus/P3euQ/

from backbone.dualstorage.

Rovanion avatar Rovanion commented on August 15, 2024

Yeah that seems to work. Odd thing that I couldn't get it working in my code then. I'll close this off then.

from backbone.dualstorage.

reubano avatar reubano commented on August 15, 2024

If you have jquery, you can wrap the fetch in a deferred.

dfdFetch: =>
  $.Deferred((deferred) => @fetch
    success: deferred.resolve
    error: deferred.reject).promise()

And then you can do things like @dfdFetch().done(somefunc).fail(otherfunc)

from backbone.dualstorage.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.