Giter VIP home page Giter VIP logo

Comments (10)

Irrelon avatar Irrelon commented on July 23, 2024

Hey ya,

I'm a bit confused about your question, specifically:

Whenever I use load, it always returns err as false, which means it never loads the data initially

Any stored data is loaded into the collection and the call to load() then tells the callback if an error occurred (which almost always will be false - which is expected behaviour).

which means it never loads the data initially

Returning err = false doesn't mean the data isn't loaded.

from forerunnerdb.

robhicks avatar robhicks commented on July 23, 2024

Okay, so it appears that collection.load() just check to see if the collection exists and if it does, it loads it. However, how would you recommend handling my scenario? I want to load the local collection not only if it exist but it contains data (particularly the case when a user changes the route (SPA)). However, if the collection is empty, it needs to be loaded.

from forerunnerdb.

Irrelon avatar Irrelon commented on July 23, 2024

The .load() method will only return an error if it actually fails, not if persistent storage data exists or not. I can add an operation summary as data in the second returned parameter in the callback if you like that will describe if data was found and if so, how many records were found.

I think that would solve your problem.

It would be something like this:

db.collection('test').load(function (err, response, op) {
    if (!op.foundData) {
        // Load our data from the API
    } else if (op.rowCount < someExpectedNumberOfDocs) {
        // Load data again as we are missing some since last time the app was loaded
    }
});

If that would solve your problem let me know!

from forerunnerdb.

Irrelon avatar Irrelon commented on July 23, 2024

Please clone the dev branch and let me know if that solves your issue as usage is described above.

from forerunnerdb.

robhicks avatar robhicks commented on July 23, 2024

Thanks for working on this. I grabbed dist/fdb-core+persist.js from your dev branch and attempted to use it. It doesn't appear to have the new code. Which one should I use?

from forerunnerdb.

Irrelon avatar Irrelon commented on July 23, 2024

Hmm, it should do! But try using fdb-all.js first. That definitely has it as it is an "all modules enabled" build.

core+persist should be ok though...

from forerunnerdb.

Irrelon avatar Irrelon commented on July 23, 2024

Oops, looks like my example above was incorrect, the operation data comes back in the third argument of the callback, not the second. I've updated the example above.

from forerunnerdb.

telekosmos avatar telekosmos commented on July 23, 2024

Just to say I came across this issue as I wanted to load the data at app startup from persistent storage, falling to network request if data not found. The callback params are perfect to check this out. As this could be very useful (IMHO), I suggest you to include in the documentation for the collection.load method.

I found response and op to have the same content (not the same == object), BTW.

cheers

from forerunnerdb.

Irrelon avatar Irrelon commented on July 23, 2024

I believe the API has been updated since this issue was raised. The callback now contains:

callback(err, tableStats, metaStats);

The err is obvious, either falsy for no error or something non-falsy for an error.

The other two are:

tableStats - The details about the data loaded for the collection.
metaStats - The details about the data loaded for the collection's meta data (meta data includes stuff like last change timestamp for the collection etc).

I will update the load method docs to reflect this. :)

from forerunnerdb.

Irrelon avatar Irrelon commented on July 23, 2024

OK, I've updated the docs on the edge branch as per the commit shown above.

from forerunnerdb.

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.