Skip to content
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

Add keyword argument support for all actions #26

Merged
merged 47 commits into from
Mar 4, 2023

Conversation

marcoroth
Copy link
Owner

@marcoroth marcoroth commented Mar 3, 2023

This pull request adds tests and keyword argument support for all remaining actions. This is following up and finishing the work started in #22, #23, #24, #25 and 05914c4.

Keyword argument support

This means, that all actions can be invoked with both positional arguments and keyword arguments, or both at the same time.

Before:

turbo_stream.set_attribute("#element", "data-controller", "example")

After:

# All positional arguments (as before)
turbo_stream.set_attribute("#element", "data-controller", "example")

# Just value as keyword argument
turbo_stream.set_attribute("#element", "data-controller", value: "example")

# attribute and value as keyword arguments
turbo_stream.set_attribute("#element", attribute: "data-controller", value: "example")

# All arguments as keyword arguments
turbo_stream.set_attribute(targets: "#element", attribute: "data-controller", value: "example")

# this also allows the arguments to be passed in any order
turbo_stream.set_attribute(value: "example", attribute: "data-controller", targets: "#element")

# the same method can be used for both targeting a single element or multiple elements
turbo_stream.set_attribute(target:  "element",  attribute: "data-controller", value: "example")
turbo_stream.set_attribute(targets: ".element", attribute: "data-controller", value: "example")
The following actions are being updated for keyword argument support in this pull request:
  • clear_storage
  • console_table
  • dispatch_event
  • graft
  • history_go
  • inner_html
  • insert_adjacent_html
  • insert_adjacent_text
  • morph
  • outer_html
  • push_state
  • reload
  • remove_attribute
  • remove_css_class
  • remove_storage_item
  • replace_state
  • reset_form
  • scroll_into_view
  • set_attribute
  • set_cookie_item
  • set_cookie
  • set_dataset_attribute
  • set_focus
  • set_meta
  • set_property
  • set_storage_item
  • set_style
  • set_styles
  • set_title
  • text_content
  • turbo_clear_cache
  • turbo_frame_reload
  • turbo_frame_set_src
  • turbo_progress_bar_hide
  • turbo_progress_bar_set_value
  • turbo_progress_bar_show

Changes to the add_css_class action

The add_css_class action now accepts an array for the classes option:

turbo_stream.add_css_class(target: "post_1", classes: ["container", "text-center"])

Changes to the remove_css_class action

The remove_css_class action now accepts an array for the classes option:

turbo_stream.remove_css_class(target: "post_1", classes: ["container", "text-center"])

Changes to the set_styles action

The set_styles action now accepts a hash for the styles option:

turbo_stream.set_styles(target: "post_1", styles: { background: "black", color: "white" })

@marcoroth marcoroth force-pushed the add-tests-and-kwargs-support-for-remaining-actions branch from 8ea1770 to 04921ac Compare March 4, 2023 07:43
@marcoroth marcoroth merged commit 68d5831 into main Mar 4, 2023
@marcoroth marcoroth deleted the add-tests-and-kwargs-support-for-remaining-actions branch March 4, 2023 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant