Giter Club home page Giter Club logo

Comments (6)

garrettlangley avatar garrettlangley commented on May 16, 2024

confirming this is a bug as well.

from backbone.localstorage.

jferguson avatar jferguson commented on May 16, 2024

Same here. Fix from Sergeyshall resolved the issue for me.

from backbone.localstorage.

jeromegn avatar jeromegn commented on May 16, 2024

Wow, I have no been receiving the email notifications of new issues. I'm sorry if that took a while.

Would you mind submitting a pull request with that code? Maybe even write a test for it :)

from backbone.localstorage.

fiznool avatar fiznool commented on May 16, 2024

My two cents - I've come across this problem before too, but my suggested approach would be to duck-punch JSON.parse. This way we don't need to add the same null checks every time we are parsing JSON. Pull Request #41 only fixes the case of JSON.parse within this library - what if I need to do JSON.parse in my own code?

For example:

brianleroux/lawnchair#48 (comment)

from backbone.localstorage.

nerdgore avatar nerdgore commented on May 16, 2024

We've come across this issue as well. In our own code it's trivial to implement a null check like value && JSON.parse(value);. To keep the fixing code separate we added jsonData().

find: function(model) {
  // call to this.jsonData instead of JSON.parse
  return this.jsonData(this.localStorage().getItem(this.name+"-"+model.id));
}

findAll: function() {
  return _(this.records).chain()
    .map(function(id){
      return this.jsonData(this.localStorage().getItem(this.name+"-"+id));
    }, this)
    .compact()
    .value();
}

and as above the actual handling is simple

jsonData: function (data) {
  return data && JSON.parse(data);
}

from backbone.localstorage.

jeromegn avatar jeromegn commented on May 16, 2024

@nerdgore If you'd like to submit that as a pull request, it'd be greatly appreciated.

from backbone.localstorage.

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.