relation.ts 681 B

123456789101112131415161718192021222324252627282930
  1. /**
  2. * 从服务器获取的术语表
  3. */
  4. import { createSlice, PayloadAction } from "@reduxjs/toolkit";
  5. import { IRelation } from "../pages/admin/relation/list";
  6. import type { RootState } from "../store";
  7. interface IState {
  8. relations?: IRelation[];
  9. }
  10. const initialState: IState = {};
  11. export const slice = createSlice({
  12. name: "relation",
  13. initialState,
  14. reducers: {
  15. pushRelation: (state, action: PayloadAction<IRelation[]>) => {
  16. state.relations = action.payload;
  17. },
  18. },
  19. });
  20. export const { pushRelation } = slice.actions;
  21. export const getRelation = (state: RootState): IRelation[] | undefined =>
  22. state.relation.relations;
  23. export default slice.reducer;