]> cat aescling's git repositories - mastodon.git/commitdiff
Replace recursion in status mapStateToProps (#7645)
authorEugen Rochko <eugen@zeonfederated.com>
Mon, 28 May 2018 00:42:06 +0000 (02:42 +0200)
committerGitHub <noreply@github.com>
Mon, 28 May 2018 00:42:06 +0000 (02:42 +0200)
app/javascript/mastodon/features/status/index.js

index 2e53dfa7e7cb30b99029270d7a75738978c91998..505a88a3ffbc3dec64a60545b1197fcd84302353 100644 (file)
@@ -62,31 +62,28 @@ const makeMapStateToProps = () => {
 
     if (status) {
       ancestorsIds = ancestorsIds.withMutations(mutable => {
-        function addAncestor(id) {
-          if (id) {
-            const inReplyTo = state.getIn(['contexts', 'inReplyTos', id]);
+        let id = status.get('in_reply_to_id');
 
-            mutable.unshift(id);
-            addAncestor(inReplyTo);
-          }
+        while (id) {
+          mutable.unshift(id);
+          id = state.getIn(['contexts', 'inReplyTos', id]);
         }
-
-        addAncestor(status.get('in_reply_to_id'));
       });
 
       descendantsIds = descendantsIds.withMutations(mutable => {
-        function addDescendantOf(id) {
+        const ids = [status.get('id')];
+
+        while (ids.length > 0) {
+          let id        = ids.shift();
           const replies = state.getIn(['contexts', 'replies', id]);
 
           if (replies) {
             replies.forEach(reply => {
               mutable.push(reply);
-              addDescendantOf(reply);
+              ids.unshift(reply);
             });
           }
         }
-
-        addDescendantOf(status.get('id'));
       });
     }