title: ngrx selecting data of specific object id with memoization method
body: <p>my question is regarding ngrx4 (with angular5).</p>
  
  <p>i am working on an app with the following data structure:</p>
  
  <pre><code>-&gt; store
  --&gt; forums: id, name
  --&gt; posts: id, message, forumid
  </code></pre>
  
  <p>when i present a post, i also present it's forum. so a post representation would be:</p>
  
  <blockquote>
    <p>postid, message, forum.id, forum.name</p>
  </blockquote>
  
  <p>from ngrx example app i understand that the way to get forum's data is to:</p>
  
  <ol>
  <li>add selectedForumId to the forum state</li>
  <li>when fetching a post: dispatch event to update selectedForumId to the post's forumid</li>
  <li>select forum data by selectedForumId</li>
  </ol>
  
  <p>in code:</p>
  
  <p>home.component.ts:</p>
  
  <pre><code>  ngOnInit() {
      this.store.dispatch(new postActions.GetAllPostsAction());
      this.posts$ = store.select(fromReducers.getAllPosts);
    }
  </code></pre>
  
  <p>home.component.html:</p>
  
  <pre><code>&lt;post *ngFor="let post of (posts$|async)" [post]="post"&gt;&lt;/post&gt;
  </code></pre>
  
  <p>post.component.ts:</p>
  
  <pre><code>  @Input() post: Post;
    ngOnInit() {
      this.store.dispatch(new forumActions.SelectForumAction(this.post.forumId));
      this.forum$ = this.store.select(fromReducers.getSelectedForum);
    }
  </code></pre>
  
  <p>forum.reducer.ts:</p>
  
  <pre><code>export interface State extends EntityState&lt;Forum&gt; {
      selectedForumId: number | null;
  };
  
  export function reducer(state = initialState, action: ForumActions): State {
      switch (action.type) {
          case ForumActionTypes.SELECT_FORUM:
              return {
                  ...state,
                  selectedForumId: action.payload,
              };
  ...
  export const getSelectedForumId = (state: State) =&gt; state.selectedForumId;
  </code></pre>
  
  <p>reducers/index.ts:</p>
  
  <pre><code>export const selectForumState = createFeatureSelector&lt;fromForum.State&gt;('forums');
  export const selectForumEntities = createSelector(selectForumState, fromForum.selectForumEntities);
  export const selectedForumId = createSelector(selectForumState, fromForum.getSelectedForumId);
  export const getSelectedForum = createSelector&lt;State, any, any, Forum&gt;(selectForumEntities, selectedForumId,
      (entities, id) =&gt; entities[id]
  );
  </code></pre>
  
  <p><strong>The Question -</strong></p>
  
  <p>my problem with this a approach is that if i have 10 posts in a page it means i would dispatch the action that updates selectedForumId 10 times and it feels wrong.</p>
  
  <p>is there a better-practice approach i can use, that will still use the advantage of createSelector which creates a memoized selector?</p>