Тэги:
#Dry-rb #Dry-initializer #Dry_initializer #ViewComponent #ViewComponent_Rails #Rails #Ruby_on_Rails #Rails_screencasts #Web_development_in_Rails #Web_development_in_RubyКомментарии:
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.
Seems weird to me that an "option" is required by default :/
Great tooling though.
Great tip
ОтветитьQuality tutorials.
Give us more.
Thank you please
I was wondering for ages why this isn't a thing in vanilla Ruby 🤔
ОтветитьBeen using dry-initializer with View Component in a previous company, works wonderfully 👌
Ответитьvery useful. I need to delve a bit more into view_component.
Ответить