pinafore/src/routes/_store/mixins/timelineMixins.js

41 lines
1.3 KiB
JavaScript
Raw Normal View History

import { pickBy, get } from '../../_utils/lodash-lite'
2018-03-10 07:31:26 +01:00
2018-03-03 23:15:50 +01:00
export function timelineMixins (Store) {
2018-01-28 22:09:39 +01:00
Store.prototype.setForTimeline = function (instanceName, timelineName, obj) {
let valuesToSet = {}
for (let key of Object.keys(obj)) {
let rootKey = `timelineData_${key}`
let root = this.get()[rootKey] || {}
let instanceData = root[instanceName] = root[instanceName] || {}
instanceData[timelineName] = obj[key]
valuesToSet[rootKey] = root
}
this.set(valuesToSet)
2018-01-28 22:09:39 +01:00
}
Store.prototype.getForTimeline = function (instanceName, timelineName, key) {
let rootKey = `timelineData_${key}`
let root = this.get()[rootKey]
2018-05-07 02:35:22 +02:00
return get(root, [instanceName, timelineName])
2018-01-28 22:09:39 +01:00
}
2018-03-11 01:21:10 +01:00
Store.prototype.getAllTimelineData = function (instanceName, key) {
let root = this.get()[`timelineData_${key}`] || {}
2018-03-11 01:21:10 +01:00
return root[instanceName] || {}
}
Store.prototype.setForCurrentTimeline = function (obj) {
let { currentInstance, currentTimeline } = this.get()
this.setForTimeline(currentInstance, currentTimeline, obj)
}
2018-03-10 07:31:26 +01:00
2018-03-11 01:21:10 +01:00
Store.prototype.getThreads = function (instanceName) {
let instanceData = this.getAllTimelineData(instanceName, 'timelineItemIds')
2018-03-10 07:31:26 +01:00
return pickBy(instanceData, (value, key) => {
return key.startsWith('status/')
})
}
2018-01-28 22:09:39 +01:00
}