refactor vuex
This commit is contained in:
1 parent
9c69e96416
commit
565b367c59
20 files changed
+264
-178
No files matched your search
@@ -1,26 +0,0 @@
|
||||
import { IApplication } from '@/operators';
|
||||
import { Module } from 'vuex';
|
||||
import { IChatState, Status } from './models';
|
||||
|
||||
export const chat: Module<IChatState, any> = {
|
||||
namespaced: true,
|
||||
state(): IChatState {
|
||||
return {
|
||||
applications: undefined,
|
||||
applicationsStatus: undefined
|
||||
};
|
||||
},
|
||||
mutations: {
|
||||
setApplications(state: IChatState, payload: IApplication[]): void {
|
||||
state.applications = payload;
|
||||
},
|
||||
setApplicationsStatus(state: IChatState, payload: Status): void {
|
||||
state.applicationsStatus = payload;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
async setApplications({ commit }: any, payload: IApplication[]) {
|
||||
commit('setApplications', payload);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
import { IApplication } from '@/operators';
|
||||
|
||||
export const setApplications = async ({ commit }: any, payload: IApplication[]) => {
|
||||
commit('setApplications', payload);
|
||||
};
|
||||
|
||||
export default {
|
||||
setApplications
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Module } from 'vuex';
|
||||
import { IChatState } from './models';
|
||||
import state from './state';
|
||||
import actions from './actions';
|
||||
import mutations from './mutations';
|
||||
|
||||
export const chat: Module<IChatState, any> = {
|
||||
namespaced: true,
|
||||
state,
|
||||
mutations,
|
||||
actions
|
||||
};
|
||||
|
||||
export default chat;
|
||||
@@ -0,0 +1,7 @@
|
||||
import { IApplication } from '@/operators';
|
||||
import { Status } from '../common/models';
|
||||
|
||||
export interface IChatState {
|
||||
applications: IApplication[] | undefined;
|
||||
applicationsStatus: Status | undefined;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { IApplication } from '@/operators';
|
||||
import { IChatState } from './models';
|
||||
import { Status } from '../common/models';
|
||||
|
||||
export const setApplications = (state: IChatState, payload: IApplication[]): void => {
|
||||
state.applications = payload;
|
||||
};
|
||||
|
||||
export const setApplicationsStatus = (state: IChatState, payload: Status): void => {
|
||||
state.applicationsStatus = payload;
|
||||
};
|
||||
|
||||
export default {
|
||||
setApplications,
|
||||
setApplicationsStatus
|
||||
};
|
||||
@@ -0,0 +1,8 @@
|
||||
import { IChatState } from './models';
|
||||
|
||||
export default (): IChatState => {
|
||||
return {
|
||||
applications: undefined,
|
||||
applicationsStatus: undefined
|
||||
};
|
||||
};
|
||||
@@ -1,79 +0,0 @@
|
||||
import { ENDPOINT } from '@/constants';
|
||||
import { IApplication, IUser } from '@/operators';
|
||||
import { ActionContext, Module } from 'vuex';
|
||||
import { ICommonState, IRootState, ISetting, IToken } from './models';
|
||||
|
||||
export const common: Module<ICommonState, IRootState> = {
|
||||
namespaced: true,
|
||||
state(): ICommonState {
|
||||
return {
|
||||
user: {},
|
||||
token: {
|
||||
access: undefined,
|
||||
refresh: undefined
|
||||
},
|
||||
setting: {
|
||||
endpoint: ENDPOINT,
|
||||
stream: false
|
||||
},
|
||||
applications: undefined
|
||||
};
|
||||
},
|
||||
mutations: {
|
||||
setUser(state: ICommonState, payload: IUser): void {
|
||||
state.user = {
|
||||
...state.user,
|
||||
...payload
|
||||
};
|
||||
},
|
||||
setToken(state: ICommonState, payload: IToken): void {
|
||||
state.token = {
|
||||
...state.token,
|
||||
...payload
|
||||
};
|
||||
},
|
||||
resetToken(state: ICommonState): void {
|
||||
state.token = {};
|
||||
},
|
||||
setSetting(state: ICommonState, payload: ISetting): void {
|
||||
state.setting = {
|
||||
...state.setting,
|
||||
...payload
|
||||
};
|
||||
},
|
||||
setApplications(state: ICommonState, payload: IApplication[]): void {
|
||||
state.applications = payload;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
resetToken({ commit }: ActionContext<ICommonState, IRootState>) {
|
||||
commit('resetToken');
|
||||
},
|
||||
setToken({ commit }: ActionContext<ICommonState, IRootState>, payload: IToken) {
|
||||
commit('setToken', payload);
|
||||
},
|
||||
setUser({ commit }: ActionContext<ICommonState, IRootState>, payload: IUser) {
|
||||
commit('setUser', payload);
|
||||
},
|
||||
setApplications({ commit }: ActionContext<ICommonState, IRootState>, payload: IApplication[]) {
|
||||
commit('setApplications', payload);
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
authenticated(state: ICommonState): boolean {
|
||||
return !!state.token.access;
|
||||
},
|
||||
user(state: ICommonState): IUser {
|
||||
return state.user;
|
||||
},
|
||||
token(state: ICommonState): IToken {
|
||||
return state.token;
|
||||
},
|
||||
setting(state: ICommonState): ISetting {
|
||||
return state.setting;
|
||||
},
|
||||
applications(state: ICommonState): IApplication[] | undefined {
|
||||
return state.applications;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,26 @@
|
||||
import { ActionContext } from 'vuex';
|
||||
import { IRootState, IToken } from '../common/models';
|
||||
import { IApplication, IUser } from '@/operators';
|
||||
|
||||
export const resetToken = ({ commit }: ActionContext<IRootState, IRootState>) => {
|
||||
commit('resetToken');
|
||||
};
|
||||
|
||||
export const setToken = ({ commit }: ActionContext<IRootState, IRootState>, payload: IToken) => {
|
||||
commit('setToken', payload);
|
||||
};
|
||||
|
||||
export const setUser = ({ commit }: ActionContext<IRootState, IRootState>, payload: IUser) => {
|
||||
commit('setUser', payload);
|
||||
};
|
||||
|
||||
export const setApplications = ({ commit }: ActionContext<IRootState, IRootState>, payload: IApplication[]) => {
|
||||
commit('setApplications', payload);
|
||||
};
|
||||
|
||||
export default {
|
||||
resetToken,
|
||||
setToken,
|
||||
setUser,
|
||||
setApplications
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
import { IRootState } from './models';
|
||||
|
||||
export const authenticated = (state: IRootState): boolean => {
|
||||
return !!state.token.access;
|
||||
};
|
||||
|
||||
export const user = (state: IRootState): any => {
|
||||
return state.user;
|
||||
};
|
||||
|
||||
export const token = (state: IRootState): any => {
|
||||
return state.token;
|
||||
};
|
||||
|
||||
export const setting = (state: IRootState): any => {
|
||||
return state.setting;
|
||||
};
|
||||
|
||||
export const applications = (state: IRootState): any => {
|
||||
return state.applications;
|
||||
};
|
||||
|
||||
export default {
|
||||
authenticated,
|
||||
user,
|
||||
token,
|
||||
setting,
|
||||
applications
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
import state from './state';
|
||||
import mutations from './mutations';
|
||||
import actions from './actions';
|
||||
import getters from './getters';
|
||||
|
||||
export default {
|
||||
state,
|
||||
mutations,
|
||||
actions,
|
||||
getters
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
import { IApplication, IUser } from '@/operators';
|
||||
import { IMidjourneyState } from '../midjourney/models';
|
||||
import { IChatState } from '../chat/models';
|
||||
|
||||
export enum Status {
|
||||
Request = 'Request',
|
||||
Success = 'Success',
|
||||
Error = 'Error'
|
||||
}
|
||||
|
||||
export interface IToken {
|
||||
access?: string;
|
||||
refresh?: string;
|
||||
}
|
||||
|
||||
export interface ISetting {
|
||||
stream?: boolean;
|
||||
endpoint?: string;
|
||||
}
|
||||
|
||||
export interface ICommonState {
|
||||
token: IToken;
|
||||
user: IUser;
|
||||
setting: ISetting;
|
||||
applications: IApplication[] | undefined;
|
||||
}
|
||||
|
||||
export interface IRootState extends ICommonState {
|
||||
midjourney?: IMidjourneyState;
|
||||
chat?: IChatState;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import { IUser } from '@/operators';
|
||||
import { IRootState } from './models';
|
||||
|
||||
export const setUser = (state: IRootState, payload: IUser): void => {
|
||||
state.user = {
|
||||
...state.user,
|
||||
...payload
|
||||
};
|
||||
};
|
||||
|
||||
export const setToken = (state: IRootState, payload: any): void => {
|
||||
state.token = {
|
||||
...state.token,
|
||||
...payload
|
||||
};
|
||||
};
|
||||
|
||||
export const resetToken = (state: IRootState): void => {
|
||||
state.token = {};
|
||||
};
|
||||
|
||||
export const setSetting = (state: IRootState, payload: any): void => {
|
||||
state.setting = {
|
||||
...state.setting,
|
||||
...payload
|
||||
};
|
||||
};
|
||||
|
||||
export const setApplications = (state: IRootState, payload: any): void => {
|
||||
state.applications = payload;
|
||||
};
|
||||
|
||||
export default {
|
||||
setUser,
|
||||
setToken,
|
||||
resetToken,
|
||||
setSetting,
|
||||
setApplications
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
import { ENDPOINT } from '@/constants';
|
||||
import { IRootState } from './models';
|
||||
|
||||
export default (): IRootState => {
|
||||
return {
|
||||
user: {},
|
||||
token: {
|
||||
access: undefined,
|
||||
refresh: undefined
|
||||
},
|
||||
setting: {
|
||||
endpoint: ENDPOINT,
|
||||
stream: false
|
||||
},
|
||||
applications: undefined
|
||||
};
|
||||
};
|
||||
+4
-4
@@ -1,12 +1,12 @@
|
||||
import { createStore, ActionContext } from 'vuex';
|
||||
import createPersistedState from 'vuex-persistedstate';
|
||||
import { common } from './common';
|
||||
import { midjourney } from './midjourney';
|
||||
import { chat } from './chat';
|
||||
import midjourney from './midjourney';
|
||||
import chat from './chat';
|
||||
import root from './common';
|
||||
|
||||
const store = createStore({
|
||||
...root,
|
||||
modules: {
|
||||
common,
|
||||
midjourney,
|
||||
chat
|
||||
},
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
import { IApplication, IMidjourneyPreset } from '@/operators';
|
||||
import { Module } from 'vuex';
|
||||
import { IMidjourneyState } from './models';
|
||||
|
||||
export const midjourney: Module<IMidjourneyState, any> = {
|
||||
namespaced: true,
|
||||
state(): IMidjourneyState {
|
||||
return {
|
||||
applications: undefined,
|
||||
preset: {}
|
||||
};
|
||||
},
|
||||
mutations: {
|
||||
setApplications(state: IMidjourneyState, payload: IApplication[]): void {
|
||||
state.applications = payload;
|
||||
},
|
||||
setPreset(state: IMidjourneyState, payload: IMidjourneyPreset): void {
|
||||
state.preset = payload;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
setPreset({ commit }: any, payload: IMidjourneyPreset) {
|
||||
commit('setPreset', payload);
|
||||
},
|
||||
setApplications({ commit }: any, payload: IApplication[]) {
|
||||
commit('setApplications', payload);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
import { IApplication, IMidjourneyPreset } from '@/operators';
|
||||
|
||||
export const setPreset = ({ commit }: any, payload: IMidjourneyPreset) => {
|
||||
commit('setPreset', payload);
|
||||
};
|
||||
|
||||
export const setApplications = ({ commit }: any, payload: IApplication[]) => {
|
||||
commit('setApplications', payload);
|
||||
};
|
||||
|
||||
export default {
|
||||
setPreset,
|
||||
setApplications
|
||||
};
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Module } from 'vuex';
|
||||
import { IMidjourneyState } from './models';
|
||||
import actions from './actions';
|
||||
import mutations from './mutations';
|
||||
|
||||
export const midjourney: Module<IMidjourneyState, any> = {
|
||||
namespaced: true,
|
||||
state(): IMidjourneyState {
|
||||
return {
|
||||
applications: undefined,
|
||||
preset: {}
|
||||
};
|
||||
},
|
||||
mutations,
|
||||
actions
|
||||
};
|
||||
|
||||
export default midjourney;
|
||||
@@ -0,0 +1,6 @@
|
||||
import { IApplication, IMidjourneyPreset } from '@/operators';
|
||||
|
||||
export interface IMidjourneyState {
|
||||
applications: IApplication[] | undefined;
|
||||
preset: IMidjourneyPreset;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { IApplication } from '@/operators';
|
||||
import { IMidjourneyState } from './models';
|
||||
|
||||
export const setApplications = (state: IMidjourneyState, payload: IApplication[]): void => {
|
||||
state.applications = payload;
|
||||
};
|
||||
|
||||
export const setPreset = (state: IMidjourneyState, payload: any): void => {
|
||||
state.preset = payload;
|
||||
};
|
||||
|
||||
export default {
|
||||
setApplications,
|
||||
setPreset
|
||||
};
|
||||
@@ -1,40 +0,0 @@
|
||||
import { IApplication, IMidjourneyPreset, IUser } from '@/operators';
|
||||
|
||||
export enum Status {
|
||||
Request = 'Request',
|
||||
Success = 'Success',
|
||||
Error = 'Error'
|
||||
}
|
||||
|
||||
export interface IToken {
|
||||
access?: string;
|
||||
refresh?: string;
|
||||
}
|
||||
|
||||
export interface ISetting {
|
||||
stream?: boolean;
|
||||
endpoint?: string;
|
||||
}
|
||||
|
||||
export interface ICommonState {
|
||||
token: IToken;
|
||||
user: IUser;
|
||||
setting: ISetting;
|
||||
applications: IApplication[] | undefined;
|
||||
}
|
||||
|
||||
export interface IMidjourneyState {
|
||||
applications: IApplication[] | undefined;
|
||||
preset: IMidjourneyPreset;
|
||||
}
|
||||
|
||||
export interface IChatState {
|
||||
applications: IApplication[] | undefined;
|
||||
applicationsStatus: Status | undefined;
|
||||
}
|
||||
|
||||
export interface IRootState {
|
||||
common: ICommonState;
|
||||
midjourney: IMidjourneyState;
|
||||
chat: IChatState;
|
||||
}
|
||||
Reference in new issue
Block a user