Use OrderedSet
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
b01b175fdc
commit
0877574c28
1 changed files with 20 additions and 24 deletions
|
@ -71,15 +71,13 @@ const makeMapStateToProps = () => {
|
||||||
(_, { id }) => id,
|
(_, { id }) => id,
|
||||||
state => state.getIn(['contexts', 'inReplyTos']),
|
state => state.getIn(['contexts', 'inReplyTos']),
|
||||||
], (statusId, inReplyTos) => {
|
], (statusId, inReplyTos) => {
|
||||||
let ancestorsIds = Immutable.List();
|
let ancestorsIds = Immutable.OrderedSet();
|
||||||
ancestorsIds = ancestorsIds.withMutations(mutable => {
|
let id = statusId;
|
||||||
let id = statusId;
|
|
||||||
|
|
||||||
while (id) {
|
while (id) {
|
||||||
mutable.unshift(id);
|
ancestorsIds = Immutable.OrderedSet([id]).union(ancestorsIds);
|
||||||
id = inReplyTos.get(id);
|
id = inReplyTos.get(id);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
return ancestorsIds;
|
return ancestorsIds;
|
||||||
});
|
});
|
||||||
|
@ -88,25 +86,23 @@ const makeMapStateToProps = () => {
|
||||||
(_, { id }) => id,
|
(_, { id }) => id,
|
||||||
state => state.getIn(['contexts', 'replies']),
|
state => state.getIn(['contexts', 'replies']),
|
||||||
], (statusId, contextReplies) => {
|
], (statusId, contextReplies) => {
|
||||||
let descendantsIds = Immutable.List();
|
let descendantsIds = Immutable.OrderedSet();
|
||||||
descendantsIds = descendantsIds.withMutations(mutable => {
|
const ids = [statusId];
|
||||||
const ids = [statusId];
|
|
||||||
|
|
||||||
while (ids.length > 0) {
|
while (ids.length > 0) {
|
||||||
let id = ids.shift();
|
let id = ids.shift();
|
||||||
const replies = contextReplies.get(id);
|
const replies = contextReplies.get(id);
|
||||||
|
|
||||||
if (statusId !== id) {
|
if (statusId !== id) {
|
||||||
mutable.push(id);
|
descendantsIds = descendantsIds.union([id]);
|
||||||
}
|
|
||||||
|
|
||||||
if (replies) {
|
|
||||||
replies.reverse().forEach(reply => {
|
|
||||||
ids.unshift(reply);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
if (replies) {
|
||||||
|
replies.reverse().forEach(reply => {
|
||||||
|
ids.unshift(reply);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return descendantsIds;
|
return descendantsIds;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue