简体   繁体   中英

How to return or export result of function javascript from service file to use in another file

Function Of Service

export const deviceInfoRequest = async (callback) => {
    var request = new DeviceInfoMessage();
    var AuthToken = 'ciOiJIUzI1NiIsInR5cCI6IkpXVCJ9';
    client.deviceInfo(request, {'x-authorization': AuthToken}, (err, response) => {
        var dataDevicename = response.getDevicename();
        var dataDeviceid = response.getDeviceid();
        console.log("DeviceName==>>>>",dataDevicename);     
        console.log("DeviceId==>>>>",dataDeviceid); 
        this.callback(dataDevicename,dataDeviceid);
    });
}

=======> Result of "console.log"=="DeviceName== test" and "DeviceId==>>>> 0xdeadbeef".

Function Of Sagas

function* getDeviceInfo({ payload }) {
    try {
        const deviceInfoData = yield call(deviceInfoRequest, payload);
        console.log("deviceInfoSagasssssssssssssssssssssss", deviceInfoData)
        if (deviceInfoData.status === 200) {
            yield put(showDeviceInfoAction(deviceInfoData.data));
        }
    } catch (error) {

    }
}

=======> Result of "console.log"=="deviceInfoSagasssssssssssssssssssssss undefined"

Well you need to import that function in your "Sagas" function file, try:

import { deviceInfoRequest } from "../PATH_TO_FUNCTION";

Then you can use that function. Also, if you want to evaluate that function just do deviceInfoRequest()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM