Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3.  
  4. Vue.use(Vuex)
  5.  
  6. /**
  7. * @interface StoreState
  8. */
  9. export interface StoreState {
  10. [key: string]: any
  11. }
  12.  
  13. /**
  14. * @interface StoreOptions
  15. */
  16. export interface StoreOptions {
  17. state: StoreState,
  18. mutations: any
  19. }
  20.  
  21. /**
  22. * @interface StoreObservable
  23. */
  24. export interface StoreObservable {
  25. state: StoreState,
  26. commit: Function
  27. }
  28.  
  29. /**
  30. * Helper to create dynamic stores
  31. * Useful to reduce boilerplate.. simple and functional
  32. * Besides the store is standalone and works fine in a lot of places
  33. * @param {StoreOptions} options
  34. * @returns {StoreObservable}
  35. */
  36. export default (options: StoreOptions): StoreObservable => {
  37. const { state, mutations } = options
  38. return {
  39. state: Vue.observable(state),
  40. commit (mutation: any, ...args: any) {
  41. mutations[mutation](state, ...args)
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement