diff options
| author | taehoon <th.dev91@gmail.com> | 2019-07-25 08:03:41 -0400 |
|---|---|---|
| committer | taehoon <th.dev91@gmail.com> | 2019-07-25 08:03:41 -0400 |
| commit | 65ef03931661561db0791ee7d560292dda6b7d48 (patch) | |
| tree | 0ad8fe6c512aa6161aa82ea168670ee3d77cfd63 /src | |
| parent | 53c9517a4aeae1158a95e3b9c6d6d89e3a7e0ee9 (diff) | |
add unit test for elimination logic
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/timeline/timeline.js | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/components/timeline/timeline.js b/src/components/timeline/timeline.js index a5c6418b..aac3869f 100644 --- a/src/components/timeline/timeline.js +++ b/src/components/timeline/timeline.js @@ -1,7 +1,20 @@ import Status from '../status/status.vue' import timelineFetcher from '../../services/timeline_fetcher/timeline_fetcher.service.js' import Conversation from '../conversation/conversation.vue' -import { throttle } from 'lodash' +import { throttle, keyBy } from 'lodash' + +export const getExcludedStatusIdsByPinning = (statuses, pinnedStatusIds) => { + const ids = [] + if (pinnedStatusIds && pinnedStatusIds.length > 0) { + for (let status of statuses) { + if (!pinnedStatusIds.includes(status.id)) { + break + } + ids.push(status.id) + } + } + return ids +} const Timeline = { props: [ @@ -43,16 +56,9 @@ const Timeline = { }, // id map of statuses which need to be hidden in the main list due to pinning logic excludedStatusIdsObject () { - const result = {} - if (this.pinnedStatusIds && this.pinnedStatusIds.length > 0) { - for (let status of this.timeline.visibleStatuses) { - if (!this.pinnedStatusIds.includes(status.id)) { - break - } - result[status.id] = true - } - } - return result + const ids = getExcludedStatusIdsByPinning(this.timeline.visibleStatuses, this.pinnedStatusIds) + // Convert id array to object + return keyBy(ids, id => id) } }, components: { |
