Skip to content

Commit

Permalink
feat(libsvelte): renaming "EchoSvelte" to simply "Svelte" and redesig…
Browse files Browse the repository at this point in the history
…ning it so that the "ssr" parameter is a property among the "props" parameter.
  • Loading branch information
razshare committed Jan 11, 2025
1 parent 7277b3c commit 787d27d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions libsvelte.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ func render(response *Response, stringProps string) (string, string, error) {
return head, body, nil
}

// EchoSvelte renders and echos the svelte application.
func EchoSvelte(response *Response, ssr bool, props map[string]interface{}) {
// Svelte renders and echos the svelte application.
func Svelte(response *Response, props map[string]interface{}) {
indexBytes, readError := response.server.embeddedFileSystem.ReadFile(filepath.Join(response.server.wwwDirectory, "dist", "client", "index.html"))
if readError != nil {
return
}

ssr := props["ssr"].(bool)

bytesProps, jsonError := json.Marshal(props)
if jsonError != nil {
ServerNotifyError(response.server, jsonError)
Expand Down
6 changes: 4 additions & 2 deletions libsvelte_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ func TestEchoSvelteWithSsr(test *testing.T) {
test.Fatal(err)
})
ServerOnRequest(server, "GET /", func(server *Server, request *Request, response *Response) {
EchoSvelte(response, true, map[string]interface{}{
Svelte(response, map[string]interface{}{
"ssr": true,
"name": "world",
})
})
Expand Down Expand Up @@ -44,7 +45,8 @@ func TestEchoSvelteWithoutSsr(test *testing.T) {
test.Fatal(err)
})
ServerOnRequest(server, "GET /", func(server *Server, request *Request, response *Response) {
EchoSvelte(response, false, map[string]interface{}{
Svelte(response, map[string]interface{}{
"ssr": false,
"name": "world",
})
})
Expand Down

0 comments on commit 787d27d

Please sign in to comment.