Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality to remove element from dom #2192

Draft
wants to merge 3 commits into
base: 2.x
Choose a base branch
from

Conversation

tito10047
Copy link

Q A
Bug fix? no
New feature? yes
Issues Fix #2007
License MIT

Add ability to remove element from dom passing the header to response

#[AsLiveComponent()]
final class Component
{
	use DefaultActionTrait;

	#[LiveAction]
	public function removeFromDom() :Response{
                $response = new Response(null);
                $response->headers->set('X-Live-Delete', '1');
                return $response;
	}
}

@tito10047
Copy link
Author

Please be patient with this PR, I'm new to the open source world and this library is huge. But I'm big fan of it and wan't to join.
So I need little help.
How I can create tests for this feature? I haven't found anything similar in the library

@javiereguiluz
Copy link
Member

@tito10047 this feature request looks like reinventing Turbo streams inside Stimulus.

Turbo Streams allow to add/remove/replace/update/prepend/append content to existing page elements. See https://symfony.com/bundles/ux-turbo/current/index.html and also the original Turbo docs: https://turbo.hotwired.dev/

@tito10047
Copy link
Author

@javiereguiluz yes, but all twig live components is about reinventing turbo. Twig live components is about add/replace/update/append content. bud I only miss there "remove" and this PR is about that

@kbond
Copy link
Member

kbond commented Sep 27, 2024

I think this does make sense. Internally we've also talked about a renderless response: an empty response that tells the frontend to do nothing. We're thinking about a custom LiveResponse extends Response that we could ship with live components. I think we could use this new object to help with some of the verbosity of the proposal here:

// in a component live action

return LiveResponse::delete();

@smnandre
Copy link
Collaborator

smnandre commented Oct 5, 2024

Yep this is something we talked about with @dejagersh

  • pure renderless responses
  • delete responses

But also "json response" (pure data/model, without HTML)... even if it seems to be another subject with very specific implementation challenges

If we talk 'http status codes', all this could be very fun :)

  • 202 could handle async backend operation with some auto-poll-check system
  • 204 also makes sense here (when deleting a child / LiveProp collection item
  • 205 could force children to refresh
  • 206 could return only a part / block (i'd love this)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[LiveComponent] delete component from DOM
4 participants