Skip to content

Commit

Permalink
Support for script RPC.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed May 6, 2024
1 parent c649e6c commit 7e1e682
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 13 deletions.
4 changes: 4 additions & 0 deletions lib/live/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
module Live
# Represents a single division of content on the page an provides helpers for rendering the content.
class View < Element
def script(code, **options)
rpc(:script, @id, code, options)
end

# Update the content of the client-side element by rendering this view.
def update!(**options)
rpc(:update, @id, self.to_html, options)
Expand Down
6 changes: 3 additions & 3 deletions test/live/.website/node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 16 additions & 4 deletions test/live/.website/node_modules/@socketry/live/Live.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions test/live/.website/node_modules/@socketry/live/test/Live.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions test/live/.website/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/live/.website/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"dependencies": {
"@socketry/live": "^0.12"
"@socketry/live": "^0.13"
}
}
13 changes: 13 additions & 0 deletions test/live/website.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,17 @@ def app

expect(find_element(css: "ul.test").text).to be == "Middle\nAppended"
end

it "can execute scripts" do
navigate_to("/index.html")

# Wait for the page to load.
find_element(css: "#test p")

tag = resolver.bound.values.first

tag.script("document.title = 'Executed'")

expect(session.document_title).to be == "Executed"
end
end

0 comments on commit 7e1e682

Please sign in to comment.