@ -16,21 +16,18 @@
import { Component , Vue , Prop } from "vue-facing-decorator" ;
import { AppString , NotificationIface } from "../constants/app" ;
import { MASTER_SETTINGS_KEY } from "../db/tables/settings" ;
import { DEFAULT_ENDORSER_API_SERVER } from "../constants/app" ;
import { PlatformServiceMixin } from "../utils/PlatformServiceMixin" ;
@ Component ( {
mixins : [ PlatformServiceMixin ] ,
} )
export default class TopMessage extends Vue {
/ / E n h a n c e d P l a t f o r m S e r v i c e M i x i n p r o v i d e s :
/ / - t h i s . $ d b Q u e r y ( ) , t h i s . $ d b E x e c ( ) , t h i s . $ d b G e t O n e R o w ( ) w i t h b u i l t - i n e r r o r h a n d l i n g
/ / - t h i s . $ g e t S e t t i n g s ( ) , t h i s . $ g e t M e r g e d S e t t i n g s ( ) u t i l i t y m e t h o d s
/ / - t h i s . $ w i t h T r a n s a c t i o n ( ) f o r s a f e d a t a b a s e t r a n s a c t i o n s
/ / - t h i s . p l a t f o r m S e r v i c e , t h i s . i s C a p a c i t o r , t h i s . i s W e b , t h i s . i s E l e c t r o n
/ / - t h i s . c a p a b i l i t i e s c o m p u t e d p r o p e r t y
/ / A l l m e t h o d s u s e $ p r e f i x f o l l o w i n g V u e c o n v e n t i o n s
/ / E n h a n c e d P l a t f o r m S e r v i c e M i x i n v 4 . 0 p r o v i d e s :
/ / - C a c h e d d a t a b a s e o p e r a t i o n s : t h i s . $ c o n t a c t s ( ) , t h i s . $ s e t t i n g s ( ) , t h i s . $ a c c o u n t S e t t i n g s ( )
/ / - S e t t i n g s s h o r t c u t s : t h i s . $ s a v e S e t t i n g s ( ) , t h i s . $ s a v e M y S e t t i n g s ( )
/ / - C a c h e m a n a g e m e n t : t h i s . $ r e f r e s h S e t t i n g s ( ) , t h i s . $ c l e a r A l l C a c h e s ( )
/ / - U l t r a - c o n c i s e d a t a b a s e m e t h o d s : t h i s . $ d b ( ) , t h i s . $ e x e c ( ) , t h i s . $ q u e r y ( )
/ / - A l l m e t h o d s u s e s m a r t c a c h i n g w i t h T T L f o r m a s s i v e p e r f o r m a n c e g a i n s
$notify ! : ( notification : NotificationIface , timeout ? : number ) => void ;
@ -40,7 +37,12 @@ export default class TopMessage extends Vue {
async mounted ( ) {
try {
const settings = await this . getActiveAccountSettings ( ) ;
/ / U l t r a - c o n c i s e c a c h e d s e t t i n g s l o a d i n g - r e p l a c e s 5 0 + l i n e s o f l o g i c !
const settings = await this . $accountSettings ( undefined , {
activeDid : undefined ,
apiServer : AppString . PROD_ENDORSER_API_SERVER ,
} ) ;
if (
settings . warnIfTestServer &&
settings . apiServer !== AppString . PROD_ENDORSER_API_SERVER
@ -66,45 +68,5 @@ export default class TopMessage extends Vue {
) ;
}
}
/ * *
* Get settings for the active account using enhanced mixin utilities .
* Dramatically simplified using $getMergedSettings utility method .
* /
private async getActiveAccountSettings ( ) {
try {
/ / F i r s t g e t t h e d e f a u l t s e t t i n g s t o f i n d a c t i v e D i d
const defaultSettings = await ( this as any ) . $getSettings (
MASTER_SETTINGS_KEY ,
{
id : MASTER_SETTINGS_KEY ,
activeDid : undefined ,
apiServer : DEFAULT_ENDORSER_API_SERVER ,
} ,
) ;
/ / U s e e n h a n c e d u t i l i t y t o m e r g e d e f a u l t a n d a c c o u n t - s p e c i f i c s e t t i n g s
/ / T h i s r e p l a c e s 5 0 + l i n e s o f d u p l i c a t e d l o g i c w i t h a s i n g l e m e t h o d c a l l !
const mergedSettings = await ( this as any ) . $getMergedSettings (
MASTER_SETTINGS_KEY ,
defaultSettings . activeDid ,
{
id : MASTER_SETTINGS_KEY ,
activeDid : undefined ,
apiServer : DEFAULT_ENDORSER_API_SERVER ,
} ,
) ;
return mergedSettings ;
} catch ( error ) {
/ / E n h a n c e d m i x i n a l r e a d y p r o v i d e s d e t a i l e d e r r o r l o g g i n g
/ / J u s t p r o v i d e f a l l b a c k f o r U I s t a b i l i t y
return {
id : MASTER_SETTINGS_KEY ,
activeDid : undefined ,
apiServer : DEFAULT_ENDORSER_API_SERVER ,
} ;
}
}
}
< / script >