-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
callback functions for steps #31
Comments
This is an example of a way I'd like to use fonda on the frontend
|
You can probably use I wonder if you have enough info in the |
After implementing the injector step I think there is no way to implement this feature with taps. Or at least I can't think on any way. To implement it with taps, a function should be implemented that traverses the steps and adds taps after each step that provides a But since the steps in a injector step are dynamically injected by fonda, I can't think on a way to also traverse those steps and add the taps for them, without modifying fonda itself. Adding the :on-* natively wouldn't add much complication to the library and can be implemented with few lines of code. And of course they would be optional. I propose to implement them natively so fonda could be used on the frontend with libraries like re-frame |
I am not clear or why you'd like to inject the callback though ..are these steps dynamic? In your above example the function |
I agree the change is not that big, I just wonder if we can use |
On the following example:
where the injected step wants to use a callback function as well... I wouldn't know how to implement that with taps |
So in one of the our functions I have to do the same and what I do is to inject a |
I think the problem is that there is no possibility to add a tap for errors... all the errors logic would be in a error-handler |
Yep but I would open a different issue for that one, the tap solution is only for successful completion |
Or we can keep talking here but to me these two are separate use cases |
implementing the callbacks on the steps allows me to do
where on-fetch is a function that dispatches ::on-fetch, which removes/adds the error on db (if fetch application-data returns anomaly, sets error, otherwise, removes) but maybe what I am trying to do is different enough that deserves it's own "fonda for frontend" library |
at the end, it's a very specific case for frontend management of errors. never mind if you think it doesn't make sense on the actual fonda |
As you know I am trying to keep the number of callbacks to a minimum. In particular semantically a tap after a successful step is a callback of sorts so I guess we are covered already there. It seems you have both success and error logic in one function though...maybe...can you show me the implementation of that callback? |
And thanks for writing a tangible use case down, it really is helpful! |
no prob! I have a generic function that sets/removes errors:
Then I use it like this:
|
but you know, I might be over-engineering things lol |
Ah ah, ok that is what I was missing, soooo...given that in fp land we don't like ifs AND we are basically doing that if in Fonda to understand if to error out, my humble opinion is that it should not be duplicated in your library and we should provide a better API for your use case. Tap is for success, and maybe we should have an error step for anomalies/errors. All the ifs should be baked in fonda |
yes yes agree that would be pretty, to handle all in fonda... I'll do some brainstorming to what the api for error taps could be...I'm out of ideas right now because we don't want to break the principle that errors short-circuit the steps flow |
I would like (can't wait to!) use Fonda on the frontend with re-frame. I'd like to define a sequence of steps running asynchronous functions that trigger events as they fail/succed.
I propose to add the following options to each step:
:on-start
Called before the processor is executed:on-success
Called after the processor executed successfully:on-error
Called after the processor failed (by anomalies or exceptions):on-complete
Called after the processor was executed, either failing or succeeding.The value for each of the options would be a function that gets the result returned by the processor function.
The text was updated successfully, but these errors were encountered: