Custom Events
Last updated
Last updated
From the Bubble manual:
Custom events are a way to define a workflow in your page that can be reused multiple times ("functions" in a code-driven language).
You will find multiple uses of custom events in the template.
Read more about the basics of Custom events in Bubble manual.
Advanced practices of using Custom events are based on the connection between Custom events and Reusable elements (you can read about the basics of Reusable elements in Bubble manual)
Reusable elements can be used as sections with UI's or just workflows (no UI). A great use case for creating reusable with only workflows in it is for example integrating payments in your app. Workflows created in one place could be then reused on multiple pages throughout your app.
We are heavy proponents of Custom events as we try to avoid duplicate work as much as we can. Custom events are a great tool to keep your workflows lean, your debugging time short and your teammates happy.
Read how we use custom events and reusable elements together in this section.
Bubble actions do NOT run sequentially. Most of the time actions will not be completed in the same order as they are triggered.
In the example below you cannot be sure that every time you run this workflow step 3 will be executed after step 1 and step 5 will always be before step 2 etc. The execution order is dependent on the type of action of client-side criteria (e.g. the newly created object needs to be displayed immediately on the page etc.)
There are two ways you can force Bubble to run your actions sequentially:
a) Use 'Result from Step X' in your conditional logic. For example 'Result of step 1 unique id is not empty'
b) use Custom Events. In the example below Bubble will first trigger Custom Event A meaning all actions inside the Custom Event will be run before triggering Custom Event B.
From Bubble manual:
When a workflow is triggered in Run-mode and hits a trigger a custom event action, the first workflow will pause, the custom event will be run till completion, and the first workflow will resume. Using the debugger can be very helpful to understand the flow of actions if you are hitting some difficulties setting things up
Learn more about order of execution from this Bubble video: