I am trying to figure out how to structure my application, for example, I have a User model, common user content to track the loading of all users so far and some UI-related stores like FriendList, PendingFriendList, BlockedUserList, LikedUserList, etc. .:
class User { id; @observable name; @observable avatar; // others functions and fields } class UserStore { @observable users = []; function resolve(id) { /*return by id*/} function createOrUpdateUser(json) { /* add user to this.users */ } } class FriendStore { @observable users = []; hasNextPage = true; currentPage = null; function loadNextPage(page) { api.loadFriends(page >= 0 ? page : this.currentPage + 1).then( users => { users.forEach( user => { this.users.push( UserStore.createOrUpdateUser(user) ) }) }) } } class PendingFriendUsers { @observable users = []; @observable query = null; hasNextPage = true; currentPage = null; function loadNextPage(page) { // more or less like FriendStore } } class BlockedUserStore { // more or less like FriendStore }
My question is: is this the way? Or is there a better way?
javascript reactjs redux mobx
Maximiliano guzenski
source share