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

[LiveComponent] add LiveProp name to modifier function #2652

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from

Conversation

jannes-io
Copy link
Contributor

@jannes-io jannes-io commented Mar 23, 2025

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

Implements proposal 2 from the examples in the RFC.

Personally I would just pass the entire liveprop metadata object to this function instead of only the name, but it's marked internal so I'm not sure if we should be exposing it to users like that.

@carsonbot carsonbot added Feature New Feature LiveComponent Status: Needs Review Needs to be reviewed labels Mar 23, 2025
@jannes-io jannes-io force-pushed the modifier-prop-name branch 2 times, most recently from 631af7c to 0a949c8 Compare March 23, 2025 19:40
@@ -2617,7 +2617,9 @@ definition::

Then the ``query`` value will appear in the URL like ``https://my.domain/search?q=my+query+string``.

If you need to change the parameter name on a specific page, you can leverage the :ref:`modifier <modifier>` option::
If you need to change the parameter name on a specific page, you can leverage the :ref:`modifier <modifier>` option
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of remarks here (unrelated to wether we will move forward with this PR or not :) )

First of all: thank you for thinking immediately "documentation". That's a very nice habit to have.

Now for the changes here: I think we should not change the existing documentation, but instead we may add a dedicated paragraph after this part.

The current version does it jobs, covers the feature and how most developers use it, while keeping things small / easy to understand.

Moreover, using a prefix instead of an alias here would offer less possibilities than before, so we should probably not describe this solution in first examples, but only when a prefix could be justified (many identical components in the same page ? still not sure to be honest)

So here I think a dedicated paragraph after this one, for more advanced use case, could be more appropriate.

@@ -135,7 +135,7 @@ public function withModifier(object $component): self
throw new \LogicException(\sprintf('Method "%s::%s()" given in LiveProp "modifier" does not exist.', $component::class, $modifier));
}

$modifiedLiveProp = $component->{$modifier}($this->liveProp);
$modifiedLiveProp = $component->{$modifier}($this->liveProp, $this->getName());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a change like this, a test would be needed. Especially for things related to query, URL, etc.

(The fact tests do pass after your changes does not proves it does work (nor that our current suite of test is good enough, to be fair))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to the existing test, I don't see the need to make a separate test for just this param unless there are some edge cases that aren't entirely obvious to me at this time.

@weaverryan
Copy link
Member

weaverryan commented Apr 1, 2025

I personally don't have a big issue with removing the internal. Very thoughtful to realize that issue :).

Alternatively, if there is something you need on the metadata, we could add it to LiveProp

@smnandre
Copy link
Member

smnandre commented Apr 2, 2025

I don't see a problem to pass the second argument 👍
(we should precise in docs this information may not be the original name of the prop in the class)

Passing the metadata is not something I'd love to do, without an absolute need to do so.
Anything we expose cannot then be changed afterwards.. And it did bring us in situations were we're a bit "stuck" to move forward / improve features.

@jannes-io
Copy link
Contributor Author

jannes-io commented Apr 6, 2025

I don't see a problem to pass the second argument 👍 (we should precise in docs this information may not be the original name of the prop in the class)

Okidoki, I can do the requested changes to the docs and add some tests to finish off this PR. Could you give me a case where the property name could be different from the name in the metadata? Or where I could find code that could create this side-effect so I can try to reproduce? Just want to understand what the implications might be there.

Passing the metadata is not something I'd love to do, without an absolute need to do so. Anything we expose cannot then be changed afterwards.. And it did bring us in situations were we're a bit "stuck" to move forward / improve features.

Agreed 😄

@jannes-io jannes-io force-pushed the modifier-prop-name branch from 0a949c8 to d3c8127 Compare April 6, 2025 13:56
Comment on lines +2654 to +2656
.. versionadded:: 2.25

The property name is passed into the modifier function since LiveComponents 2.25.
Copy link
Contributor Author

@jannes-io jannes-io Apr 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This'd have to be updated to the actual release version, I just took the next one.

@jannes-io jannes-io requested a review from smnandre April 6, 2025 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New Feature LiveComponent Status: Needs Review Needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[LiveComponent] Include prop name in the url modifier function
4 participants