File tree Expand file tree Collapse file tree 3 files changed +18
-1
lines changed
go/site/static/code_snippets/getting_started Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ public record DatastarSignalsStore : IDatastarSignalsStore
4545// add as an ASP Service
4646// allows injection of IServerSentEventGenerator, to respond to a request with a Datastar friendly ServerSentEvent
4747// and IDatastarSignalsStore, to read what is in the data-merge-signals of the client
48- builder .Services .AddDatastarGenerator <DatastarSignalsStore >();
48+ builder .Services .AddDatastar <DatastarSignalsStore >();
4949.. .
5050app .UseStaticFiles ();
5151
Original file line number Diff line number Diff line change 1+ sse.MergeFragments(@"<div id=""question"">...</div>");
2+ sse.MergeFragments(@"<div id=""instructions"">...</div>");
3+ sse.MergeSignals("{answer: '...'}");
4+ sse.MergeSignals("{prize: '...'}");
Original file line number Diff line number Diff line change 1+ using StarFederation.Datastar.DependencyInjection;
2+
3+ // add as a service
4+ builder.Services.AddDatastar();
5+
6+ app.MapGet("/", async (IServerSentEventGenerator sse) =>
7+ {
8+ // Merges HTML fragments into the DOM.
9+ await sse.MergeFragments(@"<div id=""question"">What do you put in a toaster?</div>");
10+
11+ // Merges signals into the store.
12+ await sse.MergeSignals("{response: '', answer: 'bread'}");
13+ });
You can’t perform that action at this time.
0 commit comments