pinafore/src/routes/_store/computations/timelineComputations.js

43 lines
1.7 KiB
JavaScript
Raw Normal View History

import { get } from '../../_utils/lodash-lite'
import { getFirstIdFromItemSummaries, getLastIdFromItemSummaries } from '../../_utils/getIdFromItemSummaries'
function computeForTimeline (store, key, defaultValue) {
store.compute(key,
['currentInstance', 'currentTimeline', `timelineData_${key}`],
2018-05-07 02:35:22 +02:00
(currentInstance, currentTimeline, root) => (
get(root, [currentInstance, currentTimeline], defaultValue)
)
)
}
2018-02-09 07:29:29 +01:00
export function timelineComputations (store) {
computeForTimeline(store, 'timelineItemSummaries', null)
computeForTimeline(store, 'timelineItemSummariesToAdd', null)
computeForTimeline(store, 'runningUpdate', false)
computeForTimeline(store, 'lastFocusedElementId', null)
computeForTimeline(store, 'ignoreBlurEvents', false)
computeForTimeline(store, 'showHeader', false)
computeForTimeline(store, 'shouldShowHeader', false)
computeForTimeline(store, 'timelineItemSummariesAreStale', false)
store.compute('firstTimelineItemId', ['timelineItemSummaries'], (timelineItemSummaries) => (
getFirstIdFromItemSummaries(timelineItemSummaries)
))
store.compute('lastTimelineItemId', ['timelineItemSummaries'], (timelineItemSummaries) => (
getLastIdFromItemSummaries(timelineItemSummaries)
))
2018-01-28 22:09:39 +01:00
store.compute('numberOfNotifications',
[`timelineData_timelineItemSummariesToAdd`, 'currentInstance'],
(root, currentInstance) => (
(root && root[currentInstance] && root[currentInstance].notifications &&
root[currentInstance].notifications.length) || 0
)
)
store.compute('hasNotifications',
['numberOfNotifications', 'currentPage'],
(numberOfNotifications, currentPage) => currentPage !== 'notifications' && !!numberOfNotifications
)
2018-02-09 07:29:29 +01:00
}