Dynamic display
Store
Types
Templates
Create data types, configure the store and use loops to display cards dynamically.
Getting Started with a real app (Episode 3)
Back to the Academy
Dynamic display
Express Summary: Create data types, configure the global store, and use loops to dynamically display cards and tasks.
Problem: Component scalability
Currently, we only have two cards in our application. If we had 10, it wouldn't be practical to manually place 10 components. We need to create a list of cards accessible throughout the application.
1. Define data types
Create the CardType
- Right-click � New � Type
- Name the type CardType
- Define the structure:
- Type: Card
- Structure: Object (since a card has multiple properties)
CardType properties
- title: string (the card title)
- tasks: array of strings (list of tasks)
This structure defines the "schema" that each card will have in our application.
2. Configure the global store
Create the data structure
- Go to the Store
- Redefine the schema:
- Name: cards (with an S for plural)
- Type: Array of CardType
Initialize default data
Fill the store with example data:
Card 1 - "To Do":
- title: "To Do"
- tasks: ["task 1", "task 2"]
Card 2 - "In Progress":
- title: "In Progress"
- tasks: [] (no tasks)
Card 3 - "Done":
- title: "Done"
- tasks: ["task 3", "task 4", "task 5"]
Test the store
- Click Reset to Store in the Preview tab
- The preview now displays the default store data
3. Dynamic card display
Transform static display into loop
- Return to the Main page
- Right-click on a card � Wrap in component
- Choose Template
Configure the loop
- In the Template, select For (for a loop)
- Define iteration over cards (store data)
- Change Preview from Once to All to see all cards
Connect dynamic data
- Select the Card component
- Modify the title property:
template.value.title - Titles update automatically
4. Dynamic task display
Add tasks property to Card component
- Go to the Card component
- Add a new property:
- Name: tasks
- Type: array of strings
- Default values: ["task 1", "task 2"]
Create a loop for tasks
- In the Card component, select the task area
- Wrap in component � Template
- Configure a For loop on the tasks property
- Switch Preview to All mode
Make task content dynamic
- Select the text of a task
- Replace fixed text with a variable:
{taskName} - Create the taskName property linked to
template.value - Tasks now display dynamically
5. Connect everything together
Link cards to store data
- Return to the Main page
- Select the Card component in the loop
- Modify the tasks property:
template.value.tasks - Each card now displays its own tasks
Test complete display
- Reset to Store to load data
- All three cards display with their respective titles and tasks
- Add a card to the store to test reactivity
Key concepts
Types
- Define data structure
- Ensure consistency throughout the application
- Enable automatic validation
Store
- Global data storage for the application
- Single source of truth
- Enables synchronization between components
Templates with loops
- For: iterates over arrays or objects
template.value: accesses the current loop element- Dynamic display based on data
Preview modes
- Once: displays one element (for design)
- All: displays all elements (for testing loops)
Advantages of this approach
- Scalability: adding cards only requires modifying the store
- Maintenance: single card definition for the entire app
- Consistency: types guarantee data structure
- Reactivity: store changes automatically reflect
Coming next: Implementing interactive logic to add and manipulate cards and tasks.