Using PouchDB in an existing synchronous app

201 views
Skip to first unread message

Jay Clark

unread,
Jun 23, 2015, 1:30:02 AM6/23/15
to pou...@googlegroups.com
Hi,
I consider myself still a JS beginner (lots of head knowledge but not much practice)... Here's what I'm trying to do: I'm trying to integrate PouchDB into a synchronous (react + flux) app and I'm not sure how to handle the async (delayed) return of a doc.

I've put my PouchDB logic in a cjs module, and it is returning the contents of a doc in my db. However, I'm not sure how to make the synchronous part of my app get the contents of the doc stored into a variable - it's always coming up 'undefined'. How do I receive the result of PouchDB's promise in my app?

Many thanks,
~Jay

Nolan Lawson

unread,
Jun 26, 2015, 1:01:38 PM6/26/15
to pou...@googlegroups.com, runleve...@gmail.com
Hi Jay,

Unfortunately we still have yet to see someone write a nice beginner tutorial about using PouchDB with React/Flux, but you ought to be able to do it by listening for events on PouchDB's changes() feed and notifying your Dispatcher when that occurs. To take an example from the well-known "What the Flux" article (http://jonathancreamer.com/what-the-flux/), this would be the "Hey everyone! There's new stuff!" point. :)

This article may also help you, since it describes a simple method to "mirror" a PouchDB to an in-memory array of documents: http://pouchdb.com/2015/02/28/efficiently-managing-ui-state-in-pouchdb.html

Good luck,
Nolan
Reply all
Reply to author
Forward
0 new messages