You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, if we want to call the method after the fetch trait is complete or error, we need to add all the handlers into the fetch trait’s onComplete and use the disabled to control whether they should be executed. In addition, we also need to add the global states to mark the different trigger ways and clear their values after using it which brings a lot of mental burdens.
For example, I want to implement this demand:
when click button1: call api → set state value →set input1's value to button1 after complete
when click button2: call api → set state value → set input1's value to button2 after complete
Because they use the same fetch trait to call the same API, they use the same trigger. However, the things the buttons need to do in onComplete is different.
Do you mean to use the different fetch traits to call the same API and then they can use the different onComplete to solve the problem?
They can't reuse the parameters and some common logic and so on if use the different fetch traits to call the same API. I think this isn't the best way to solve the problem.
The Problem
Currently, if we want to call the method after the fetch trait is complete or error, we need to add all the handlers into the fetch trait’s
onComplete
and use thedisabled
to control whether they should be executed. In addition, we also need to add the global states to mark the different trigger ways and clear their values after using it which brings a lot of mental burdens.For example, I want to implement this demand:
button1
: callapi
→ setstate
value →setinput1
's value tobutton1
after completebutton2
: callapi
→ setstate
value → setinput1
's value tobutton2
after completeThe whole application schema to be this:
The logic turn to JavaScript code just like this:
🙃 There are so awful to do this.
Improvement
To improve this, I want to define whether the method is the async function.
The spec to define a method to be the async function may be like this:
Then if the method is an async function, it would support the
onComplete
andonError
in the schema to call other methods.The whole schema may be like this:
The logic turn to JavaScript code just like this:
Compare that to the before schema:
isClickButton1
,isClickButton2
onComplete
from the fetch trait to thebutton1
andbutton2
The text was updated successfully, but these errors were encountered: