{"_id":"@abhinavzspace/redux-pouchdb","_rev":"3-c740a69a1857e432e18abeb01e6e7542","name":"@abhinavzspace/redux-pouchdb","description":"Sync store state to pouchdb","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@abhinavzspace/redux-pouchdb","version":"0.1.0","description":"Sync store state to pouchdb","main":"lib/index.js","scripts":{"build":"rimraf lib && babel src --out-dir lib","prepublish":"npm run build","test":"babel-tape-runner tests/*.js"},"files":["lib/","package.json","README.md"],"repository":{"type":"git","url":"git+https://github.com/vicentedealencar/redux-pouchdb.git"},"keywords":["redux","react-component","pouchdb"],"author":{"name":"Vicente de Alencar"},"license":"MIT","bugs":{"url":"https://github.com/vicentedealencar/redux-pouchdb/issues"},"homepage":"https://github.com/vicentedealencar/redux-pouchdb","babel":{"presets":["es2015","stage-0"]},"dependencies":{"array.from":"^1.0.2","deep-equal":"^1.0.1"},"devDependencies":{"babel-cli":"^6.11.4","babel-core":"^6.11.4","babel-preset-es2015":"^6.9.0","babel-preset-stage-0":"^6.5.0","babel-tape-runner":"^2.0.1","pouchdb-adapter-memory":"^5.4.5","pouchdb-core":"^5.4.5","redux":"^3.5.2","rimraf":"^2.5.3","tape":"^4.6.0","timeout-then":"^1.0.0"},"gitHead":"6d1d9a0f6f094413accf93855e543f8ebc411223","_id":"@abhinavzspace/redux-pouchdb@0.1.0","_shasum":"18d66f3b6f14ba4eb6eda2b3701cbb77c1eefcc9","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.7.0","_npmUser":{"name":"abhinavzspace","email":"abhinavzspace@gmail.com"},"dist":{"shasum":"18d66f3b6f14ba4eb6eda2b3701cbb77c1eefcc9","tarball":"https://registry.npmjs.org/@abhinavzspace/redux-pouchdb/-/redux-pouchdb-0.1.0.tgz","integrity":"sha512-2+/Pm+O9nC0AlRVWycLFiI2b1Wp6MVlu2pxgASjttHP+mosLP2JzwAH0HVMMuJ4T62E2KF5x2zGry+0j/wHovg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCvyFUeyGZ/m3CssJBwZ+pQQrGb+YLAX6QkLtC8fqplqAIhAJgzhvOZRmUpqVBr2520Y2PWNWZxPQZLJ8b9yD7fWq/D"}]},"maintainers":[{"name":"abhinavzspace","email":"abhinavzspace@gmail.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/redux-pouchdb-0.1.0.tgz_1475650842154_0.6940312597434968"}}},"readme":"# redux-pouchdb\n\n## What is going on here?\n\nIt is very simple:\n- The [PouchDB](http://pouchdb.com/) database persists the state of chosen parts of the [Redux](rackt.github.io/redux) store every time it changes.\n- Your reducers will be passed the state from PouchDB when your app loads and every time a change arrives (if you are syncing with a remote db).\n\n## Usage\n\n### `persistentStore`\n\nThis store enhancer should be composed with yours in order to initialize\n\n``` js\nimport { persistentStore } from 'redux-pouchdb';\n\nconst db = new PouchDB('dbname');\n\n//optional\nconst applyMiddlewares = applyMiddleware(\n  thunkMiddleware,\n  loggerMiddleware\n);\n\nconst createStoreWithMiddleware = compose(\n  applyMiddlewares,\n  persistentStore(db)\n)(createStore);\n\nconst store = createStoreWithMiddleware(reducer, initialState);\n```\n\nThe `persistentStore` enhancer takes an optional second argument which can be a function or an array of functions which are called whenever changes arrive from the database. These functions are given the document (see the format at the bottom) from PouchDB and any truthy return values will be dispatched to the store. You can use this to set up more complex actions based on new data. If you want to take advantage of any middleware you are also setting up, compose the `persistentStore` before `applyMiddlewares`\n\n```js\nconst changeHandler = doc => {\n  // Return thunk based on doc.\n};\nconst createStoreWithMiddleware = compose(\n  persistentStore(db, changeHandler),\n  applyMiddlewares\n)(createStore);\n// ...\n```\n\n### `persistentReducer`\n\nThe reducers you wish to persist should be enhanced with this higher order reducer.\n\n``` js\nimport { persistentReducer } from 'redux-pouchdb';\n\nconst counter = (state = {count: 0}, action) => {\n  switch(action.type) {\n  case INCREMENT:\n  console.log(state.count + 1);\n    return { count: state.count + 1 };\n  case DECREMENT:\n    return { count: state.count - 1 };\n  default:\n    return state;\n  }\n};\n\nexport default persistentReducer(counter);\n```\n\nNOTE: If you plan on minifying your code, or you want to use a name different from the reducer function name, you can pass a second parameter to `persistentReducer`.\n\n```js\nexport default persistentReducer(counter, 'counter');\n```\n\n## Caveat\n\nThe current behavior is to have a document relative to the reducer that looks like:\n\n``` js\n{\n  _id: 'reducerName', // the name of the reducer function\n  state: {}|[], // the state of the reducer\n  _rev: '' // pouchdb keeps track of the revisions\n}\n```\n\nNotice that if your reducer actually returns an array, and you want your elements to be stored in separate documents of a specific bucket, this is not yet supported.\n","maintainers":[{"name":"abhinavzspace","email":"abhinavzspace@gmail.com"}],"time":{"modified":"2022-06-12T14:14:28.706Z","created":"2016-10-05T07:00:44.940Z","0.1.0":"2016-10-05T07:00:44.940Z"},"homepage":"https://github.com/vicentedealencar/redux-pouchdb","keywords":["redux","react-component","pouchdb"],"repository":{"type":"git","url":"git+https://github.com/vicentedealencar/redux-pouchdb.git"},"author":{"name":"Vicente de Alencar"},"bugs":{"url":"https://github.com/vicentedealencar/redux-pouchdb/issues"},"license":"MIT","readmeFilename":"README.md"}