Hello, first of all great job, thanks for this library!
I do not understand why db always triggers change event when I have two persistentDocumentReducer, maybe I'm doing something wrong ?
The problem is only in the "redux-pouchdb" version: "^ 1.0.0-rc.2"
PS: now use version 0.1. * there is no such problem
precondition:
lib version: "redux-pouchdb": "^1.0.0-rc.2",
configureStore
`
import { createStore, applyMiddleware, compose } from 'redux';
import { routerMiddleware } from 'react-router-redux';
import createSagaMiddleware from 'redux-saga';
import dynamicMiddlewares from 'redux-dynamic-middlewares';
import { persistStore } from 'redux-pouchdb';
import createReducer from './reducers';
const sagaMiddleware = createSagaMiddleware();
export default function configureStore(initialState = {}, history) {
const middlewares = [
sagaMiddleware,
routerMiddleware(history),
dynamicMiddlewares,
];
const enhancers = [applyMiddleware(...middlewares)];
const composeEnhancers =
process.env.NODE_ENV !== 'production' &&
typeof window === 'object' &&
window.REDUX_DEVTOOLS_EXTENSION_COMPOSE
? window.REDUX_DEVTOOLS_EXTENSION_COMPOSE({
shouldHotReload: false,
})
: compose;
const store = createStore(
createReducer(),
initialState,
composeEnhancers(...enhancers),
);
persistStore(store);
store.runSaga = sagaMiddleware.run;
store.injectedReducers = {};
store.injectedSagas = {};
if (module.hot) {
module.hot.accept('./reducers', () => {
store.replaceReducer(createReducer(store.injectedReducers));
});
}
return store;
}`
first reducer
`
import { persistentDocumentReducer } from 'redux-pouchdb';
import { appState as appStateDb } from 'configureDb';
import { isNull } from 'lodash';
import {
DEFAULT_ACTION,
SWITCH_CHANGE_ACTION,
CHECKBOX_CHANGE_ACTION,
RESET_DEFAULT_ACTION,
TOGGLE_DIALOG_ACTION,
LOAD_AND_SHOW_RESERVATION_DIALOG_ACTION,
} from './constants';
const initialState = {
loadDefaultAction: true,
checkedIds: [],
switchIds: [],
events: {},
checkedEvents: [],
isDialogLoad: false,
isDialogOpen: false,
reservationRange: null,
};
function reducer(state = initialState, action) {
switch (action.type) {
case RESET_DEFAULT_ACTION: {
return {
...state,
loadDefaultAction: true,
};
}
case DEFAULT_ACTION: {
const { checkedIds, events, checkedEvents } = action,
result = {
...state,
checkedIds,
events,
checkedEvents,
loadDefaultAction: false,
};
return result;
}
case SWITCH_CHANGE_ACTION: {
const { checkedIds, switchIds, checkedEvents } = action,
result = {
...state,
checkedIds,
switchIds,
};
if (!isNull(checkedEvents)) {
result.checkedEvents = checkedEvents;
}
return result;
}
case CHECKBOX_CHANGE_ACTION: {
const { checkedIds, checkedEvents } = action,
result = {
...state,
checkedIds,
checkedEvents,
};
return result;
}
case TOGGLE_DIALOG_ACTION: {
return {
...state,
isDialogOpen: action.value,
};
}
case LOAD_AND_SHOW_RESERVATION_DIALOG_ACTION: {
const { isDialogOpen, isDialogLoad, reservationRange } = action;
return {
...state,
isDialogOpen,
isDialogLoad,
reservationRange,
};
}
default:
return state;
}
}
const reducerName = 'uniqueReducerName';
export default persistentDocumentReducer(appStateDb, reducerName)(reducer);
`
second reducer
`
import { persistentDocumentReducer } from 'redux-pouchdb';
import { appState as appStateDb } from 'configureDb';
import { SET_TAB_VALUE, HANDLE_DRAWER_TOGGLE } from './constants';
const initialState = {
open: false,
tabValue: 0,
};
function appReducer(state = initialState, action) {
switch (action.type) {
case SET_TAB_VALUE: {
return {
...state,
tabValue: action.value,
};
}
case HANDLE_DRAWER_TOGGLE: {
return {
...state,
open: !state.open,
};
}
default:
return state;
}
}
const reducerName = 'app';
export default persistentDocumentReducer(appStateDb, reducerName)(appReducer);
`
When I turn to the page where two reducers are connected at once (dynamically connected), change event are always triggered
pouchdb:api log
pouchdb:api /app-state-522fc10d-a59a-4766-89c2-faa280ab06fd +1ms put success {ok: true, id: "apartmentReservationPage", rev: "618-01871ea6836aeb5f595b778fe8a8ecb4"} browser.js:133 pouchdb:api /app-state-522fc10d-a59a-4766-89c2-faa280ab06fd +1ms get apartmentReservationPage browser.js:133 pouchdb:api /app-state-522fc10d-a59a-4766-89c2-faa280ab06fd +6ms get success {state: {…}, _id: "apartmentReservationPage", _rev: "618-01871ea6836aeb5f595b778fe8a8ecb4"} browser.js:133 pouchdb:api /app-state-522fc10d-a59a-4766-89c2-faa280ab06fd +1ms put {state: {…}, _id: "apartmentReservationPage", _rev: "618-01871ea6836aeb5f595b778fe8a8ecb4"} browser.js:133 pouchdb:api /app-state-522fc10d-a59a-4766-89c2-faa280ab06fd +2ms bulkDocs {docs: Array(1)} {} browser.js:133 pouchdb:api /app-state-522fc10d-a59a-4766-89c2-faa280ab06fd +16ms bulkDocs success [{…}] browser.js:133 pouchdb:api /app-state-522fc10d-a59a-4766-89c2-faa280ab06fd +0ms put success {ok: true, id: "apartmentReservationPage", rev: "619-2244c2adf65b7a53f9b2d8f7e787643a"} browser.js:133 pouchdb:api /app-state-522fc10d-a59a-4766-89c2-faa280ab06fd +2ms get apartmentReservationPage browser.js:133 pouchdb:api /app-state-522fc10d-a59a-4766-89c2-faa280ab06fd +5ms get success {state: {…}, _id: "apartmentReservationPage", _rev: "619-2244c2adf65b7a53f9b2d8f7e787643a"} browser.js:133 pouchdb:api /app-state-522fc10d-a59a-4766-89c2-faa280ab06fd +1ms put {state: {…}, _id: "apartmentReservationPage", _rev: "619-2244c2adf65b7a53f9b2d8f7e787643a"} browser.js:133 pouchdb:api /app-state-522fc10d-a59a-4766-89c2-faa280ab06fd +1ms bulkDocs {docs: Array(1)} {} browser.js:133 pouchdb:api /app-state-522fc10d-a59a-4766-89c2-faa280ab06fd +9ms bulkDocs success [{…}] browser.js:133 pouchdb:api /app-state-522fc10d-a59a-4766-89c2-faa280ab06fd +0ms put success {ok: true, id: "apartmentReservationPage", rev: "620-46d2e402895149c18488ba8a33ce9c59"} browser.js:133 pouchdb:api /app-state-522fc10d-a59a-4766-89c2-faa280ab06fd +2ms get apartmentReservationPage browser.js:133 pouchdb:api /app-state-522fc10d-a59a-4766-89c2-faa280ab06fd +4ms get success {state: {…}, _id: "apartmentReservationPage", _rev: "620-46d2e402895149c18488ba8a33ce9c59"} browser.js:133 pouchdb:api /app-state-522fc10d-a59a-4766-89c2-faa280ab06fd +2ms put {state: {…}, _id: "apartmentReservationPage", _rev: "620-46d2e402895149c18488ba8a33ce9c59"} browser.js:133 pouchdb:api /app-state-522fc10d-a59a-4766-89c2-faa280ab06fd +1ms bulkDocs {docs: Array(1)} {} browser.js:133 pouchdb:api /app-state-522fc10d-a59a-4766-89c2-faa280ab06fd +15ms bulkDocs success [{…}] browser.js:133 pouchdb:api /app-state-522fc10d-a59a-4766-89c2-faa280ab06fd +0ms put success {ok: true, id: "apartmentReservationPage", rev: "621-9d4dd0b9d2290c248e0c5ecb0a5fe6cb"} browser.js:133 pouchdb:api /app-state-522fc10d-a59a-4766-89c2-faa280ab06fd +1ms get apartmentReservationPage browser.js:133 pouchdb:api /app-state-522fc10d-a59a-4766-89c2-faa280ab06fd +5ms get success {state: {…}, _id: "apartmentReservationPage", _rev: "621-9d4dd0b9d2290c248e0c5ecb0a5fe6cb"} browser.js:133 pouchdb:api /app-state-522fc10d-a59a-4766-89c2-faa280ab06fd +1ms put {state: {…}, _id: "apartmentReservationPage", _rev: "621-9d4dd0b9d2290c248e0c5ecb0a5fe6cb"} browser.js:133 pouchdb:api /app-state-522fc10d-a59a-4766-89c2-faa280ab06fd +1ms bulkDocs {docs: Array(1)} {} browser.js:133 pouchdb:api /app-state-522fc10d-a59a-4766-89c2-faa280ab06fd +11ms bulkDocs success [{…}] browser.js:133 pouchdb:api /app-state-522fc10d-a59a-4766-89c2-faa280ab06fd +1ms put success {ok: true, id: "apartmentReservationPage", rev: "622-edcc4b3a150ff7b865687b8a297d5045"}