How to think about multiple on success events

  • dfeinberg5-1303966468056023112

    Danny

    4 months ago

    When building an API, there are events, such as on success. However, there are also the same events when building different workflows. I'm curious if anyone has thoughts on when to do it one way vs. the other (screenshots attached). They way I've been thinking about it is setting the event on the API itself if I know it's something I'll always want to do in that instance and setting the event in the course of a workflow if it's specific to a certain instance, but not necessarily something I would want to do in all cases where I might call the API. Also, does the event within the API get called before the event in the workflow?

    Hopefully that makes sense!
    1303966468421058581-image.png
    1303966468765122580-image.png
  • andreasmoller-1303985843211473006

    Andreas Møller

    4 months ago

    Events on the API are executed before the ones specified on the action: https://toddle.dev/docs/call-apis
  • andreasmoller-1303987715368423424

    Andreas Møller

    4 months ago

    In most cases I prefer to have the events on the API, but there are times where the events on the Action are useful.

    Imagine that you have a list of items that is using a repeat formula. Each item has a button on that deletes the item.
  • When you click delete you want to first call the delete API with the id of the item.
    1303987889540960266-CleanShot_2024-11-07_at_08.41.312x.png
  • And then show a toast message saying the item was deleted
    1303988035075178556-CleanShot_2024-11-07_at_08.42.302x.png
  • andreasmoller-1303988319708774400

    Andreas Møller

    4 months ago

    You cannot call the action to show the toast form the Event in the API panel, since you dont have access to the name from the repeat item.
  • dfeinberg5-1304291283396726815

    Danny

    4 months ago

    Ah, that makes sense. That seems pretty aligned to what I've been doing, but helpful to hear another explanation. Thanks @Andreas Møller !

Stop scrolling. Start building.

toddle is a visual web app builder that rivals custom code — but accessible to your entire team!

Try toddle — it's free!

© Copyright 2024 toddle. All rights reserved.