rescript-lang.org icon indicating copy to clipboard operation
rescript-lang.org copied to clipboard

How to create generator function

Open clifflo opened this issue 5 years ago • 4 comments

In the documentation I have noticed that we can use promise to handle asynchronous request. AFAIK, I assume that yield is not useable in Rescript context. However, in redux-saga we have to use functions with an asterisk besides it. For example, function* mySaga() { yield takeEvery("USER_FETCH_REQUESTED", fetchUser); } function* mySaga() { yield takeLatest("USER_FETCH_REQUESTED", fetchUser); }

So for Rescript how can I write that out then?

clifflo avatar Feb 03 '21 03:02 clifflo

Unfortunately ReScript doesn't semantically support generators. You'd probably need to write your generators logic as plain JS / raw expressions.

ryyppy avatar Feb 04 '21 10:02 ryyppy

bummer :-(

ruifortes avatar Feb 19 '21 20:02 ruifortes

to be fair, the idea of redux-saga doesn't really find any good use-case in ReScript (beside interop), since the language itself offers enough facilities to express complex state machines. I've used sagas a lot myself back then and have seen it in a handful of codebases,... but never had a need for it ever since I've used ReScript & React hooks.

ryyppy avatar Mar 05 '21 08:03 ryyppy

I will close this for now, since this question usually would go to the forum

ryyppy avatar Apr 01 '21 14:04 ryyppy