-
-
Notifications
You must be signed in to change notification settings - Fork 388
Description
Hi 👋🏻
Small suggestion to improve the current usage of ComponentToolsTrait::emit()
, for now, the method defines the following signature:
public function emit(string $eventName, array $data = [], ?string $componentName = null): void
{
$this->liveResponder->emit($eventName, $data, $componentName);
}
The main issue here IMHO is the usage of $data
, AFAIK, we can only pass arrays of scalars, this prevent us from using objects when communicating between components using only the PHP approach (without emitting from the JS code), I'm not sure how it can be improved (after discussing with @smnandre, maybe we can use a new attribute #[ExposedStimulusObject]
for example, this attribute would allow us to say that this object is serialized/deserialized when emitting the event and that if it contains sensitive data, we're fully responsible for any leak) but I think it could be a good idea as we sometimes want to emit events that contains objects (think of notifications, ValueObject's, DTO's, etc).
Any thoughts? 🙂
PS: This approach would not allow to emit event with objects from the frontend (as we need to obtain and keep the FQCN of the object to serialize/deserialize) but this kind of use case if strongly tied to the PHP usage of the emit
method.