hoodiehq / pouchdb-hoodie-api

:dog: Hoodie-like API for PouchDB
https://hoodiehq.github.io/pouchdb-hoodie-api
Apache License 2.0
44 stars 11 forks source link

add .clear() method #39

Closed gr2m closed 9 years ago

gr2m commented 9 years ago

follow up for #31

We left out api.clear() from the scope of this plugin initially because we thought we wouldn't add events. api.clear() is just like api.removeAll(), but without triggering the add, update, remove and change events.

It shouldn't be exposed for Modular Usage, just like on, one and off

UPDATE also add clear event, that only gets called when api.clear() gets called and it finishes successfully

HipsterBrown commented 9 years ago

@gr2m by "follow up", you mean after #31 has been merged, correct?

gr2m commented 9 years ago

yes, exactly, it kind of depends on #31, that's why I added it

patriciagarcia commented 9 years ago

@gr2m, I am not sure this is compatible with the current implementation of events. In #31, I am using PouchDB events and afaik there is no way to stop PouchDB events from being triggered when you delete docs. The only operation I can find that won't trigger the events is destroying the db.

Maybe we need to rethink the whole events implementation if clear is needed?

gr2m commented 9 years ago

destroying the db sounds right to me for .clear(). You'd call clear for example when you sign out of an account, you'd want to remove everything in the database and start with a clear state. Anything speaking against destroying the db on clear?

gr2m commented 9 years ago

@nolanlawson if I remember correctly, there is some known issue with db.destroy(), right? I'd love to hear your thoughts on adding a store.clear() method that wouldn't trigger the delete events on objects, if you have a moment

nolanlawson commented 9 years ago

@gr2m Long-term, both destroy() and calling remove() for all documents should be stable, but in practice there are lots of issues with destroy() due to race conditions in different implementations of IndexedDB. I'm hoping most of those will be ironed out once I (or someone) have implemented native secondary indexes, which are the source of most of those race conditions.

gr2m commented 9 years ago

thanks @nolanlawson! What would you recommend for the time being? Should we silently delete all docs and do not call db.destroy() at all?

toh82 commented 9 years ago

Orrr, donno how to link issues with PRs ^^, so here is it https://github.com/hoodiehq/pouchdb-hoodie-api/pull/50

gr2m commented 9 years ago

@toh82 add a closes #39 to the description of the PR. Once it gets merged, the related issue will be closed automagically :)

gr2m commented 9 years ago

fixed via https://github.com/hoodiehq/pouchdb-hoodie-api/issues/50