Giter Club home page Giter Club logo

Comments (6)

techfort avatar techfort commented on June 19, 2024

Thanks for flagging this Ryan.
As it is a callback that cFun looks like it was meant to be a
cFun.call(null, data);
Would you be able to test if that works? I won't be in front of a pc for
a few days and this seems a pretty major bug.

joe

On 08/01/15 22:32, Ryan wrote:

To verify that this was an issue, I made a simple index.html file w/
the following code (taken from the docs)

var db = new loki('test', { env: 'BROWSER'}),
        db2 = new loki('test', { env: 'BROWSER'});

var users = db.addCollection('users');
users.insert({
    name: 'joe'
});
users.insert({
    name: 'john'
});
users.insert({
    name: 'jack'
});
console.log(users.data);
db.saveDatabase();

db2.loadDatabase(function () {
    var users2 = db2.getCollection('users')
    console.log(users2.data);
});

|loadDatabase| breaks in the following code snippet (which exists in
two areas):

    if (localStorageAvailable()) {
      self.loadJSON(localStorage.getItem(this.filename));
      cFun(null, data);
    } else {
      cFun(new Error('localStorage is not available'));
    }

Data is undefined and an error is thrown. I've verified that removing
data from the callback resolves the issue.


Reply to this email directly or view it on GitHub
#56.

from lokijs.

chimon2000 avatar chimon2000 commented on June 19, 2024

That alone didn't work. Data being undefined but referenced like a global variable still causes that nasty error to get thrown.

Assuming that you want the localStorage / BROWSER version to work just like the NODEJS version, the following

            var data = localStorage.getItem(this.filename);

            self.loadJSON(data, options || {});
            cFun.call(null, data);

worked fine and may suffice as a solution.

from lokijs.

techfort avatar techfort commented on June 19, 2024

If you want to submit a PR i'm happy for you to get the credit for it.
Otherwise I'll see if @obeliskos has time to address this.

On Thu, Jan 8, 2015 at 10:53 PM, Ryan [email protected] wrote:

That alone didn't work. Data being undefined but referenced like a global
variable still causes that nasty error to get thrown.

Assuming that you want the localStorage / BROWSER version to work just
like the NODEJS version, the following

        var data = localStorage.getItem(this.filename);

        self.loadJSON(data, options || {});
        cFun.call(null, data);

worked fine and may suffice as a solution.


Reply to this email directly or view it on GitHub
#56 (comment).

from lokijs.

chimon2000 avatar chimon2000 commented on June 19, 2024

PR Submitted. Thanks!

from lokijs.

obeliskos avatar obeliskos commented on June 19, 2024

I needed to modify the call to just cFun(null, data) instead of the cFun.call which appears to treat the first param as a 'this' context before mapping the other args so the data was being mapped to err. I suppose we could have just passed this as first param but I don't know that we need that context to a user function.

from lokijs.

obeliskos avatar obeliskos commented on June 19, 2024

Re-opening to allow time for all to review changes

from lokijs.

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.