-
-
Save Fl0pZz/84e80242f649e0b80dba0457c6525942 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vue from 'vue' | |
import Vuex from 'vuex' | |
import notification from './notifications/index' | |
import toast from './toasts/index' | |
Vue.use(Vuex) | |
const debug = process.env.NODE_ENV !== 'production' | |
const store = new Vuex.Store({ | |
strict: debug, | |
modules: { | |
notification, | |
toast | |
} | |
}) | |
if (module.hot) { | |
module.hot.accept([ | |
'./notifications/index', | |
'./toasts/index' | |
], () => { | |
store.hotUpdate({ | |
modules: { | |
notification: require('./notifications/index').default, | |
toast: require('./toasts/index').default | |
} | |
}) | |
}) | |
} | |
export default store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const INIT_QUEUE = 'INIT_QUEUE' | |
export const DISPLAY = 'DISPLAY' | |
export const UPDATE_FLAG = 'UPDATE_FLAG' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as types from './toast-mutation-types' | |
export default { | |
[types.INIT_QUEUE] (state, size) { | |
state.init = true | |
state._max_toasts = size | |
state.free = size | |
for (let i = 0; i < size; ++i) { | |
state.flags[i] = null | |
} | |
}, | |
[types.DISPLAY] (state, { id, notification }) { | |
let i = state.flags.findIndex(elem => (elem === null)) | |
if (i !== -1) { | |
state.flags[i] = {id, notification} | |
state.free -= 1 | |
} | |
}, | |
[types.UPDATE_FLAG] (state, { index, val }) { | |
state.flags[index] = val | |
if (val === null) state.free += 1 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { mapGetters } from 'vuex' | |
import Toast from './toast/Toast' | |
import { DISPLAY } from 'store/toasts/toast-mutation-types' | |
const MAX_NOTICES = 5 | |
export default { | |
name: 'toast-manager', | |
components: { | |
Toast | |
}, | |
watch: { | |
isEmpty (empty) { | |
if (!empty && this.$store.getters['toast/canDisplay']) { | |
this.$store.dispatch('notification/pop_back') | |
.then(pair => { this.$store.commit(DISPLAY, pair) }) // <-- вот тут | |
} | |
}, | |
canDisplay (able) { | |
if (able && !this.$store.getters['notification/isEmpty']) { | |
this.$store.dispatch('notification/pop_back') | |
.then(pair => { this.$store.commit(DISPLAY, pair) }) // <-- вот тут | |
} | |
} | |
}, | |
created () { | |
this.$store.dispatch('toast/init', MAX_NOTICES) | |
}, | |
computed: { | |
...mapGetters({ | |
isEmpty: 'notification/isEmpty', | |
canDisplay: 'toast/canDisplay', | |
toastStackSize: 'toast/toastStackSize' | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment