Skip to content

Commit

Permalink
use mergeArray in message-registry
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Sep 24, 2020
1 parent 96f48a9 commit 8db6c1c
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/message-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { CompositeDisposable, Emitter } from 'atom'
import debounce from 'lodash/debounce'
import type { Disposable, TextBuffer } from 'atom'
import { messageKey, updateKeys, createKeyMessageMap, flagMessages } from './helpers'
import { messageKey, updateKeys, createKeyMessageMap, flagMessages, mergeArray } from './helpers'
import type { MessagesPatch, Message, Linter } from './types'

type Linter$Message$Map = {
Expand Down Expand Up @@ -52,26 +52,26 @@ class MessageRegistry {
const result = { added: [], removed: [], messages: [] }
for (const entry of this.messagesMap) {
if (entry.deleted) {
result.removed = result.removed.concat(entry.oldMessages)
mergeArray(result.removed, entry.oldMessages)
this.messagesMap.delete(entry)
continue
}
if (!entry.changed) {
result.messages = result.messages.concat(entry.oldMessages)
mergeArray(result.messages, entry.oldMessages)
continue
}
entry.changed = false
if (!entry.oldMessages.length) {
// All messages are new, no need to diff
// NOTE: No need to add .key here because normalizeMessages already does that
result.added = result.added.concat(entry.messages)
result.messages = result.messages.concat(entry.messages)
mergeArray(result.added, entry.messages)
mergeArray(result.messages, entry.messages)
entry.oldMessages = entry.messages
continue
}
if (!entry.messages.length) {
// All messages are old, no need to diff
result.removed = result.removed.concat(entry.oldMessages)
mergeArray(result.removed, entry.oldMessages)
entry.oldMessages = []
continue
}
Expand All @@ -90,10 +90,10 @@ class MessageRegistry {
// update the result and cache
if (flaggedMessages !== null) {
const { oldKept, oldRemoved, newAdded } = flaggedMessages
result.added = result.added.concat(newAdded)
result.removed = result.removed.concat(oldRemoved)
mergeArray(result.added, newAdded)
mergeArray(result.removed, oldRemoved)
const allThisEntry = newAdded.concat(oldKept)
result.messages = result.messages.concat(allThisEntry)
mergeArray(result.messages, allThisEntry)
entry.oldMessages = allThisEntry // update chache
}
}
Expand Down

0 comments on commit 8db6c1c

Please sign in to comment.