-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathWindowStore.js
45 lines (37 loc) · 1.21 KB
/
WindowStore.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { createStore } from '@helpers/StoreHelper'
// The namespace used to register this module in the Vuex store.
export const namespace = 'window'
export const state = () => ({
// Whether the navigation bar and the footer should be hidden.
isFullscreen: false,
// The current height of the window.
windowHeight: window.innerHeight,
// The current width of the window.
windowWidth: window.innerWidth
})
export const getters = {
// Useful to use a single watcher to detect resize events.
windowSize (state) {
return state.windowHeight * state.windowWidth
}
}
export const mutations = {
SET_FULLSCREEN (state, isFullscreen) {
state.isFullscreen = isFullscreen
},
SET_WINDOW_SIZE (state, { height, width }) {
state.windowHeight = height
state.windowWidth = width
}
}
export const actions = {
// Changes to fullscreen mode.
setFullscreen ({ commit }, isFullscreen) {
commit('SET_FULLSCREEN', isFullscreen)
},
// Updates the screen size when the window is resized.
updateWindowSize ({ commit }, size = { height: window.innerHeight, width: window.innerWidth }) {
commit('SET_WINDOW_SIZE', size)
}
}
export default createStore({ namespace, state, getters, mutations, actions })