Skip to main content

Example approach: Refactoring stories

Walk through common refactoring steps in Tines stories using simple scenarios.

Written by Yanni Hajioannou
Updated over 2 weeks ago

Overview

One of the best practices to follow when building stories in Tines is refactoring. In this article, we cover some simple scenarios that showcase the most common methods of optimizing your story builds.

Tines references

Before getting started, we recommend familiarizing yourself with the functionality this article covers:

Make it happen

Collapsing multiple Event Transform actions

In this video, we look at an example with four Event Transform actions. The first three are using functions to capture different aspects of the date: day, month, and year. The final Event Transform is a reference of the upstream actions' values.

Refactoring: Instead of calculating each date piece in individual actions, we use that same series of functions in the fourth "Total Info" action. Once consolidated, we are left with the same end results of day, month, and year within one action, instead of across four.

A Tines storyboard showing the refactored "Collapsing multiple Event Transform actions" example. An Event Transform action named "Total Info" is selected, with the Payload section visible on the right. The Builder view is highlighted with a red border, showing a single payload object with three keys: day using the formula DATE(NOW(), "%d"), month using DATE(NOW(), "%m"), and year using DATE(NOW(), "%Y"), consolidating all three date calculations into one action.

Reducing actions with functions

In this video, we look at an existing story that uses Explode, Implode, and a Condition action to check an array of spells returned from an HTTP Request action and see if the "Feast" spell is included in the array.

Note: In this video, you'll see the action referred to as a "Trigger." This action has since been renamed to "Condition action." The functionality is the same.

Refactoring: Instead of building out this logic through multiple actions, this can be done using the INCLUDES function, which returns TRUE if the target includes the specified value. Wrapping the array in TEXT first makes it easier to check with INCLUDES. We build this into a Condition action to handle both TRUE and FALSE scenarios, if needed.

A Tines storyboard showing the refactored "Reducing actions with functions" example. An HTTP Request action named "Get all Spells" connects to a Condition action named "Feast spell?", which is highlighted with a red border. The Build panel on the right shows the Condition action's configuration: the Rules section contains the formula INCLUDES(TEXT(get_all_spells.body.results), "Feast") with the rule type set to "formula is true." Below, the event data panel shows the output with rule_matched: true highlighted with a red arrow, confirming the spell was found in the array.

Review the results

We optimize these stories by reducing the total count of actions on the storyboard. It's also easier to troubleshoot when all of the formula logic is within one action.

Did this answer your question?