Event handlers
Last updated
Last updated
In PocketBlocks, event handlers are responsible for collecting and processing events from components and queries, and executing subsequent actions. For example, for a Button component, you can add an event handler to trigger the Run query action in response to the button Click event.
Set event handlers wisely to provide a reactive and responsive user experience (UX). For example, triggering a returns all data query after insert new data query finishes enables table automatically refresh.
You can add as many event handlers as you want for a single component or query, and these event handlers run concurrently.
Different components have different events. For example, Button components only have a Click event.
Input components have Change, Focus, Blur, and Submit events.
Running a query can result in success or failure, so queries have two events: Success or Failure. You can add event handlers to queries in Query editor.
There are a number of event handler actions available in PocketBlocks for handling different scenarios. Set them in the Action dropdown list in an event handler.
See advanced on this page to know advanced settings.
Trigger the selected query.
To control a component, select a component in the Component dropdown list and call one of its methods in the Method dropdown list.
Store data in a temporary state.
Navigate to an PocketBlocks app with optional query or hash parameters.
Parameter | Function |
---|---|
URL Query | Append |
URL Hash | Append |
In the User list app, click See info to navigate to the User info app, and the detailed information of the user in the selected row will be displayed.
The User list app passes {{currentRow.id}}
in the table row as a URL Query parameter to the User info app.
The URL field of the User info app global variable will automatically resolve the URL requested by the app. In this case, the value of url.query
is {"id":3}
, so the query will retrieve the corresponding user info via {{url.query.id}}
. See the figure below.
Navigate to an external URL.
Show a floating notification of informational, success, warning, or error message.
Copy a value to the clipboard.
Export data in a certain file type (TXT, JSON, CSV, and Excel).
The action can be triggered only under a specified condition. Configure the running condition of an event handler in Only run when option, and then the event handler runs only when this condition evaluates to true
.
Debounce and Throttle reduce the frequency of triggering the action.
Debounce delays an action. Once a debounce time is set, the action will not be executed immediately following the event until the debounce time passes. If the event occurs again before the time ends, the debounce time will be retimed. For example, an input component triggers a query once the user changes the text. If the query is expensive to run and you don't want to run it after every single character is typed, you can delay the execution of the query by setting the debounce time. Then the query will only run after the user finishes typing.
Throttle lets an action happen only once during a specified period of time. By default, every single event triggers an action, but sometimes running an action can be costly. For example, you set an event handle to trigger Run query action to update data in response to the Click event, but you find that query too expensive to run, then you can set a throttle time to let the query run only once within a given time.