joshleblanc / view_component_reflex

Call component methods right from your markup
http://view-component-reflex-expo.grep.sh/
MIT License
293 stars 28 forks source link

Is it suppose to instance vars be available as data values in Stimulus controllers? #105

Closed theo-bittencourt closed 1 year ago

theo-bittencourt commented 1 year ago
export default class extends Controller {
  static values = { latitude: Number, longitude: Number }
  ...
}
class MyComponent < ViewComponentReflex::Component
  def initialize
    @latitude = 17.0213812
    @longitude = 13.9127312
  end
end
<%= component_controller do %>
  <div></div>
<% end %>

Given the above component, how to access latitude and longitude values?

The component_controller helper seems not to accept the data-x-value as parameters.

theo-bittencourt commented 1 year ago
<%= component_controller data: {
  'my-component-latitude-value': @latitude,
  'my-component-longitude-value': @longitude,
} do %>
...
<% end %>

This worked for me.

joshleblanc commented 1 year ago

Apologies, I don't know why I didn't get this notification. That's about what you would have to do to access any ivars in a stimulus controller.