@@ -4,11 +4,14 @@ Live Components
44**EXPERIMENTAL ** This component is currently experimental and is likely
55to change, or even change drastically.
66
7- Live components work with the `TwigComponent `_ library
7+ Live components builds on top of the `TwigComponent `_ library
88to give you the power to automatically update your Twig components on
99the frontend as the user interacts with them. Inspired by
1010`Livewire `_ and `Phoenix LiveView `_.
1111
12+ If you're not familiar with Twig components yet, it's worth taking a few minutes
13+ to familiarize yourself in the `TwigComponent documentation `_.
14+
1215A real-time product search component might look like this::
1316
1417 // src/Components/ProductSearch.php
@@ -55,16 +58,6 @@ A real-time product search component might look like this::
5558 </ul>
5659 </div>
5760
58- .. versionadded :: 2.1
59-
60- The ability to reference local variables in the template (e.g. ``query ``) was added in TwigComponents 2.1.
61- Previously, all data needed to be referenced through ``this `` (e.g. ``this.query ``).
62-
63- .. versionadded :: 2.1
64-
65- The ability to initialize live component with the ``attributes `` twig variable was added in LiveComponents
66- 2.1. Previously, the ``init_live_component() `` function was required (this function was removed in 2.1).
67-
6861Done! Now render it wherever you want:
6962
7063.. code-block :: twig
@@ -79,20 +72,19 @@ Want some demos? Check out https://ux.symfony.com/live-component#demo
7972Installation
8073------------
8174
82- Before you start, make sure you have `Symfony UX configured in your app `_.
75+ Before you start, make sure you have `StimulusBundle configured in your app `_.
8376
8477Now install the library with:
8578
8679.. code-block :: terminal
8780
8881 $ composer require symfony/ux-live-component
8982
90- If you're using WebpackEncore, install your assets and restart Encore. This is
91- not needed if you're using AssetMapper:
83+ If you're using WebpackEncore, install your assets and restart Encore (not
84+ needed if you're using AssetMapper) :
9285
9386.. code-block :: terminal
9487
95- # Don't forget to install the JavaScript dependencies as well and compile
9688 $ npm install --force
9789 $ npm run watch
9890
@@ -411,7 +403,8 @@ In this case, the model (e.g. ``publishAt``) will probably *not*
411403update correctly because JavaScript doesn't trigger the normal
412404``change `` event. To fix this, you'll need to "hook" into the
413405JavaScript library and set the model directly (or trigger a
414- ``change `` event on the ``data-model `` field). See :ref: `working-in-javascript `.
406+ ``change `` event on the ``data-model `` field). See
407+ :ref: `manually trigger an element change <javascript-manual-element-change >`.
415408
416409.. _hydration :
417410
@@ -789,6 +782,8 @@ initialized:
789782 const component = document .getElementById (' id-of-your-element' ).__component ;
790783 component .mode = ' editing' ;
791784
785+ .. _javascript-manual-element-change :
786+
792787Finally, you can also set the value of a model field directly. However,
793788be sure to *also * trigger a ``change `` event so that live components is notified
794789of the change:
@@ -2949,14 +2944,15 @@ However it is currently considered `experimental`_, meaning it is not
29492944bound to Symfony's BC policy for the moment.
29502945
29512946.. _`TwigComponent` : https://symfony.com/bundles/ux-twig-component/current/index.html
2947+ .. _TwigComponent documentation : https://symfony.com/bundles/ux-twig-component/current/index.html
29522948.. _`Livewire` : https://laravel-livewire.com
29532949.. _`Phoenix LiveView` : https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html
29542950.. _`Twig Component` : https://symfony.com/bundles/ux-twig-component/current/index.html
29552951.. _`Twig Component mount documentation` : https://symfony.com/bundles/ux-twig-component/current/index.html#the-mount-method
29562952.. _`Symfony form` : https://symfony.com/doc/current/forms.html
29572953.. _`experimental` : https://symfony.com/doc/current/contributing/code/experimental.html
29582954.. _`dependent form fields` : https://ux.symfony.com/live-component/demos/dependent-form-fields
2959- .. _ `Symfony UX configured in your app` : https://symfony.com/doc/ current/frontend/ux .html
2955+ .. _ StimulusBundle configured in your app : https://symfony.com/bundles/StimulusBundle/ current/index .html
29602956.. _`localizes its URLs` : https://symfony.com/doc/current/translation/locale.html#translation-locale-url
29612957.. _`attributes variable` : https://symfony.com/bundles/ux-twig-component/current/index.html#component-attributes
29622958.. _`CollectionType` : https://symfony.com/doc/current/form/form_collections.html
0 commit comments