Closed gkemmey closed 6 years ago
Hi @gkemmey thanks for the PR! We'll review this with the team.
First thing that comes to my mind: I think we would need to "blacklist" the use of properties
as a variable passed to the component
helper, to make sure there is no risk of collision.
In other terms, we would raise an exception in case you write:
= component "input", properties: {}
so it doesn't conflict with using @properties
.
Another approach would be to access properties using a properties
method, instead of a @properties
instance variable.
I think I prefer this second approach. What do you think?
Ah, makes sense. I agree that's nicer. So are you thinking
define_singleton_method(:properties) { locals }
would work instead?
Hello @gkemmey,
Great idea to make the same variables available through properties
or via instance variables. The method properties
seems good to me.
Can you reuse the existing fixtures/my_app
to make your tests instead of creating a new one ? I don't care between cucumber
, rspec
or test-unit
, take what you like to make your tests. The 2 related PRs can give you inspiration for adapting fixtures/my_app
in order to make tests working.
We should use the foundation you made to implement other tests for component_helper
.
@florentferry, @Spone Thanks for reviewing!
Think this is fixed, let me know if anything else needs to change.
Thanks for the changes. Good to merge for me, just need a mention about the locals accessible via properties in https://github.com/komposable/komponent#passing-variables, and an addition to changelog.
Thanks for the changes, ready to merge!
Seems like it'd be nice to get access to all the properties given to a component.
Usage Example
InputComponent
_input.html.erb
_new_todo.html.erb
InputComponent
becomes a wrapper around a call totext_field
that you could apply some stylings to or whatever.Testing
I wrote some tests that involved adding another app under
fixtures
calledtest_app
(hence all the files). On that, I created a couple components I could use to test expected rendering in aActiveSupport::ViewTest
.Looks like some of the testing process is in limbo in other PRs, so happy to adjust if need be.