tracardi icon indicating copy to clipboard operation
tracardi copied to clipboard

We need to replace request with asyncRemote

Open atompie opened this issue 3 years ago • 12 comments

We need to replace request with asyncRemote. Contrary to remote, asyncRemote can be used as awaitable.

Task

Find all occurrences of request calls and replace them with asyncRemote.

Use where possible the async way of calling the method. Example

try {
   const response = await asyncRemote({
     url: '/tracardi',
     method: "POST",
     data: data
   })

   // ...

} catch (e) {
   // ....
}

It is not possible to make call awaitable in useEffects. Then handle it with promise.

asyncRemote({
     url: '/tracardi',
     method: "POST",
     data: data
}).then((response) => {
            // ...            
}).catch((e)=> {
           // ...            
});

Test it thoroughly. Test every change separately.

Do not forget to set loading where it was used.

For example:

This code:

useEffect(() => {
        request({url: "/info/version"}, setLoading, () => {}, setReady);
    }, [])

Should be replaced like this. No await because it is in useEffects.

useEffect(() => {
        setLoading(true);
        asyncRemote(
            {url: "/info/version"}
        ).then((response) => {
            if (response?.status == 200) {
                setReady(response.data)
            }
        }).catch((e) => {
        }).finally(()=>{setLoading(false);});
    }, [])

mind the setLoading.

If it was not in useEffects always use it like this

try {
      setLoading(true);
       const response = asyncRemote(
            {url: "/info/version"}
        )
} catch(e) {
   // ...
} finally {
      setLoading(false);
}

atompie avatar Dec 16 '21 08:12 atompie

Hello @atompie , Can you assign this issue to me?

M-RAY47 avatar Dec 16 '21 11:12 M-RAY47

Hello @atompie , Can you assign this issue to me?

@M-RAY47 Sure. Please make a PR after first change so we can CR it and see if you are going in the right direction. Otherwise if something is not right then you may loose a lot of time.

atompie avatar Dec 16 '21 11:12 atompie

Hello @atompie , Can you assign this issue to me?

@M-RAY47 Sure. Please make a PR after first change so we can CR it and see if you are going in the right direction. Otherwise if something is not right then you may loose a lot of time.

Ok, I am on it.

M-RAY47 avatar Dec 16 '21 12:12 M-RAY47

Sorry to ask what PR and CR mean? Can you give some hint because I couldn't locate javaScript files, most of them are python files

M-RAY47 avatar Dec 16 '21 12:12 M-RAY47

@M-RAY47 Take a look at http://GitHub.com/tracardi/tracardi-gui

atompie avatar Dec 16 '21 12:12 atompie

We keep gui files in this repo. I may transfer this issue to this repo.

atompie avatar Dec 16 '21 12:12 atompie

Please fork tracardi-gui

atompie avatar Dec 16 '21 12:12 atompie

Ok I got it, thanks

M-RAY47 avatar Dec 16 '21 13:12 M-RAY47

@M-RAY47 If you are working on this task please update the code frequently as the is continuous change and some of the parts of this task may be already done.

atompie avatar Jan 14 '22 09:01 atompie

@atompie hello, sir I think you can close this issue from this project, because it should in the other project "Tracardi-gui"

M-RAY47 avatar Jan 16 '22 05:01 M-RAY47

Is this still an issue?

caseyjkey avatar Jun 22 '22 19:06 caseyjkey

@caseyjkey Yes we still have some places to refactor.

atompie avatar Jun 27 '22 08:06 atompie