                (let [component-state (get component-states entity-id)
                      context (get-component-context state
                                                     entity-id
-                                                    component)
+                                                    component
+                                                    cached-get-component-state)
                      next-comp-state (component-fn entity-id
                                                    component-state
                                                    context)]

                  (if (vector? component)
                    (let [[component-id entity-id] component]
                      [(concat-keywords component-id entity-id)
                       (get-component-state state
                                            component-id
                                            entity-id)])
                    [component
                     (get-component-state state
                                          component
                                          entity-id)])))
        select-component-ids))

(defn get-component-context
  "Returns a hashmap of context for use with a component fn."
  [state entity-id component]
  (let [{:keys [subscriptions select-components]} component]
    (cond-> {}
      subscriptions (assoc :inbox

                            ;; the selectors, this
                            ;; ensures messages are
                            ;; per entity
                            (map #(vector % entity-id) subscriptions)))
      select-components (select-component-states state entity-id select-components cached-get-component-state))))

(defn system-next-state [state component-id]
  (let [entity-ids (entities-with-component state component-id)
        component-states (get-all-component-state state component-id)
        component (get-component state component-id)
        component-fn (:fn component)
        cached-get-component-state (memoize get-component-state)
        event-accum (transient [])]
    [(assoc-in
      state
