chore: bunch of improvements
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import { defineStore } from 'pinia'
|
||||
import { serviceService } from '../services'
|
||||
import { ServiceObject } from '../models/service'
|
||||
import type {
|
||||
ServiceIdentifier,
|
||||
ServiceLocation,
|
||||
SourceSelector,
|
||||
ServiceIdentity,
|
||||
@@ -59,13 +60,23 @@ export const useServicesStore = defineStore('mailServicesStore', () => {
|
||||
* @returns Service object or null
|
||||
*/
|
||||
function service(provider: string, identifier: string | number, retrieve: boolean = false): ServiceObject | null {
|
||||
const key = identifierKey(provider, identifier)
|
||||
if (retrieve === true && !_services.value[key]) {
|
||||
console.debug(`[Mail Manager][Store] - Force fetching service "${key}"`)
|
||||
return serviceByIdentifier(identifierKey(provider, identifier), retrieve)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a service from store by its unique identifier, with optional retrieval
|
||||
*
|
||||
* @param identifier - unique service identifier
|
||||
* @param retrieve - Retrieve behavior: true = fetch if missing or refresh, false = cache only
|
||||
* @returns Service object or null
|
||||
*/
|
||||
function serviceByIdentifier(identifier: ServiceIdentifier, retrieve: boolean = false): ServiceObject | null {
|
||||
if (retrieve === true && !_services.value[identifier]) {
|
||||
console.debug(`[Mail Manager][Store] - Force fetching service "${identifier}"`)
|
||||
fetch(provider, identifier)
|
||||
}
|
||||
|
||||
return _services.value[key] || null
|
||||
return _services.value[identifier] ?? null
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -341,6 +352,7 @@ export const useServicesStore = defineStore('mailServicesStore', () => {
|
||||
|
||||
// Actions
|
||||
service,
|
||||
serviceByIdentifier,
|
||||
serviceForAddress,
|
||||
list,
|
||||
fetch,
|
||||
|
||||
Reference in New Issue
Block a user