Git Product home page Git Product logo

Comments (2)

rezonant avatar rezonant commented on August 16, 2024

Interesting, and unfortunate, but this looks like an artifact of how IndexedDB works:

https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB#Adding_data_to_the_database

Now that you have a transaction you need to understand its lifetime. Transactions are tied very closely to the event loop. If you make a transaction and return to the event loop without using it then the transaction will become inactive. The only way to keep the transaction active is to make a request on it. When the request is finished you'll get a DOM event and, assuming that the request succeeded, you'll have another opportunity to extend the transaction during that callback. If you return to the event loop without extending the transaction then it will become inactive, and so on. As long as there are pending requests the transaction remains active. Transaction lifetimes are really very simple but it might take a little time to get used to. A few more examples will help, too. If you start seeing TRANSACTION_INACTIVE_ERR error codes then you've messed something up.

After looking at your issue here I worried that the find() example which uses an inner query may not work correctly, but I think it still would because the async operation would be an IndexedDB one, and so the transaction would not become inactive due to that.

But any other async operation would cause the transaction to close. The best way to handle this would be to initiate another transaction if you need to perform an asynchronous operation.

Perhaps there could be some functionality we could add to Dibello to make this a smoother process, like perhaps introducing a Dibello-specific transaction injectable which would be capable of starting a new transaction without re-establishing your stores/injectables (ie apples, trees). But I'm not sure if this is the direction we should go in, since it sort of modifies the definition of what a transaction is in Dibello versus what IndexedDB does underneath the covers.

For now you would have to do:

...
await delay(1);
db.transact('readwrite', async (apples) => apples.persist(apple));

from dibello.

rafis avatar rafis commented on August 16, 2024

Thank you. Now I see, IndexedDB is not perfect as I thought. I do not understand why they have decided to bind IndexedDB to the DOM, DOM event system. Sometimes I think that perhaps using localStorage is better choice for me.

Did you get these errors while developing the library and debugging its code? Because I'm getting 2-3 types of similar error while debugging inside db.transact(). But if I don't have breakpoints inside transaction logic then I'm receiving the errors more rarely, so it is doable.

I haven't look deeply into tests and I don't have much experience developing javascript tests, but using IndexedDB mock disturbs me, such a feeling that using mocks are not testing the system holistically. I will try to look deeper if I will have time.

from dibello.

Related Issues (2)

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.