Files
freeplanet/src/store/Modules/GlobalStore.ts

82 lines
1.5 KiB
TypeScript
Raw Normal View History

import { IGlobalState } from 'model'
2018-11-17 21:07:07 +01:00
import { storeBuilder } from './Store/Store'
2018-11-15 19:48:37 +01:00
const state: IGlobalState = {
conta: 0,
isLoginPage: false,
layoutNeeded: true,
mobileMode: false,
menuCollapse: true,
leftDrawerOpen: true,
posts: [],
listatodo: [
{namecat: 'personal', description: 'personal'},
{namecat: 'work', description: 'work'},
{namecat: 'shopping', description: 'shopping'}
]
2018-11-15 19:48:37 +01:00
}
const b = storeBuilder.module<IGlobalState>('GlobalModule', state)
// Getters
namespace Getters {
const conta = b.read(state => state.conta, 'conta')
const listatodo = b.read(state => state.listatodo, 'listatodo')
2018-11-15 19:48:37 +01:00
export const getters = {
get conta() {
return conta()
},
get listaTodo() {
return listatodo()
}
2018-11-15 19:48:37 +01:00
}
}
namespace Mutations {
function setConta(state: IGlobalState, num: number) {
state.conta = num
}
function setleftDrawerOpen(state: IGlobalState, bool: boolean) {
state.leftDrawerOpen = bool
}
2018-11-15 19:48:37 +01:00
export const mutations = {
setConta: b.commit(setConta),
setleftDrawerOpen: b.commit(setleftDrawerOpen)
2018-11-15 19:48:37 +01:00
}
}
namespace Actions {
async function setConta(context, num: number) {
2018-11-15 19:48:37 +01:00
Mutations.mutations.setConta(num)
}
export const actions = {
setConta: b.dispatch(setConta)
}
}
const stateGetter = b.state()
2018-11-15 19:48:37 +01:00
// Module
const GlobalModule = {
get state() {
return stateGetter()
},
2018-11-15 19:48:37 +01:00
getters: Getters.getters,
mutations: Mutations.mutations,
actions: Actions.actions
}
export default GlobalModule