Skip to content

Commit

Permalink
Start drawing Live factory/renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
smnandre committed Nov 14, 2024
1 parent 89c7fa9 commit 33ed519
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 0 deletions.
80 changes: 80 additions & 0 deletions src/LiveComponent/src/LiveComponentFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\UX\LiveComponent;

use Symfony\Component\PropertyAccess\Exception\ExceptionInterface as PropertyAccessExceptionInterface;
use Symfony\UX\LiveComponent\EventListener\DeferLiveComponentSubscriber;
use Symfony\UX\TwigComponent\ComponentFactory;
use Symfony\UX\TwigComponent\ComponentRendererInterface;
use Symfony\UX\TwigComponent\Event\PostMountEvent;
use Symfony\UX\TwigComponent\Event\PreMountEvent;
use Symfony\UX\TwigComponent\Event\PreRenderEvent;

/**
* @author Simon André <[email protected]>
*
* @internal
*/
class LiveComponentFactory
{
public function __construct(
private ComponentFactory $inner,
) {
}

protected function onPreMount(PreMountEvent $event)
{
// model binding parser

// DataModelLivePropsSubscriber
// data-model="live"
// $event->setData($data);
}

/**
* @param PostMountEvent $event
* @return void
*
* @see DeferLiveComponentSubscriber
*/
protected function onPostMountLazy(PostMountEvent $event)
{
// extraData(loading, loading-tag)...
// $event->setData($data);
}

/**
* @param PostMountEvent $event
* @return void
*
* @see QueryStringInitializeSubscriber
*/
protected function onPostMountQueryString(PostMountEvent $event)
{
// AddLiveAttributes
// $event->setTemplate($template);
// $event->setVariables($variables);
//
//
// $queryStringData = $this->queryStringPropsExtractor->extract($request, $metadata, $event->getComponent());
//
// $component = $event->getComponent();
//
// foreach ($queryStringData as $name => $value) {
// try {
// $this->propertyAccessor->setValue($component, $name, $value);
// } catch (PropertyAccessExceptionInterface $exception) {
// // Ignore errors
// }
// } }
}
}
72 changes: 72 additions & 0 deletions src/LiveComponent/src/LiveComponentRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\UX\LiveComponent;

use Symfony\UX\LiveComponent\EventListener\ResetDeterministicIdSubscriber;
use Symfony\UX\TwigComponent\ComponentRendererInterface;
use Symfony\UX\TwigComponent\Event\PostRenderEvent;
use Symfony\UX\TwigComponent\Event\PreRenderEvent;

/**
* @author Simon André <[email protected]>
*
* @internal
*/
class LiveComponentRenderer implements ComponentRendererInterface
{
public function __construct(
private ComponentRendererInterface $inner,
) {
}

public function createAndRender(string $name, array $props = []): string
{
$this->inner->createAndRender($name, $props);
}

protected function onPreRender(PreRenderEvent $event): ?string
{
// AddLiveAttributes
// $event->setTemplate($template);
// $event->setVariables($variables);
}

/**
* @see DeferLiveComponentSubscriber
*/
protected function onPreRenderLoading(PreRenderEvent $event)
{
// change template
// $event->setTemplate($template);

// $variables['loadingTemplate'] = self::DEFAULT_LOADING_TEMPLATE;
// $variables['loadingTag'] = self::DEFAULT_LOADING_TAG;
// $variables['loading'] = $mountedComponent->getExtraMetadata('loading');
// $variables['componentTemplate'] = $componentTemplate;
//
// $event->setVariables($variables);
}

/**
* @param PostRenderEvent $event
* @return void
*
* @see ResetDeterministicIdSubscriber
*/
protected function postRender(PostRenderEvent $event)
{
// $event->setHtml($html);
// if (!$this->componentStack->getCurrentComponent()) {
// $this->idCalculator->reset();
// }
}
}

0 comments on commit 33ed519

Please sign in to comment.