-
Notifications
You must be signed in to change notification settings - Fork 79
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
Ruby SDK #600
Draft
ismasan
wants to merge
50
commits into
starfederation:develop
Choose a base branch
from
ismasan:ruby_sdk
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Ruby SDK #600
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Thanks for the PR, looks like a great start! Can you please follow the remaining tasks as outlined in the Contribution Guidelines? I’ll put this PR into draft mode until it’s ready for review again. |
I pushed changes to code-get constants, and a few code snippets. I don't think existing SDKs have working examples for all code snippets. Is that a requirement for new SDKs going forward? |
Datastar.config.on_error { |err| Sentry.notify(err) }
…eams in separate threads
Also do not check for SSE Accept on stream. Leave it up to the user.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implement the Datastart SSE procotocol in Ruby. It can be used in any Rack handler, and Rails controllers.
Installation
For now, point your
Gemfile
to the sourceUsage
Initialize the Datastar dispatcher
In your Rack handler or Rails controller:
Sending updates to the browser
There are two ways to use this gem in HTTP handlers:
One-off update:
In this mode, the response is closed after the fragment is sent.
Streaming updates
In this mode, the response is kept open until
stream
blocks have finished.Concurrent streaming blocks
Multiple
stream
blocks will be launched in threads/fibers, and will run concurrently.Then their updates are linearized and sent to the browser.
Datastar methods
All these methods are available in both the one-off and the streaming modes.
merge_fragments
See https://data-star.dev/reference/sse_events#datastar-merge-fragments
remove_fragments
See https://data-star.dev/reference/sse_events#datastar-remove-fragments
merge_signals
See https://data-star.dev/reference/sse_events#datastar-merge-signals
remove_signals
See https://data-star.dev/reference/sse_events#datastar-remove-signals
execute_script
See https://data-star.dev/reference/sse_events#datastar-execute-script
signals
See https://data-star.dev/guide/getting_started#data-signals
Returns signals sent by the browser.
Lifecycle callbacks
on_connect
Register server-side code to run when the connection is first handled.
on_client_disconnect
Register server-side code to run when the connection is closed by the client
on_server_disconnect
Register server-side code to run when the connection is closed by the server.
Ie when the served is done streaming without errors.
on_error
Ruby code to handle any exceptions raised by streaming blocks.
Note that this callback can be registered globally, too.
Global configuration
Tests
Running Datastar's SDK test suite
Install dependencies.
From this library's root, run the bundled-in test Rack app:
Now run the test bash scripts in the
test
directory in this repo.