0
    import { call, put } from 'redux-saga/effects';
    import axios from 'axios';

    import parser from 'fast-xml-parser';
    import he from 'he';

    import { getItems, getInputValue } from '../../actions/getItemsAction';


let xml = `<?xml version="1.0" encoding="utf-8"?>
      <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
        <soap12:Header>
          <AuthSoapHeader xmlns="http://tempuri.org/">
            <Login></Login>
            <Password></Password>
          </AuthSoapHeader>
        </soap12:Header>
        <soap12:Body>
          <FindClientFL xmlns="http://tempuri.org/">
            <search>
              <Request>
                <RequestId>1</RequestId>
              </Request>
              <Details>
                <StateCode>**Сюда параметр ${param}**</StateCode>
              </Details>
            </search>
          </FindClientFL>
        </soap12:Body>
        </soap12:Envelope>
      `;
    export default function* workerFetchData() {
  try {
    const data = yield call(() => {
      let config = {
        headers: {
          'Content-Type': 'application/soap+xml; charset=utf-8, application/json;',
        },
      };
      return axios
        .post(
          `http://test`,
          xml,
          config
        )
        .then(data => (data.status === 200 ? data.data : {}))
        .then(data => {
          if( parser.validate(data) === true) { //optional (it'll return an object in case it's not valid)
            return parser.parse(data,options)['soap:Envelope']['soap:Body']['FindClientFLResponse']['FindClientFLResult'];
          }
        });
    });
    console.log(getInputValue())

    yield put(getItems(data));
  } catch (error) {
    yield put(error => console.log(error));
  }
}

1 ответ 1

0

передать в воркер как args. Например:

function* workerFetchData(args) {
    yield put (action(args)) 

как должен выглядеть экшн:

const action = ({arg1, agr2, arg3 ..., argN}) => {
    return {
        type:"TYPE_ACTION",
        arg1,
        arg2,
        arg3,
        ...,
        argN
    }

Как вызвать в компаненте диспатч вотчера:

dispatch({
    type: "WATCH_TYPE_ACTION",
    arg1,
    arg2,
    arg3,
    arg4
  })

И, наконец, вотчер:

export function* watcherFetchData (){

    yield takeEvery ('WATCH_TYPE_ACTION', workerFetchData)
}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.