{"size": 1674, "ext": "js", "max_stars_repo_path": "src/models/eventRule.js", "max_stars_repo_name": "a313901703/pack-project-front", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/models/eventRule.js", "max_issues_repo_name": "a313901703/pack-project-front", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/models/eventRule.js", "max_forks_repo_name": "a313901703/pack-project-front", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.32, "max_line_length": 81, "alphanum_fraction": 0.5161290323}
import { addApis, queryApi, editApis, removeApis } from '../services/datasource';
import { queryAll } from '../services/event_rules';

export default {
  namespace: 'eventRule',

  state: {
    data: {
      list: [],
      pagination: {},
    },
    item: {},
  },

  effects: {
    *fetch({ payload }, { call, put }) {
      const response = yield call(queryAll, payload);
      yield put({
        type: 'saveRules',
        payload: response,
      });
    },
    *add({ payload, callback }, { call, put }) {
      const response = yield call(addApis, payload);
      yield put({
        type: 'saveRules',
        payload: response,
      });
      if (callback) callback();
    },
    *edit({ payload, callback }, { call, put }) {
      const response = yield call(editApis, payload);
      yield put({
        type: 'saveRules',
        payload: response,
      });
      if (callback) callback();
    },
    *fetchOne({ payload, callback }, { call, put }) {
      const response = yield call(queryApi, payload);
      yield put({
        type: 'setRule',
        payload: response,
      });
      if (callback) callback(response);
    },
    *remove({ payload, callback }, { call, put }) {
      const response = yield call(removeApis, payload);
      yield put({
        type: 'removeRule',
        payload: response,
      });
      if (callback) callback();
    },
  },

  reducers: {
    saveRules(state, action) {
      return {
        ...state,
        data: action.payload,
      };
    },
    setRule(state, action) {
      return {
        ...state,
        item: action.payload,
      };
    },
    removeRule(state) {
      return state;
    },
  },
};
