Browse Source

[Redux] 네이밍 규칙 샘플

master
junh_eee(이준희) 8 months ago
parent
commit
9fcb359c27
  1. 51
      src/modules/_sample/actions/index.ts
  2. 14
      src/modules/_sample/apis/index.ts
  3. 5
      src/modules/_sample/index.ts
  4. 24
      src/modules/_sample/models/index.ts
  5. 15
      src/modules/_sample/reducers/index.ts
  6. 16
      src/modules/_sample/sagas/index.ts

51
src/modules/_sample/actions/index.ts

@ -0,0 +1,51 @@
import { createAsyncAction, ActionType, createAction } from 'typesafe-actions';
/**
* [Action ]
* _를 .
* .
* .
* DISPATCH_ .
* (ex. ) LOG로 .
*
*
* - LIST
* () - DETAIL
* / - CREATE
* / - UPDATE
* - DELETE
*
*
* [Action ]
* .
* Action . (ex. DRONE_LIST_REQUEST -> dronList)
* createAction을 .
*/
// 드론 목록
const DRONE_LIST_REQUEST = 'sample/DRONE_LIST_REQUEST';
const DRONE_LIST_SUCCESS = 'sample/DRONE_LIST_SUCCESS';
const DRONE_LIST_FAILURE = 'sample/DRONE_LIST_FAILURE';
// 지도 타입
const DISPATHC_MAPTYPE = 'sample/DISPATCH_MAPTYPE';
// 비행 이력 목록
const HISTORY_LIST_REQUEST = 'sample/HISTORY_LIST_REQUEST';
// 비행 이력 상세 목록
const HISTORY_LOG_REQUEST = 'sample/HISTORY_LOG_REQUEST';
export const droneList = createAsyncAction(
DRONE_LIST_REQUEST,
DRONE_LIST_SUCCESS,
DRONE_LIST_FAILURE
)();
export const dispatchMapType = createAction(DISPATHC_MAPTYPE)();
const actions = {
droneList
};
export type SampleActions = ActionType<typeof actions>;

14
src/modules/_sample/apis/index.ts

@ -0,0 +1,14 @@
import axios from '../../utils/customAxiosUtil';
/**
* + API로 .
* api는 Action .
* return은 .
*/
export const sampleAPI = {
// 드론 목록 조회
droneList: async () => {
return await axios.get('api/bas/dron/list...');
}
};

5
src/modules/_sample/index.ts

@ -0,0 +1,5 @@
export * from './actions';
export * from './apis';
export * from './models';
export * from './reducers';
export * from './sagas';

24
src/modules/_sample/models/index.ts

@ -0,0 +1,24 @@
/**
* interface는 'I' .
* initialState로 .
*/
export interface ISampleState {
droneList: IDroneDetail[] | undefined;
count: number | 0;
}
export interface IDroneDetail {
groupId: string;
arcrftSno: number;
arcrftHght: number;
arcrftLngth: number;
arcrftModelNm: string;
arcrftTypeCd: string;
arcrftWdth: number;
}
export const initialState: ISampleState = {
droneList: undefined,
count: 0
};

15
src/modules/_sample/reducers/index.ts

@ -0,0 +1,15 @@
import { createReducer } from 'typesafe-actions';
import produce from 'immer';
import { ISampleState, initialState } from '../models';
import * as Actions from '../actions';
/**
* Reducer .
*/
export const sampleReducer = createReducer<ISampleState, Actions.SampleActions>(
initialState
).handleAction(Actions.droneList.success, (state, action) =>
produce(state, draft => {})
);

16
src/modules/_sample/sagas/index.ts

@ -0,0 +1,16 @@
import { ActionType } from 'typesafe-actions';
import * as Actions from '../actions';
import { takeEvery } from 'redux-saga/effects';
/**
* saga Action + Saga로 .
*/
function* dronListSaga(action: ActionType<typeof Actions.droneList.request>) {
try {
} catch (error: any) {}
}
export function* sampleSaga() {
yield takeEvery(Actions.droneList.request, dronListSaga);
}
Loading…
Cancel
Save