helpers.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. import { createApp } from "vue";
  2. import {
  3. mapState,
  4. mapGetters,
  5. mapActions,
  6. mapMutations,
  7. createNamespacedHelpers
  8. } from "../index";
  9. const helpers = createNamespacedHelpers('foo');
  10. createApp({
  11. computed: {
  12. ...mapState(["a"]),
  13. ...mapState('foo', ["b"]),
  14. ...mapState({
  15. c: "c"
  16. }),
  17. ...mapState('foo', {
  18. d: "d"
  19. }),
  20. ...mapState({
  21. e: (state: any, getters: any) => state.a + getters.g
  22. }),
  23. ...mapState('foo', {
  24. f: (state: any, getters: any) => state.a + getters.g
  25. }),
  26. ...mapGetters(["g"]),
  27. ...mapGetters('foo', ["h"]),
  28. ...mapGetters({
  29. i: "i"
  30. }),
  31. ...mapGetters('foo', {
  32. j: "j"
  33. }),
  34. ...helpers.mapState(["k"]),
  35. ...helpers.mapState({
  36. l: "l"
  37. }),
  38. ...helpers.mapState({
  39. m: (state: any, getters: any) => state.a + getters.g,
  40. useThis(state: any, getters: any): any {
  41. return state.a + getters.g + this.whatever
  42. }
  43. }),
  44. ...helpers.mapGetters(["n"]),
  45. ...helpers.mapGetters({
  46. o: "o"
  47. }),
  48. otherComputed () {
  49. return "";
  50. }
  51. },
  52. methods: {
  53. ...mapActions(["p"]),
  54. ...mapActions({
  55. q: "q"
  56. }),
  57. ...mapActions({
  58. r (dispatch, a: string, b: number, c: boolean) {
  59. dispatch('p', { a, b, c })
  60. dispatch({
  61. type: 'p',
  62. a,
  63. b,
  64. c
  65. })
  66. }
  67. }),
  68. ...mapActions('foo', ["s"]),
  69. ...mapActions('foo', {
  70. t: "t"
  71. }),
  72. ...mapActions('foo', {
  73. u (dispatch, a: string, b: number, c: boolean) {
  74. dispatch('p', { a, b, c })
  75. dispatch({
  76. type: 'p',
  77. a,
  78. b,
  79. c
  80. })
  81. }
  82. }),
  83. ...mapMutations(["v"]),
  84. ...mapMutations({
  85. w: "w"
  86. }),
  87. ...mapMutations({
  88. x (commit, a: string, b: number, c: boolean) {
  89. commit('v', { a, b, c })
  90. commit({
  91. type: 'v',
  92. a,
  93. b,
  94. c
  95. })
  96. }
  97. }),
  98. ...mapMutations('foo', ["y"]),
  99. ...mapMutations('foo', {
  100. z: "z"
  101. }),
  102. ...mapMutations('foo', {
  103. aa (commit, a: string, b: number, c: boolean) {
  104. commit('v', { a, b, c })
  105. commit({
  106. type: 'v',
  107. a,
  108. b,
  109. c
  110. })
  111. }
  112. }),
  113. ...helpers.mapActions(["ab"]),
  114. ...helpers.mapActions({
  115. ac: "ac"
  116. }),
  117. ...helpers.mapActions({
  118. ad (dispatch, value: string) {
  119. dispatch('p', value)
  120. }
  121. }),
  122. ...helpers.mapMutations(["ae"]),
  123. ...helpers.mapMutations({
  124. af: "af"
  125. }),
  126. ...helpers.mapMutations({
  127. ag (commit, value: string) {
  128. commit('v', value)
  129. }
  130. }),
  131. otherMethod () {}
  132. },
  133. created() {
  134. // Computed
  135. this.a
  136. this.b
  137. this.c
  138. this.d
  139. this.e
  140. this.f
  141. this.g
  142. this.h
  143. this.i
  144. this.j
  145. this.k
  146. this.l
  147. this.m
  148. this.n
  149. this.o
  150. this.otherComputed
  151. // Methods
  152. this.p()
  153. this.q()
  154. this.r('', 0, true)
  155. this.s()
  156. this.t()
  157. this.u('', 0, true)
  158. this.v()
  159. this.w()
  160. this.x('', 0, true)
  161. this.y()
  162. this.z()
  163. this.aa('', 0, true)
  164. this.ab()
  165. this.ac()
  166. this.ad('')
  167. this.ae()
  168. this.af()
  169. this.ag('')
  170. this.otherMethod()
  171. }
  172. });