persistentCollectionReducer: Only top level objects persisted. #34
Open
Description
I have a following contrived reducer where state resulting from ADD_TODO
action is correctly persisted. However, state resulting from COMPLETED
action is not persisted. As you can see my initialState is [ ]
. FWIW, state in redux is as expected but not synced with db
for COMPLETED
action.
import { persistentCollectionReducer } from "redux-pouchdb";
import PouchDB from "pouchdb-browser";
const db = new PouchDB("todos");
const initialState = [];
const todosReducer = (state = initialState, { type, payload }) => {
switch (type) {
case "ADD_TODO":
return [
...state,
{
_id: Math.random().toString(8),
...payload,
},
];
case "COMPLETED":
return state.map((item) => {
if (item._id === payload.id) {
item.completed = !item.completed;
}
return item;
});
default:
return state;
}
};
export default persistentCollectionReducer(db, "todos")(todosReducer);
Metadata
Assignees
Labels
No labels