Arpith Siromoney 💬

Reading everyone you love

I’m building an app to let you share your notes called Constellational (sign up here if you want this). Earlier I had talked about what kinds of posts my app supports, and yesterday I wrote about what goes into sharing a post. Right now posts are shared via a link that leads to a webpage, but I want to change that. I’m working on reading other people’s posts in the app itself(without having to go to their webpage). To do this, my flux store has to support multiple users (not just your posts).


As you can see from this commit, things changed quite a bit — however, the main idea is that _posts[username][postURL] is where posts stay, and _users[username] gets you the list of postURLs for that user. Otherwise, it’s pretty much the same code!

You do need to initialise _posts[username] (as an empty object) when fetching posts:

function fetchFromServer(username) {
 if (!username) username = SettingStore.getUsername();
 return fetchUser(username).then((user) => {
   _users[username] = user;
   var promiseArr = user.posts.map(url => fetchPost(username, url));
   return Promise.all(promiseArr);
 }).then((posts) => {
   if (!_posts[username]) _posts[username] = {};
   posts.map((post) => {
     _posts[username][post.url] = post;
   });
   PostStore.emitChange();
 });
}

Still to come: actually handling URL’s for other users! This is one step in the quest towards universal links and Google app indexing.