Replace recursion in status mapStateToProps (#7645)

th-downstream
Eugen Rochko 7 years ago committed by GitHub
parent 8a3b9d26fb
commit 20a23c7d08

@ -62,31 +62,28 @@ const makeMapStateToProps = () => {
if (status) { if (status) {
ancestorsIds = ancestorsIds.withMutations(mutable => { ancestorsIds = ancestorsIds.withMutations(mutable => {
function addAncestor(id) { let id = status.get('in_reply_to_id');
if (id) {
const inReplyTo = state.getIn(['contexts', 'inReplyTos', id]);
while (id) {
mutable.unshift(id); mutable.unshift(id);
addAncestor(inReplyTo); id = state.getIn(['contexts', 'inReplyTos', id]);
} }
}
addAncestor(status.get('in_reply_to_id'));
}); });
descendantsIds = descendantsIds.withMutations(mutable => { 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]); const replies = state.getIn(['contexts', 'replies', id]);
if (replies) { if (replies) {
replies.forEach(reply => { replies.forEach(reply => {
mutable.push(reply); mutable.push(reply);
addDescendantOf(reply); ids.unshift(reply);
}); });
} }
} }
addDescendantOf(status.get('id'));
}); });
} }

Loading…
Cancel
Save