|
| 1 | +import { ActionContext } from 'vuex'; |
| 2 | +import DirectVuex from 'direct-vuex'; |
| 3 | + |
1 | 4 | import { IOption as ISomeValue } from '@common/IamSelect/IamSelect.option.i';
|
2 | 5 | import { SomeSvc } from '@services/SomeSvc';
|
3 |
| -// import { moduleActionContext } from '~/VueApp/store'; |
| 6 | +import { moduleActionContext } from '~/VueApp/store'; |
| 7 | + |
| 8 | +/* eslint-disable import/no-cycle */ |
| 9 | +import { modSomeForm } from '.'; |
4 | 10 |
|
5 | 11 | import * as mutationTypes from './mutations.conf';
|
| 12 | +import { IState } from './state.i'; |
| 13 | + |
| 14 | +// Not naming imported cause of SystemJs import only default |
| 15 | +// https://github.com/paleo/direct-vuex/issues/14#issuecomment-568543969 |
| 16 | +const { createActions } = DirectVuex; |
| 17 | + |
| 18 | +export const modSomeFormActionContext = (ctx: any) => moduleActionContext(ctx, modSomeForm); |
| 19 | + |
| 20 | +export const actions = createActions({ |
| 21 | + getSomeValues( |
| 22 | + // commit полученных данных выполняется другим (синхронным) action, потому dispatch |
| 23 | + // { dispatch }: { dispatch: Function }, |
| 24 | + context: ActionContext<IState, IState>, |
| 25 | + { label }: ISomeValue, |
| 26 | + ): Promise <Array<ISomeValue> | void> { |
| 27 | + return SomeSvc |
| 28 | + .fetchData({ label }) // Все опции запроса в одном параметре-объекте (помимо label) |
| 29 | + .then((resp) => { |
| 30 | + // const { dispatch } = context; |
| 31 | + const { dispatch } = modSomeFormActionContext(context); |
| 32 | + dispatch.setSomeValues(resp); |
| 33 | + }); |
| 34 | + }, |
| 35 | + |
| 36 | + setSomeValues( |
| 37 | + { commit }: { commit: Function }, |
| 38 | + values: Array<ISomeValue>, |
| 39 | + ): void { |
| 40 | + commit(mutationTypes.SOME_VALUES_SET, values); |
| 41 | + }, |
6 | 42 |
|
7 |
| -export const getSomeValues = ( |
8 |
| - // commit полученных данных выполняется другим (синхронным) action, потому dispatch |
9 |
| - { dispatch }: { dispatch: Function }, |
10 |
| - { label }: ISomeValue, |
11 |
| -): Promise <Array<ISomeValue> | void> => SomeSvc |
12 |
| - .fetchData({ label }) // Все опции запроса в одном параметре-объекте (помимо label) |
13 |
| - .then((resp) => dispatch('setSomeValues', resp)); |
14 |
| - |
15 |
| -export const setSomeValues = ( |
16 |
| - { commit }: { commit: Function }, |
17 |
| - values: Array<ISomeValue>, |
18 |
| -): void => commit(mutationTypes.SOME_VALUES_SET, values); |
19 |
| - |
20 |
| -export const selectSomeValue = ( |
21 |
| - { commit }: { commit: Function }, |
22 |
| - value: ISomeValue | null, |
23 |
| -): void => commit(mutationTypes.SOME_VALUE_SELECT, value); |
| 43 | + selectSomeValue( |
| 44 | + { commit }: { commit: Function }, |
| 45 | + value: ISomeValue | null, |
| 46 | + ): void { |
| 47 | + commit(mutationTypes.SOME_VALUE_SELECT, value); |
| 48 | + }, |
| 49 | +}); |
0 commit comments