Skip to content

Commit

Permalink
feat(web): basic modular store structure (core, auth)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hagith committed Feb 4, 2020
1 parent e9fd586 commit cbcdf0f
Show file tree
Hide file tree
Showing 17 changed files with 96 additions and 50 deletions.
13 changes: 12 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,16 @@
"rules": {
"no-console": "error",
"@typescript-eslint/explicit-function-return-type": "off"
}
},
"overrides": [
{
"files": ["**/*.js"],
"env": {
"node": true
},
"rules": {
"@typescript-eslint/no-var-requires": "off"
}
}
]
}
24 changes: 9 additions & 15 deletions apps/web/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
module.exports = {
env: {
node: true
node: true,
},
extends: [
'plugin:vue/essential',
'@vue/typescript'
],
extends: ['plugin:vue/essential', '@vue/prettier', '@vue/typescript'],
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
},
overrides: [
{
files: [
'**/__tests__/*.{j,t}s?(x)',
'**/tests/unit/**/*.spec.{j,t}s?(x)'
],
files: ['**/__tests__/*.{j,t}s?(x)', '**/tests/unit/**/*.spec.{j,t}s?(x)'],
env: {
jest: true
}
}
]
}
jest: true,
},
},
],
};
1 change: 1 addition & 0 deletions apps/web/src/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<script lang="ts">
import Vue from 'vue';
import './layout';
import './modules';
const DEFAULT_LAYOUT = 'default';
Expand Down
14 changes: 14 additions & 0 deletions apps/web/src/core/store/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Vue from 'vue';
import Vuex from 'vuex';
import { RootState } from './state';

Vue.use(Vuex);

export default new Vuex.Store<RootState>({
strict: process.env.NODE_ENV !== 'production',
state: {},
mutations: {},
actions: {},
});

export { RootState };
1 change: 1 addition & 0 deletions apps/web/src/core/store/state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type RootState = {};
4 changes: 2 additions & 2 deletions apps/web/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import Vue from 'vue';
import App from './app.vue';
import './registerServiceWorker';
import router from './router';
import store from './store';
import store from './core/store';

Vue.config.productionTip = false;
Vue.config.productionTip = process.env.NODE_ENV === 'production';

Vue.use(BootstrapVue);

Expand Down
1 change: 1 addition & 0 deletions apps/web/src/modules/auth/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './store';
5 changes: 5 additions & 0 deletions apps/web/src/modules/auth/store/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ActionTree } from 'vuex';
import { RootState } from '~app/core/store';
import { AuthState } from './state';

export const authActions: ActionTree<AuthState, RootState> = {};
5 changes: 5 additions & 0 deletions apps/web/src/modules/auth/store/getters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { GetterTree } from 'vuex';
import { RootState } from '~app/core/store';
import { AuthState } from './state';

export const authGetters: GetterTree<AuthState, RootState> = {};
17 changes: 17 additions & 0 deletions apps/web/src/modules/auth/store/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Module } from 'vuex';
import store, { RootState } from '~app/core/store';
import { authActions } from './actions';
import { authGetters } from './getters';
import { authMutations } from './mutations';
import { AuthState, initialAuthState } from './state';

export const MODULE_PATH = 'auth';

export const authStore: Module<AuthState, RootState> = {
state: initialAuthState(),
actions: authActions,
mutations: authMutations,
getters: authGetters,
};

store.registerModule(MODULE_PATH, authStore);
4 changes: 4 additions & 0 deletions apps/web/src/modules/auth/store/mutations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { MutationTree } from 'vuex';
import { AuthState } from './state';

export const authMutations: MutationTree<AuthState> = {};
15 changes: 15 additions & 0 deletions apps/web/src/modules/auth/store/state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// TODO interface shared with backend
export interface User {
id: number;
name: string;
}

export interface AuthState {
user: User | null;
}

export function initialAuthState(): AuthState {
return {
user: null,
};
}
1 change: 1 addition & 0 deletions apps/web/src/modules/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './auth';
11 changes: 0 additions & 11 deletions apps/web/src/store/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion apps/web/src/views/home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</template>

<script lang="ts">
import HelloWorld from '@/components/HelloWorld.vue';
import HelloWorld from '~app/components/HelloWorld.vue';
export default {
name: 'home',
Expand Down
24 changes: 4 additions & 20 deletions apps/web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,11 @@
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"types": [
"webpack-env",
"jest"
],
"types": ["webpack-env", "jest"],
"paths": {
"@/*": [
"src/*"
]
"~app/*": ["src/*"]
},
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
"lib": ["esnext", "dom", "dom.iterable", "scripthost"]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"tests/**/*.ts",
"tests/**/*.tsx"
]
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "tests/**/*.ts", "tests/**/*.tsx"]
}
4 changes: 4 additions & 0 deletions apps/web/vue.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
const path = require('path');
const isDev = process.env.NODE_ENV !== 'production';

module.exports = {
lintOnSave: false,
css: {
sourceMap: isDev,
},
chainWebpack: config => {
config.resolve.alias.set('~app', path.resolve('./src'));
},
};

0 comments on commit cbcdf0f

Please sign in to comment.