Simplify your VIEW COMPONENTS with dry-initializer

  Рет қаралды 1,175

Rapid Ruby

Rapid Ruby

Жыл бұрын

I’m going to show you a neat little library from the dry-rb project, dry-initializer. It can be really useful to help reduce boilerplate code in ViewComponent’s and service objects.
Check out the dry-initializer docs:
dry-rb.org/gems/dry-initializ...
Source code available here:
github.com/phawk/rapid_dry_in...
P.s. Want access to next week's video right now? Head on over and sign up on rapidruby.com now!
---
Has this video helped you out? Consider buying me a coffee to say thanks and support future content like this, thanks!
app.payhere.co/rapid-ruby/buy...
You can also find more content like this, including premium courses and exclusive community and mentorship to help you level-up! Head over to rapidruby.com and use the code RRKZbin for a discount!

Пікірлер: 13
@jankomarohnic
@jankomarohnic Жыл бұрын
Been using dry-initializer with View Component in a previous company, works wonderfully 👌
@stpaquet
@stpaquet Жыл бұрын
very useful. I need to delve a bit more into view_component.
@danbeggan
@danbeggan Жыл бұрын
Great tip
@dencam
@dencam Жыл бұрын
Quality tutorials. Give us more. Thank you please
@rapid-ruby
@rapid-ruby Жыл бұрын
Haha I’ll try my best!
@bobmaerten
@bobmaerten Жыл бұрын
Seems weird to me that an "option" is required by default :/ Great tooling though.
@rapid-ruby
@rapid-ruby Жыл бұрын
Hah yeah, I think the naming on that one is just a little conflated, due to them calling normal non-keyword arguments ‘param’. It probably stems from before keyword arguments where in ruby core, and they were used more as a hash of options at the end of the list of your normal arguments.
@tomasvalent3876
@tomasvalent3876 Жыл бұрын
I was wondering for ages why this isn't a thing in vanilla Ruby 🤔
@rapid-ruby
@rapid-ruby Жыл бұрын
Yeah that would be neat!
@tombranson9341
@tombranson9341 Жыл бұрын
I think that you've jumped the shark in this video suggestion. Personally, I believe that no additional libraries should be installed until all proper solutions have been exhausted. In this example, it sort of missed the point a little bit about the definition of Web Components (ie View Components in this case), a "Thumbnail" is a separate component to a Card, a thumbnail can be reused in other places, thus a Thumbnail component should be created, and in the initializer, place nil as the default, and in the call method put the image tag with @thumbnail.presence || "default title". Bam you're done. So, when the Card component gets created just use the thumbnail attribute or eliminate it, since it defaults to nil (optional), hits that part in the partial, just placing a render Thumbnail.new(thumbnail) and it will either have the thumbnail or nil and it will figure out what it should do, and you're just placing the one line in the Card partial without the if/else block. Or possibly to use the slot feature within the card component and point to the Thumbnail component. I enjoy your tips and suggestions and am a subscriber. This comment is being a little critical, since if I were a code reviewer and the developer thought that solving something by importing a new gem or library to solve something that is easily solvable using the current gem because all the avenues of the solution weren't examined, I would offer this as the simpler solution. Github (the creator of the View Component gem) has already thought of these scenarios for us, just use the solutions. And if it's not available and seems like it should be there, offer up a pull request.
@rapid-ruby
@rapid-ruby Жыл бұрын
Hi Tom, thanks for taking the time to put together such a detailed response! And thanks for subscribing to the channel :) Sorry, I haven’t made the purpose of this video clear, it’s not about how to design or compose ViewComponents, rather just how you can make use of dry-initialiser to simplify the initialiser and attr_reader code that we write for every single ViewComponent. While I agree that breaking down components into smaller more composable components is definitely the way to go. Doing this approach doesn’t take away from the removal of boilerplate code that dry-initialiser provides. If you have a separate thumbnail component, you still need to define an attr_reader and an initialiser on that component. Sometimes my example code can be overly simplistic for the sake of creating short videos, and to help take me a little less time to produce them. I do also agree with you on minimising third party libraries/gems, but would urge you to take a look at the dry-rb libraries, they are all very small and well put together and maintained. Hope that helps explain the purpose a little better :)
@tombranson9341
@tombranson9341 Жыл бұрын
@@rapid-ruby Thanks for clearing up the messaging. Keep up the good work.
@rapid-ruby
@rapid-ruby Жыл бұрын
@@tombranson9341 Thanks!
Rails Performance Tips and Tricks
38:46
CJ Avilla
Рет қаралды 2 М.
【獨生子的日常】让小奶猫也体验一把鬼打墙#小奶喵 #铲屎官的乐趣
00:12
“獨生子的日常”YouTube官方頻道
Рет қаралды 112 МЛН
ISSEI funny story😂😂😂Strange World | Magic Lips💋
00:36
ISSEI / いっせい
Рет қаралды 148 МЛН
Не пей газировку у мамы в машине
00:28
Даша Боровик
Рет қаралды 9 МЛН
Tailwind fancy select with Hotwire and view component
29:43
Rapid Ruby
Рет қаралды 3,2 М.
Чем dry-rb (не) полезен мне
17:25
Ruby Russia club
Рет қаралды 1,5 М.
The BEST way to build Infinite Scroll using Hotwire
6:25
Rapid Ruby
Рет қаралды 1,3 М.
David Heinemeier Hansson: Microservices vs. Monolith
2:43
Honeypot
Рет қаралды 51 М.
ViewComponents in the Real World - Joel Hawksley
34:17
Ruby Central
Рет қаралды 7 М.
dry-rb, collection of next-generation Ruby libraries
1:05:18
GitHub
Рет қаралды 2,8 М.
Купите ЭТОТ БЮДЖЕТНИК вместо флагманов от Samsung, Xiaomi и Apple!
13:03
Thebox - о технике и гаджетах
Рет қаралды 79 М.
Обманет ли МЕНЯ компьютерный мастер?
20:48
Харчевников
Рет қаралды 166 М.
Girl camera photo Editing 3d with adobe Photoshop /9/33/Am
0:43
Amir TECh
Рет қаралды 252 М.
The power button can never be pressed!!
0:57
Maker Y
Рет қаралды 45 МЛН
How much charging is in your phone right now? 📱➡️ 🔋VS 🪫
0:11
Чехол для iPhone на все случаи жизни
0:35