pinafore/routes/_store/mixins/autosuggestMixins.js
2018-05-06 16:25:17 -07:00

20 lines
653 B
JavaScript

export function autosuggestMixins (Store) {
Store.prototype.setForAutosuggest = function (instanceName, realm, obj) {
let valuesToSet = {}
for (let key of Object.keys(obj)) {
let rootKey = `autosuggestData_${key}`
let root = this.get()[rootKey] || {}
let instanceData = root[instanceName] = root[instanceName] || {}
instanceData[realm] = obj[key]
valuesToSet[rootKey] = root
}
this.set(valuesToSet)
}
Store.prototype.setForCurrentAutosuggest = function (obj) {
let { currentInstance, currentComposeRealm } = this.get()
this.setForAutosuggest(currentInstance, currentComposeRealm, obj)
}
}