Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to modify an object through an asynchronous action in a hook #57

Closed
madarche opened this issue Jan 12, 2015 · 3 comments
Closed

Comments

@madarche
Copy link

Hello,

First, thank you for Dexie.js, this is really a nice way to use IndexedDB!

At the moment it's possible to exec an asynchronous action in the table hooks (for example with a promise). But if a hook modifies the object (obj), it is actually not persisted because when the object is later fetched it bears no trace of the modification.

db.some_store.hook('creating', function(primKey, obj, trans) {
    execAPromise();
});

Could there be a way to tell to wait until the async action is finalized?

Maybe something like the following:

db.some_store.hook('creating', function(primKey, obj, trans, done) {
    execAPromise().then(done);
});

But it's not Promise-oriented at all :-(

Any ideas about it?

Thank you

@madarche
Copy link
Author

I know the creating hook can have return value but it's use to possibly generate an ID.

So I'm sure you ran into this problem before. So there should be a solution :-)

Cheers,

@dfahlander
Copy link
Collaborator

Related to #14. There is a solution on its way. This is a limitation, yes! The change is a part of a larger change with a redesign of the internal chaining of filters to be asynchronic and then make the hooks take advantage of that.

You may modify the obj but in current version, that has to be done in the same call to have any effect.

Kind regards,
David

@madarche
Copy link
Author

Hello David,

Yes this is definitely a duplicate of #14. Maybe the title of #14 could be edited to reflect the generic nature of the limitation. This is why I've missed it when I checked for duplicates.

Best regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants