Skip to content

Commit

Permalink
sdk/dotnet-code_snippets (#247)
Browse files Browse the repository at this point in the history
* sdk/dotnet-code_snippets - csharp snippets: multiple_events and setup

* sdk/dotnet-code_snippets - setup updated to be more terse

* Update multiple_events.csharpsnippet

* Update README.md

---------

Co-authored-by: Greg Holden <[email protected]>
  • Loading branch information
SpiralOSS and SpiralOSS authored Nov 29, 2024
1 parent 1b4b228 commit 26b947b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion code/dotnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public record DatastarSignalsStore : IDatastarSignalsStore
// add as an ASP Service
// allows injection of IServerSentEventGenerator, to respond to a request with a Datastar friendly ServerSentEvent
// and IDatastarSignalsStore, to read what is in the data-merge-signals of the client
builder.Services.AddDatastarGenerator<DatastarSignalsStore>();
builder.Services.AddDatastar<DatastarSignalsStore>();
...
app.UseStaticFiles();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sse.MergeFragments(@"<div id=""question"">...</div>");
sse.MergeFragments(@"<div id=""instructions"">...</div>");
sse.MergeSignals("{answer: '...'}");
sse.MergeSignals("{prize: '...'}");
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using StarFederation.Datastar.DependencyInjection;

// add as a service
builder.Services.AddDatastar();

app.MapGet("/", async (IServerSentEventGenerator sse) =>
{
// Merges HTML fragments into the DOM.
await sse.MergeFragments(@"<div id=""question"">What do you put in a toaster?</div>");

// Merges signals into the store.
await sse.MergeSignals("{response: '', answer: 'bread'}");
});

0 comments on commit 26b947b

Please sign in to comment.