Closed benhartouz closed 5 years ago
You should pass only raw objects to reducers. Working with database should be done either in middleware or saga. For example in our app when loading users, i load them in saga, then dispatch action with already pulled data that is handled by reducers layer.
@ivanpagac thanks for your comment, in fact, I passed it through redux-thunk. what do you mean by v raw objects?
@ivanpagac Thank you for your suggestion. Please elaborate. I am not familiar with saga.
Raw objects are not realm database connected objects?
I am using database objects in my reducer and things are slow.
"react-native": "0.55.4",
"react-native-router-flux": "4.0.0-beta.27",
"react-redux": "^5.0.7",
"realm": "^2.2.14",
"redux": "^3.7.2",
"redux-thunk": "^2.3.0",
@esutton can provide a sample of your code, Now we are building the application that gets data using API or Local database, but we have troubles with Realm object when we passed to store. In fact, I did some hack to my code, I passed a callback to my action to get the result of realm.
export const fetch_wokrspaces = (cb = () => {}) => {
return (dispatch, getState) => {
let con = true;
if(con){
// get data from api using axios
}else{
let users = realm.objects("User");
cb(users);
}
}
};
@benhartouz I’m also using Realm and Redux on projects and in my case, I use the thunks/sagas to write API responses to the Realm database only and, on the Containers, I just make the queries to the Realm database and make them listen for live changes. With this behavior, I only use Redux for stuff that I don’t need to store on device and which is shared along different Containers.
https://github.com/lolatravel/realm-react-redux is not supported or endorsed by us but might be worth a try.
Hey - looks like you forgot to add a T:* label - could you please add one?
Goals
In fact, I'm building a react native application and i'm using Realm as database and also I'm using redux to manage state, but I find a problem when I pass realm object through reducers my application goes slow.
Expected Results
Getting and parsing data
Actual Results
Slower navigation of react native application
Code Sample
Version of Realm and Tooling