pinafore/routes/_store/mixins/statusMixins.js

30 lines
1 KiB
JavaScript
Raw Normal View History

2018-03-21 00:41:39 +00:00
function getStatusModifications (store, instanceName) {
let { statusModifications } = store.get()
2018-03-21 00:41:39 +00:00
statusModifications[instanceName] = statusModifications[instanceName] || {
favorites: {},
reblogs: {},
pins: {}
2018-03-21 00:41:39 +00:00
}
return statusModifications
}
function setStatusModification (store, instanceName, statusId, key, value) {
let statusModifications = getStatusModifications(store, instanceName)
statusModifications[instanceName][key][statusId] = value
store.set({ statusModifications })
}
2018-03-21 00:41:39 +00:00
export function statusMixins (Store) {
Store.prototype.setStatusFavorited = function (instanceName, statusId, favorited) {
setStatusModification(this, instanceName, statusId, 'favorites', favorited)
2018-03-21 00:41:39 +00:00
}
Store.prototype.setStatusReblogged = function (instanceName, statusId, reblogged) {
setStatusModification(this, instanceName, statusId, 'reblogs', reblogged)
}
Store.prototype.setStatusPinned = function (instanceName, statusId, pinned) {
setStatusModification(this, instanceName, statusId, 'pins', pinned)
2018-03-21 00:41:39 +00:00
}
}