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

table clear #60

Closed
tszpinda opened this issue Jan 18, 2015 · 3 comments
Closed

table clear #60

tszpinda opened this issue Jan 18, 2015 · 3 comments

Comments

@tszpinda
Copy link

Hi, first got to say its a pleasure to work with yours library.

I think there is a issue with clear method it returns error when used with bind method, example:

var db = new Dexie('cleartest');
db.version(1).stores({
foo: '&id',
bar: '&id',
});
db.open();
db.foo.clear().then(db.bar.clear).catch(alert);

it errors with:
"TypeError: undefined is not an object (evaluating 'this.hook')"

@dfahlander
Copy link
Collaborator

Thanks for apprechiating the library.

By looking at the code, I see that you are sending 'db.bar.clear' as a pure function argument, which will invalidate the 'this' reference. There is not chance for the clear() method to know which Table instance to work with. A corrected version of your test would be:

        var db = new Dexie('cleartest');
        db.version(1).stores({
            foo: '&id',
            bar: '&id',
        });
        db.open();
        db.foo.clear().then(function() {
            return db.bar.clear();
        }).then(function() {
            alert("Successfully cleared foo and bar")
        }).catch(alert);

Did I get it right?

@tszpinda
Copy link
Author

oh silly error, this works too:
db.foo.clear().then(db.bar.clear.bind(db.bar))

although not sure which one is easier to read

@dfahlander
Copy link
Collaborator

True. Your works identically. It also returns the promise from db.bar.clear so that your chain of promises is intact and the final then() or catch() will in include its operation.

A question of taste which one is the simplest...

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