text: import { query,add,remove,edit,editStatus } from '../services/vendor_meter';
  
  export default {
    namespace: 'vendor_meter',
    state: {
      data:[],
      meta: {pagination: {total: 0, per_page: 0}},
      loading: true,
      name:''
  
    },
    effects: {
      *fetch({ payload ,callback}, { call, put }) {
        yield put({
          type: 'changeLoading',
          payload: true,
        });
        const response = yield call(query, payload);
        console.log(response)
        if(response.status===200){
          yield put({
            type: 'save',
            payload:  response.data
          });
          yield put({
            type: 'changeLoading',
            payload: false,
          });
  
          if (callback) callback();
        }
      },
      *fetchAndPush({ payload,callback }, { call, put }) {
        // yield put({
        //   type: 'changeLoading',
        //   payload: true,
        // });
        const response = yield call(query, payload);
        console.log(response)
        if(response.status===200){
          yield put({
            type: 'saveAndPush',
            payload:  response.data
          });
          // yield put({
          //   type: 'changeLoading',
          //   payload: false,
          // });
          if (callback) callback();
        }
  
      },
      *add({ payload, callback }, { call, put }) {
        const response = yield call(add, payload);
        console.log(response)
        if(response.status===200){
          if (callback) callback();
        }
      },
      *edit({ payload, callback }, { call, put }) {
        const response = yield call(edit, payload);
        console.log(response)
        if(response.status===200){
          if (callback) callback();
        }
      },
      *editStatus({ payload, callback }, { call, put }) {
        console.log(payload)
        const response = yield call(editStatus, payload);
        console.log(response)
        if(response.status===200){
          if (callback) callback();
        }
      },
      *remove({ payload, callback }, { call, put }) {
        const response = yield call(remove, payload);
        if(response.status===200){
          if (callback) callback();
        }
      },
    },
  
    reducers: {
      save(state, action) {
        return {
          ...state,
          data: action.payload.data,
          meta:action.payload.meta
        };
      },
      saveAndPush(state, action) {
        // console.log('[...state.data,...action.payload.data]',[...state.data,...action.payload.data]);
        const data=[...state.data,...action.payload.data];
        // data.map((item,index)=>{
        //   item.index=index
        // })
        return {
          ...state,
          data: data,
          meta:action.payload.meta
        };
      },
      changeLoading(state, action) {
        return {
          ...state,
          loading: action.payload,
        };
      },
      saveName(state,action){
        return {
          ...state,
          name: action.payload,
        };
      }
    },
  };
  