Working with formulas
Discover how to effectively work with formulas to manipulate data and streamline logic in Nordcraft.
Create a formula
To create a new formula in Nordcraft:
- 1Navigate to the data panel with no element selected
- 2Click the + button in the Formulas section
- 3Enter a name for your formula
- 4(Optional) Add inputs with test values to use while developing the formula
- 5(Optional) Expose the formula in context to make it available to child components
- 6(Optional) Delete the formula when it is no longer needed
- 7Define the formula logic using the formula editor
Test values for the inputs are particularly useful during development as they allow you to verify your formula works correctly without needing to set up actual data flows.
Accessing data in formulas
Formulas can access various data sources within your component:
- Inputs: Formula-specific inputs
- Attributes: Values passed into the component
- Variables: Variables defined in the component
- API data: Results from API calls
- Context values: Data exposed by parent components
- Component formulas: Formulas defined in the component
- Global formulas: Formulas defined at the global project level
Reusable formulas
To keep your formulas efficient and maintainable, define reusable formulas that can be referenced throughout your project. If you find yourself repeating the same formula logic in multiple places, follow these steps:
- 1Create a component-level formula in the data panel
- 2Give it a descriptive name
- 3Define its logic once
- 4Reference it wherever needed
Reusable formulas provide these benefits:
- Reduce duplication in your codebase
- Improve maintainability (changes in one place affect all usages)
- Enhance performance through result caching (due to their pure function nature)
Nested formulas
In Nordcraft you can create nested formulas where one formula can call another:
- Build small, focused formulas that perform specific tasks
- Combine these smaller formulas to create more complex logic
- This modular approach makes your code more readable and easier to maintain
By breaking down complex operations into smaller, reusable pieces, you can build sophisticated functionality while keeping each formula simple and focused on a single responsibility.
Common formula examples
The formula editor supports many JavaScript-like operations, presented through Nordcraft's visual approach. Below are some common formula examples to help you get started.