-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[7.x] Implement anonymous components #31363
Conversation
ea9e861
to
5ffac6d
Compare
With class based components you can use colons to indicate directories like:
Will resolve to |
At a quick glance, I'm not sure it will since the function view()
{
return collect(explode('\\', Str::after($this->view, '\\View\\Components\\')))->map(function ($segment) {
return Str::kebab($segment);
})->implode('.');
} If This would also work for tags such as |
I'm also curious how something like |
@calebporzio suggested perhaps a @props directive at the top of anon components that specifies which variables should be extracted from the attribute bag and made real variables... |
b3ead30
to
f8d0cf7
Compare
f8d0cf7
to
6275dd4
Compare
This is why this PR and Blade X being appealing is so strange to me. That is completely valid in html/js and you could access that attribute via In Vue this is the main way of including components and exposing props - it solves a complicated problem on the frontend, but in PHP that simply isn't a problem and doesn't solve anything. It just creates an unnescary intermediary. Rendering on the server is totally different to rendering client side. Anyway, that's just my take on it. I'm sure this comment will get deleted. 😋 |
Actually I think it is solving a lot of problems - just because you don't see them doesn't mean they don't exist... 😄 Comments get deleted if they are off topic. Here is a problem it solves for example. Say I'm building a package that ships a nice "map" component that uses Blade component tags. It accepts some data as props but I also want to allow developers to be able to add a class to it to supply some margin or something (or any other arbitrary HTML attribute) but I also need some default values on the class: <x-map :target="map" class="mb-4 border-2" /> Within the map component: <div {{ $attributes->merge(['class' => 'flex items-center']) }}>
Do something with {{ $target }}
</div> The Managing the |
70b8399
to
d9c0788
Compare
Yeah slots just work as normal.
You can do that here as well.
This isn't a problem because views are compiled and cached. |
Yes, it handles slots just like normal components. Yes, it handles dynamic options exactly like Blade X (same syntax there). Yes, it creates a class to use a component. People can weigh the performance benefits if they wish and use them or not use them. If you're rendering thousands of input components with lots of custom attributes then it's probably going to be slow. People doing that can take a different approach. |
@garygreen For reference... rendering 1000 components on a screen takes about 45ms on my machine. So, yes it can be "slow". Rendering 1000 A more "typical" page rendering 100 components takes about 5-6ms to render (vs about 4ms using |
* upstream/master: (78 commits) [7.x] Implement anonymous components (laravel#31363) Apply fixes from StyleCI (laravel#31480) Apply fixes from StyleCI (laravel#31479) revert broken table feature move files add test for event payload of type object (laravel#31477) [7.x] Refactor route caching (laravel#31188) [6.x] Fixes appendRow on console table (laravel#31469) Apply fixes from StyleCI (laravel#31474) formatting Throw exception on empty collection (laravel#31471) Add tests for Query Builder when array value given (laravel#31464) Remove addHidden method (laravel#31463) allow afterResponse chain add getRawOriginal Remove unused use-statement Update comment [6.x] Change MySql nullable modifier to allow generated columns to be not null (laravel#31452) [6.x] Test for pushed events (laravel#31451) Fixed phpdoc ...
$attributes return nothing currently when using anonymous components.. |
Aright nvm, It used to not working on 7.x-dev but in 7.0.2 is working fine! |
If I have a package that has some anonymous components, the only way I can make them available is to create a class for them and register them individually. Is there some (undocumented) way of loading anonymous components from the package? |
Thanks for quick reply. I created an issue #32154 about it. |
This PR introduces class-less components à la Blade X. What it does under the hood is make use of a
ClassLessComponent
class (wait whut?) to pipe through all the attributes as data to the component. This way you can do this:welcome.blade.php
components/avatar.blade.php
All without a component class. This will be super useful for very simple small components and composition where you don't always need a class for.
Update
Decided to rename
ClassLessCompnent
toAnonymousComponent
.