Mapping large items to model #1968
Replies: 2 comments
-
much issue also is When api return normalized data and requires normalazed. |
Beta Was this translation helpful? Give feedback.
-
Hey @ParadiseFallen - I have a similar use case in my app. We have a pretty large payload from an internal API and load it into MST. We have an array of API data that needs to end up as an array of MST nodes. We've gone through two different iterations:
const Book = types.model({
id: types.numIdentifier,
title: types.string,
});
const BookStore = types.mpdel({
items : types.array(Book)
})
.actions((self)=>({
loadItems : flow(function* (){
const api = getEnv(self).services.bookService;
const response = yield bookService.loadAll();
const booksFromAPI = yield response.json() // Or whatever gets you an array of your objects
self.items = [...booksFromAPI]
})
})); I can't prove that this is the most performant way to do this, but we load thousands of domain-specific objects in one operation like that, and it happens quite fast in a React Native app. I don't expect this would be much of a performance problem, but if you have some performance monitoring that tells you it's a problem, I'd love to hear more and see if I can help you with a better solution. |
Beta Was this translation helpful? Give feedback.
-
Hi. In my app i has api service that ferch some data for me.
I has
Beta Was this translation helpful? Give feedback.
All reactions