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

29 lines
986 B
JavaScript
Raw Normal View History

import { get } from '../../_utils/lodash-lite.js'
2018-03-03 14:15:50 -08:00
export function instanceMixins (Store) {
Store.prototype.getInstanceSetting = function (instanceName, settingName, defaultValue) {
2019-08-03 13:49:37 -07:00
const { instanceSettings } = this.get()
return get(instanceSettings, [instanceName, settingName], defaultValue)
}
Store.prototype.setInstanceSetting = function (instanceName, settingName, value) {
2019-08-03 13:49:37 -07:00
const { instanceSettings } = this.get()
if (!instanceSettings[instanceName]) {
instanceSettings[instanceName] = {}
}
instanceSettings[instanceName][settingName] = value
this.set({ instanceSettings })
}
Store.prototype.setInstanceData = function (instanceName, key, value) {
2019-08-03 13:49:37 -07:00
const instanceData = this.get()[key] || {}
instanceData[instanceName] = value
this.set({ [key]: instanceData })
}
Store.prototype.getInstanceData = function (instanceName, key) {
2019-08-03 13:49:37 -07:00
const instanceData = this.get()[key] || {}
return instanceData[instanceName]
}
2018-03-03 14:15:50 -08:00
}