Replies: 2 comments 2 replies
-
|
Hi there! Welcome, and yes!! this is absolutely the right place to ask! It's great to hear you are exploring Jooby for your new project. Because the Datastar SDK is framework-agnostic, you can create a simple adapter like this: public class JoobyDatastarAdapter {
/**
* Wraps a Jooby SSE into a Datastar ServerSentEventGenerator.
*/
public static ServerSentEventGenerator wrap(ServerSentEmitter sse) {
return new ServerSentEventGenerator(eventData -> {
// Map the Datastar SDK event to Jooby's ServerSentMessage
ServerSentMessage msg = new ServerSentMessage(eventData.getData())
.event(eventData.getEvent());
if (eventData.getId() != null) {
msg.id(eventData.getId());
}
if (eventData.getRetry() != null) {
msg.retry(Duration.ofMillis(eventData.getRetry()));
}
// Dispatch via Jooby
sse.send(msg);
});
}
}
App.java:
{
sse("/my-datastar-endpoint", (ctx, sse) -> {
// 1. Wrap Jooby's emitter with the official Datastar SDK generator
ServerSentEventGenerator datastar = JoobyDatastarAdapter.wrap(sse);
// 2. Use the official SDK to mutate the frontend!
datastar.patchElements("<div id='my-target'>Updated from Jooby!</div>");
// 3. Close the stream for single-shot updates (like a button click)
sse.close();
});
}This was from a quick look, you probably need to write a response adapter from io.jooby.Context too. I didn't try it. Give this a try and let me know how it goes! If this works well for your use case, we might even look into adding it as an official jooby-datastar module in the future. |
Beta Was this translation helpful? Give feedback.
-
|
The io.jooby.Context expose all you need for a response adapter (even the writer). We could explore further and add support to the code generartor. So you can declarative expose datastar responses via annotations. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Not sure if this is the right place to ask questions, but it's enabled, so I thought I'd try! We are exploring Jooby for a new project and wanted to integrate with datastar. We found this library: https://github.com/starfederation/datastar-java, but it doesn't appear to have adapters that are compatible with your project.
Do you happen to have any pointers on where to start?
Thanks for any help you can offer!
Beta Was this translation helpful? Give feedback.
All reactions