helpers.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import Vue from "vue";
  2. import {
  3. mapState,
  4. mapGetters,
  5. mapActions,
  6. mapMutations,
  7. createNamespacedHelpers
  8. } from "../index";
  9. const helpers = createNamespacedHelpers('foo');
  10. new Vue({
  11. computed: Object.assign({},
  12. mapState(["a"]),
  13. mapState('foo', ["a"]),
  14. mapState({
  15. b: "b"
  16. }),
  17. mapState('foo', {
  18. b: "b"
  19. }),
  20. mapState({
  21. c: (state: any, getters: any) => state.c + getters.c
  22. }),
  23. mapState('foo', {
  24. c: (state: any, getters: any) => state.c + getters.c
  25. }),
  26. mapGetters(["d"]),
  27. mapGetters('foo', ["d"]),
  28. mapGetters({
  29. e: "e"
  30. }),
  31. mapGetters('foo', {
  32. e: "e"
  33. }),
  34. helpers.mapState(["k"]),
  35. helpers.mapState({
  36. k: "k"
  37. }),
  38. helpers.mapState({
  39. k: (state: any, getters: any) => state.k + getters.k,
  40. useThis(state: any, getters: any) {
  41. return state.k + getters.k + this.whatever
  42. }
  43. }),
  44. helpers.mapGetters(["l"]),
  45. helpers.mapGetters({
  46. l: "l"
  47. }),
  48. {
  49. otherComputed () {
  50. return "f";
  51. }
  52. }
  53. ),
  54. methods: Object.assign({},
  55. mapActions(["g"]),
  56. mapActions({
  57. h: "h"
  58. }),
  59. mapActions({
  60. g (dispatch, a: string, b: number, c: boolean): void {
  61. dispatch('g', { a, b, c })
  62. dispatch({
  63. type: 'g',
  64. a,
  65. b,
  66. c
  67. })
  68. }
  69. }),
  70. mapActions('foo', ["g"]),
  71. mapActions('foo', {
  72. h: "h"
  73. }),
  74. mapActions('foo', {
  75. g (dispatch, a: string, b: number, c: boolean): void {
  76. dispatch('g', { a, b, c })
  77. dispatch({
  78. type: 'g',
  79. a,
  80. b,
  81. c
  82. })
  83. }
  84. }),
  85. mapMutations(["i"]),
  86. mapMutations({
  87. j: "j"
  88. }),
  89. mapMutations({
  90. i (commit, a: string, b: number, c: boolean): void {
  91. commit('i', { a, b, c })
  92. commit({
  93. type: 'i',
  94. a,
  95. b,
  96. c
  97. })
  98. }
  99. }),
  100. mapMutations('foo', ["i"]),
  101. mapMutations('foo', {
  102. j: "j"
  103. }),
  104. mapMutations('foo', {
  105. i (commit, a: string, b: number, c: boolean): void {
  106. commit('i', { a, b, c })
  107. commit({
  108. type: 'i',
  109. a,
  110. b,
  111. c
  112. })
  113. }
  114. }),
  115. helpers.mapActions(["m"]),
  116. helpers.mapActions({
  117. m: "m"
  118. }),
  119. helpers.mapActions({
  120. m (dispatch, value: string) {
  121. dispatch('m', value)
  122. }
  123. }),
  124. helpers.mapMutations(["n"]),
  125. helpers.mapMutations({
  126. n: "n"
  127. }),
  128. helpers.mapMutations({
  129. n (commit, value: string) {
  130. commit('m', value)
  131. }
  132. }),
  133. {
  134. otherMethod () {}
  135. }
  136. )
  137. });