Bug 1328822 - cache getSelectedRequest with reselect; r=jsnajdr
authorFred Lin <gasolin@mozilla.com>
Thu, 05 Jan 2017 17:10:25 +0800
changeset 456714 50ab4998bee758ab818fd1d415d43ccd8d7f81f4
parent 456713 f43da8b320ae38974744f380c461c2efbc3b97a1
child 456715 53193729a50b40c00889b1fa07df8dffab7781f9
child 457032 801e4543e990929e6bb076a032774b788e612937
push id40575
push userjwwang@mozilla.com
push dateFri, 06 Jan 2017 02:27:46 +0000
reviewersjsnajdr
bugs1328822
milestone53.0a1
Bug 1328822 - cache getSelectedRequest with reselect; r=jsnajdr MozReview-Commit-ID: Eo6repa3Z8z
devtools/client/netmonitor/selectors/requests.js
--- a/devtools/client/netmonitor/selectors/requests.js
+++ b/devtools/client/netmonitor/selectors/requests.js
@@ -88,32 +88,35 @@ const getDisplayedRequestsSummary = crea
     return {
       count: requests.size,
       bytes: totalBytes,
       millis: totalMillis,
     };
   }
 );
 
+const getSelectedRequest = createSelector(
+  state => state.requests,
+  requests => {
+    if (!requests.selectedId) {
+      return null;
+    }
+
+    return requests.requests.find(r => r.id === requests.selectedId);
+  }
+);
+
 function getRequestById(state, id) {
   return state.requests.requests.find(r => r.id === id);
 }
 
 function getDisplayedRequestById(state, id) {
   return getDisplayedRequests(state).find(r => r.id === id);
 }
 
-function getSelectedRequest(state) {
-  if (!state.requests.selectedId) {
-    return null;
-  }
-
-  return getRequestById(state, state.requests.selectedId);
-}
-
 module.exports = {
-  getSortedRequests,
+  getDisplayedRequestById,
   getDisplayedRequests,
   getDisplayedRequestsSummary,
   getRequestById,
-  getDisplayedRequestById,
   getSelectedRequest,
+  getSortedRequests,
 };