Skip to content

Commit 57c2921

Browse files
committed
minor #2025 [Cookbook] - fix component_architecture (WebMamba)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- [Cookbook] - fix component_architecture | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Issues | Fix | License | MIT Commits ------- 686ab07 [Cookbook] - fix component_architecture
2 parents e6be7a8 + 686ab07 commit 57c2921

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

ux.symfony.com/cookbook/component_architecture.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ title: Component architecture
33
description: Rules and pattern to work with components
44
image: images/cookbook/component-architecture.png
55
tags:
6-
- javascript
7-
- symfony
6+
- JavaScript
7+
- Symfony
88
author: Mathéo Daninos
99
published_at: '2024-08-02'
1010
---
1111

1212
## Introduction
1313

14-
In SymfonyUX exist two packages: [TwigComponents](https://symfony.com/bundles/ux-twig-component/current/index.html) and [LiveComponent](https://symfony.com/bundles/ux-live-component/current/index.html).
14+
In Symfony UX exist two packages: [TwigComponents](https://symfony.com/bundles/ux-twig-component/current/index.html) and [LiveComponent](https://symfony.com/bundles/ux-live-component/current/index.html).
1515
Those two packages allow you to create reusable components in your Symfony application.
16-
But the component architecture is not exclusive to Symfony, it is a design pattern that can be applied to any programming language or framework.
17-
And the js world already implement this architecture for long time, on many different frameworks like React, Vue, or Svelte.
18-
So, a set of rules and pattern has already be defined to work with components. This is why SymfonyUX try to be as close as possible to those rules.
19-
So let's see what are those rules!
16+
But the component architecture is not exclusive to Symfony, it's a design pattern that can be applied to any programming language or framework.
17+
And the Javascript world already implements this architecture for long time, on many different frameworks like React, Vue, or Svelte.
18+
So, a set of rules and patterns has already be defined to work with components. This is why Symfony UX tries to be as close as possible to those rules.
19+
So, let's see what those rules are!
2020

2121
## 4 Rules
2222

@@ -43,27 +43,25 @@ Or you can make composition with the following syntax:
4343

4444
```twig
4545
<twig:Card>
46-
<twig:CardHeader>
47-
<h2>My Card</h2>
48-
</twig:CardHeader>
49-
<twig:CardBody>
50-
<p>This is the content of my card.</p>
51-
</twig:CardBody>
46+
<twig:Icon name="info"/>
47+
<twig:Button>
48+
<twig:Icon name="close" />
49+
</twig:Button>
5250
</twig:Card>
5351
```
5452

55-
So here we Card component, and we give to the content of this component mutliple other components.
53+
So here we have a Card component, and we give to the content of this component two other components.
5654

5755
### Independence
5856

59-
This is a really important rule, and not obvious. But your component should leave on his own context,
60-
he should not be aware of the rest of the page. You should to talk one component into a page, to another and it should work exactly the same.
61-
This rule make your component trully reusable.
57+
This is a really important rule, and not obvious. But your component should live on his own context,
58+
it should not be aware of the rest of the page. You should be able to take a component into a page, from another and it should work exactly the same.
59+
This rule makes your component truly reusable.
6260

6361
***How does it work into Symfony?***
6462

65-
Symfony keep the context of the page into the context of your component. So this your own responsability to follow this rules.
66-
But notice that if there are conflic between a variable from the context page and your component, your component context override the page context.
63+
Symfony keeps the context of the page into the context of your component. So this your own responsibility to follow those rules.
64+
But notice that if there are conflicts between a variable from the context page and your component, your component context overrides the page context.
6765

6866
### Props
6967

@@ -119,7 +117,7 @@ And when the loading is done, the state `loading` can be set to `false` and the
119117

120118
***How does it work into Symfony?***
121119

122-
In symfony you 2 different approach to handle state. The first one is to use stimulus directly
120+
In Symfony you have two different approaches to handle state. The first one is to use stimulus directly
123121
in to your component. What we recommend to do is to set a controller stimulus at the root of your component.
124122

125123
```twig
@@ -161,9 +159,11 @@ the following component:
161159
#[AsLiveComponent]
162160
class Button
163161
{
164-
#[LiveProp]
162+
use DefaultActionTrait;
163+
165164
public int $clicks = 0;
166165

166+
#[LiveAction]
167167
public function increment()
168168
{
169169
$this->clicks++;

0 commit comments

Comments
 (0)