Improve Transactions handling #28

Merged
jacob1123 merged 10 commits from transactions into master 2022-02-28 14:28:39 +01:00
2 changed files with 6 additions and 4 deletions
Showing only changes of commit 27372199f7 - Show all commits

View File

@ -11,7 +11,10 @@ const app = createApp(App)
app.use(router) app.use(router)
const pinia = createPinia() const pinia = createPinia()
pinia.use(PiniaLogger()) pinia.use(PiniaLogger({
expanded: false,
showDuration: true
}))
app.use(pinia) app.use(pinia)
app.mount('#app') app.mount('#app')

View File

@ -11,9 +11,8 @@ const formatTime = (date = new Date()) => {
const hours = date.getHours().toString().padStart(2, '0'); const hours = date.getHours().toString().padStart(2, '0');
const minutes = date.getMinutes().toString().padStart(2, '0'); const minutes = date.getMinutes().toString().padStart(2, '0');
const seconds = date.getSeconds().toString().padStart(2, '0'); const seconds = date.getSeconds().toString().padStart(2, '0');
const milliseconds = date.getMilliseconds().toString();
return `${hours}:${minutes}:${seconds}:${milliseconds}`; return `${hours}:${minutes}:${seconds}`;
}; };
export interface PiniaLoggerOptions { export interface PiniaLoggerOptions {
@ -52,7 +51,7 @@ export const PiniaLogger = (config = defaultOptions) => (ctx: PiniaPluginContext
const duration = endTime - startTime + 'ms'; const duration = endTime - startTime + 'ms';
const nextState = cloneDeep(ctx.store.$state); const nextState = cloneDeep(ctx.store.$state);
const storeName = action.store.$id; const storeName = action.store.$id;
const title = `action 🍍 ${options.showStoreName ? `[${storeName}] ` : ''}${action.name} ${isError ? `failed after ${duration} ` : ''}@ ${formatTime()}`; const title = `${formatTime()} action 🍍 ${options.showStoreName ? `[${storeName}] ` : ''}${action.name} ${isError ? `failed after ` : ''}in ${duration}`;
console[options.expanded ? 'group' : 'groupCollapsed'](`%c${title}`, `font-weight: bold; ${isError ? 'color: #ed4981;' : ''}`); console[options.expanded ? 'group' : 'groupCollapsed'](`%c${title}`, `font-weight: bold; ${isError ? 'color: #ed4981;' : ''}`);
console.log('%cprev state', 'font-weight: bold; color: grey;', prevState); console.log('%cprev state', 'font-weight: bold; color: grey;', prevState);