helpers.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. }),
  41. helpers.mapGetters(["l"]),
  42. helpers.mapGetters({
  43. l: "l"
  44. }),
  45. {
  46. otherComputed () {
  47. return "f";
  48. }
  49. }
  50. ),
  51. methods: Object.assign({},
  52. mapActions(["g"]),
  53. mapActions({
  54. h: "h"
  55. }),
  56. mapActions({
  57. g (dispatch, a: string, b: number, c: boolean): void {
  58. dispatch('g', { a, b, c })
  59. dispatch({
  60. type: 'g',
  61. a,
  62. b,
  63. c
  64. })
  65. }
  66. }),
  67. mapActions('foo', ["g"]),
  68. mapActions('foo', {
  69. h: "h"
  70. }),
  71. mapActions('foo', {
  72. g (dispatch, a: string, b: number, c: boolean): void {
  73. dispatch('g', { a, b, c })
  74. dispatch({
  75. type: 'g',
  76. a,
  77. b,
  78. c
  79. })
  80. }
  81. }),
  82. mapMutations(["i"]),
  83. mapMutations({
  84. j: "j"
  85. }),
  86. mapMutations({
  87. i (commit, a: string, b: number, c: boolean): void {
  88. commit('i', { a, b, c })
  89. commit({
  90. type: 'i',
  91. a,
  92. b,
  93. c
  94. })
  95. }
  96. }),
  97. mapMutations('foo', ["i"]),
  98. mapMutations('foo', {
  99. j: "j"
  100. }),
  101. mapMutations('foo', {
  102. i (commit, a: string, b: number, c: boolean): void {
  103. commit('i', { a, b, c })
  104. commit({
  105. type: 'i',
  106. a,
  107. b,
  108. c
  109. })
  110. }
  111. }),
  112. helpers.mapActions(["m"]),
  113. helpers.mapActions({
  114. m: "m"
  115. }),
  116. helpers.mapActions({
  117. m (dispatch, value: string) {
  118. dispatch('m', value)
  119. }
  120. }),
  121. helpers.mapMutations(["n"]),
  122. helpers.mapMutations({
  123. n: "n"
  124. }),
  125. helpers.mapMutations({
  126. n (commit, value: string) {
  127. commit('m', value)
  128. }
  129. }),
  130. {
  131. otherMethod () {}
  132. }
  133. )
  134. });