2019-05-25 13:21:36 -07:00
|
|
|
import { get } from '../../_utils/lodash-lite'
|
|
|
|
|
|
2018-03-03 14:15:50 -08:00
|
|
|
export function instanceMixins (Store) {
|
2018-03-03 14:51:48 -08:00
|
|
|
Store.prototype.setComposeData = function (realm, obj) {
|
2018-04-19 09:37:05 -07:00
|
|
|
let { composeData, currentInstance } = this.get()
|
|
|
|
|
let instanceNameData = composeData[currentInstance] = composeData[currentInstance] || {}
|
2018-03-03 14:51:48 -08:00
|
|
|
instanceNameData[realm] = Object.assign(instanceNameData[realm] || {}, obj)
|
2018-08-29 21:42:57 -07:00
|
|
|
this.set({ composeData })
|
2018-03-03 14:15:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Store.prototype.getComposeData = function (realm, key) {
|
2018-04-19 09:37:05 -07:00
|
|
|
let { composeData, currentInstance } = this.get()
|
|
|
|
|
return composeData[currentInstance] &&
|
|
|
|
|
composeData[currentInstance][realm] &&
|
|
|
|
|
composeData[currentInstance][realm][key]
|
2018-03-03 14:15:50 -08:00
|
|
|
}
|
2018-03-04 16:27:15 -08:00
|
|
|
|
|
|
|
|
Store.prototype.clearComposeData = function (realm) {
|
2018-04-19 09:37:05 -07:00
|
|
|
let { composeData, currentInstance } = this.get()
|
|
|
|
|
if (composeData && composeData[currentInstance]) {
|
|
|
|
|
delete composeData[currentInstance][realm]
|
2018-03-04 16:27:15 -08:00
|
|
|
}
|
2018-08-29 21:42:57 -07:00
|
|
|
this.set({ composeData })
|
2018-03-04 16:27:15 -08:00
|
|
|
}
|
2019-05-25 13:21:36 -07:00
|
|
|
|
|
|
|
|
Store.prototype.getInstanceSetting = function (instanceName, settingName, defaultValue) {
|
|
|
|
|
let { instanceSettings } = this.get()
|
|
|
|
|
return get(instanceSettings, [instanceName, settingName], defaultValue)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Store.prototype.setInstanceSetting = function (instanceName, settingName, value) {
|
|
|
|
|
let { instanceSettings } = this.get()
|
|
|
|
|
if (!instanceSettings[instanceName]) {
|
|
|
|
|
instanceSettings[instanceName] = {}
|
|
|
|
|
}
|
|
|
|
|
instanceSettings[instanceName][settingName] = value
|
|
|
|
|
this.set({ instanceSettings })
|
|
|
|
|
}
|
2018-03-03 14:15:50 -08:00
|
|
|
}
|