From ef9d4f4e0615bcc42528e2e73ade0ba02baa3ed9 Mon Sep 17 00:00:00 2001
From: Eugen Rochko <eugen@zeonfederated.com>
Date: Sat, 8 Oct 2016 00:01:22 +0200
Subject: Use reselect to memoize denormalization in UI state Also upgrade
 react-redux to latest version. This is a performance update

---
 .../components/features/public_timeline/index.jsx  | 40 ++++++++++++----------
 1 file changed, 21 insertions(+), 19 deletions(-)

(limited to 'app/assets/javascripts/components/features/public_timeline/index.jsx')

diff --git a/app/assets/javascripts/components/features/public_timeline/index.jsx b/app/assets/javascripts/components/features/public_timeline/index.jsx
index dd31dc115..450725af6 100644
--- a/app/assets/javascripts/components/features/public_timeline/index.jsx
+++ b/app/assets/javascripts/components/features/public_timeline/index.jsx
@@ -1,32 +1,34 @@
-import { connect }        from 'react-redux';
-import PureRenderMixin    from 'react-addons-pure-render-mixin';
-import ImmutablePropTypes from 'react-immutable-proptypes';
-import StatusList         from '../../components/status_list';
-import Column             from '../ui/components/column';
-import Immutable          from 'immutable';
-import { selectStatus }   from '../../reducers/timelines';
+import { connect }         from 'react-redux';
+import PureRenderMixin     from 'react-addons-pure-render-mixin';
+import ImmutablePropTypes  from 'react-immutable-proptypes';
+import StatusList          from '../../components/status_list';
+import Column              from '../ui/components/column';
+import Immutable           from 'immutable';
+import { makeGetTimeline } from '../../selectors';
 import {
   updateTimeline,
   refreshTimeline,
   expandTimeline
-}                         from '../../actions/timelines';
-import { deleteStatus }   from '../../actions/statuses';
-import { replyCompose }   from '../../actions/compose';
+}                          from '../../actions/timelines';
+import { deleteStatus }    from '../../actions/statuses';
+import { replyCompose }    from '../../actions/compose';
 import {
   favourite,
   reblog,
   unreblog,
   unfavourite
-}                         from '../../actions/interactions';
+}                          from '../../actions/interactions';
 
-function selectStatuses(state) {
-  return state.getIn(['timelines', 'public'], Immutable.List()).map(id => selectStatus(state, id)).filterNot(status => status === null);
-};
+const makeMapStateToProps = () => {
+  const getTimeline = makeGetTimeline();
 
-const mapStateToProps = (state) => ({
-  statuses: selectStatuses(state),
-  me: state.getIn(['timelines', 'me'])
-});
+  const mapStateToProps = (state) => ({
+    statuses: getTimeline(state, 'public'),
+    me: state.getIn(['timelines', 'me'])
+  });
+
+  return mapStateToProps;
+};
 
 const PublicTimeline = React.createClass({
 
@@ -100,4 +102,4 @@ const PublicTimeline = React.createClass({
 
 });
 
-export default connect(mapStateToProps)(PublicTimeline);
+export default connect(makeMapStateToProps)(PublicTimeline);
-- 
cgit 

