Skip to content

Commit

Permalink
Move detail attribute of dispatch_event action to <template> tag
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoroth committed Sep 24, 2022
1 parent d0a299a commit 43b75ee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/turbo_power/stream_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def set_value(target, value, **attributes)
# Event Actions

def dispatch_event(target, name, detail: {}, **attributes)
custom_action_all :dispatch_event, targets: target, attributes: attributes.merge(name: name, detail: detail)
custom_action_all :dispatch_event, targets: target, attributes: attributes.merge(name: name), content: detail.to_json
end

# Storage Actions
Expand Down
16 changes: 16 additions & 0 deletions test/turbo_power/stream_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

require "test_helper"

module TurboPower
class StreamHelperTest < ActionView::TestCase
include TurboStreamHelpers
include Turbo::Streams::ActionHelper

test "dispatch_event" do
stream = %(<turbo-stream name="custom-event" action="dispatch_event" targets="#element"><template>{"count":1,"type":"custom","enabled":true,"ids":[1,2,3]}</template></turbo-stream>)

assert_dom_equal stream, turbo_stream.dispatch_event("#element", "custom-event", detail: { count: 1, type: "custom", enabled: true, ids: [1, 2, 3] })
end
end
end

0 comments on commit 43b75ee

Please sign in to comment.