未捕获(承诺)TypeError:updatePropertyInfo(...)。则不是函数

时间:2018-08-30 18:04:28

标签: javascript reactjs rest redux promise

我正在尝试进行一系列服务调用,并在等待服务解析时用微调框将其包装起来。 我正在努力使这些承诺成为现实。我认为这是解决此错误所需的工作。如何修复我的动作,以便testAction起作用?

当这些动作在testAction之外被触发时,这些动作就会运行并运行。

export function testAction(dispatch) {
    return new Promise((resolve, reject) => {
        interstitialHandler(updatePropertyInfo()
            .then(fetchCoverages(dispatch, resolve))
            .catch((dispatch, reject)), {highBrand: false});
    });
};

此承诺会触发两个服务调用(一个PUT),然后需要触发一个GET。

PUT:

export function updatePropertyInfo() {
    return (dispatch, getState) => {
        const {form} = getState();
        const body = form.formName.values;
        dispatch(putPropertyInfo(getTransactionId(), body));
    };
}

export function putPropertyInfo(transactionID, body = '') {
    let data = {...body};

    const serviceUrl = CANNOT SHARE THIS DATA, 
    BUT THE CALL WORKS OUTSIDE THE PROMISE;

    return {
        types: [
             PUT_PROPERTY_INFO__UPDATE_DATA, 
             PUT_PROPERTY_INFO__UPDATE_SUCCESS, 
             SET_TRAP_ERROR_MESSAGE
        ],
        promise: {
            url: serviceUrl,
            method: 'put',
            withCredentials: true,
            headers: {
                'Content-Type': 'application/json'
            },
            data: data,
            timeout: 15000
        }
    };
}

GET:

export function fetchCoverages() {
    return dispatch => {
        let transactionID = getTransactionId();

        if (transactionID) {
            dispatch(getCoverages(transactionID));
        } else {
            if (pushState()) {
                transactionID = getTransactionId();
                dispatch(getCoverages(transactionID));
            } else {
                dispatch({
                    type: SET_TRAP_ERROR_MESSAGE
                });
            }
        }
    };
}

export function getCoverages(transactionID) {
    let params = {};

    const serviceUrl = CANNOT SHARE THIS DATA, BUT THE 
    CALL WORKS OUTSIDE THE PROMISE;

    return {
        types: [
                GET_COVERAGES__FETCH_DATA,
                GET_COVERAGES__FETCH_SUCCESS, 
                SET_TRAP_ERROR_MESSAGE
        ],
        promise: {
            url: serviceUrl,
            params,
            method: 'get',
            withCredentials: true,
            timeout: 15000
        }
    };
}

0 个答案:

没有答案