Commit 5ffeba96 authored by Robert Knight's avatar Robert Knight

Simplify code using `filter`/`map`

This makes it more obvious what is going on at a glance. Refactoring the
code in this way revealed to TS a hazard where `newGroupId` could, at
least based only on local reasoning, be null. In practice this shouldn't
happen due to the contexts when the method is called, but I've added a
check to be safe and keep TS happy.
parent 97eae5d4
...@@ -446,17 +446,13 @@ export class GroupsService { ...@@ -446,17 +446,13 @@ export class GroupsService {
const newGroupId = this._store.focusedGroupId(); const newGroupId = this._store.focusedGroupId();
const groupHasChanged = prevGroupId !== newGroupId && prevGroupId !== null; const groupHasChanged = prevGroupId !== newGroupId && prevGroupId !== null;
if (groupHasChanged) { if (groupHasChanged && newGroupId) {
// Move any top-level new annotations to the newly-focused group. // Move any top-level new annotations to the newly-focused group.
// Leave replies where they are. // Leave replies where they are.
const updatedAnnotations = []; const updatedAnnotations = this._store
this._store.newAnnotations().forEach(annot => { .newAnnotations()
if (!isReply(annot)) { .filter(ann => !isReply(ann))
updatedAnnotations.push( .map(ann => ({ ...ann, group: newGroupId }));
Object.assign({}, annot, { group: newGroupId })
);
}
});
if (updatedAnnotations.length) { if (updatedAnnotations.length) {
this._store.addAnnotations(updatedAnnotations); this._store.addAnnotations(updatedAnnotations);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment