Hi there,
I’m using the meteor-react-native
package suggested here, while also using redux-persist
to load the minimongo-cache on app startup should the user have gone offline. The way I load the Meteor data into Redux is through the following:
const ADDED = "ddp/added";
const CHANGED = "ddp/changed";
const REMOVED = "ddp/removed";
...
const onRehydration = (store) => {
const data = Meteor.getData();
const db = data && data.db;
if (db) {
_.each(store.getState(), (collectionData, collectionName) => {
if (!db[collectionName]) {
db.addCollection(collectionName);
}
const collectionArr = _.map(collectionData, (doc, _id) => {
doc._id = _id;
return doc;
});
if (
collectionArr.every((doc) => typeof doc._id !== "undefined")
) {
db[collectionName].upsert(collectionArr);
}
});
}
};
...
export default () => {
....
let persistor = persistStore(store, null, async () => {
onRehydration(store);
});
Meteor.ddp.on("added", (payload) => {
store.dispatch({ type: ADDED, payload });
});
Meteor.ddp.on("changed", (payload) => {
store.dispatch({ type: CHANGED, payload });
});
Meteor.ddp.on("removed", (payload) => {
store.dispatch({ type: REMOVED, payload });
});
return { store, persistor };
};
However, whenever I logout and then immediately log in again, neither Meteor.ddp.on("added")
or Meteor.ddp.on("changed")
are called to populate the redux store so I can use Redux Persist. I’m assuming it has something to do with the minimongo-cache
versions, but I’m unsure how I can create a fresh session on a new login. If I reload the app after having clicked “login”, everything works fine (as I’m assuming the minimongo-cache has cleared).
Thoughts? Suggestions?