Skip to content

Commit ce86ded

Browse files
committed
clean up tsunami/app api surface
1 parent 6bff9aa commit ce86ded

4 files changed

Lines changed: 72 additions & 74 deletions

File tree

tsunami/app/defaultclient.go

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,25 @@ import (
1111
"github.com/wavetermdev/waveterm/tsunami/vdom"
1212
)
1313

14-
var defaultClient = MakeClient()
14+
var defaultClient = makeClient()
1515
var assetsFS fs.FS
1616
var staticFS fs.FS
17-
var manifestFile *FileHandlerOption
17+
var manifestFileBytes []byte
1818

1919
// Default client methods that operate on the global defaultClient
2020

2121
func DefineComponent[P any](name string, renderFn func(ctx context.Context, props P) any) vdom.Component[P] {
22-
return DefineComponentEx(defaultClient, name, renderFn)
22+
return defineComponentEx(defaultClient, name, renderFn)
2323
}
2424

25-
func SetGlobalEventHandler(handler func(client *Client, event vdom.VDomEvent)) {
25+
func SetGlobalEventHandler(handler func(event vdom.VDomEvent)) {
2626
defaultClient.SetGlobalEventHandler(handler)
2727
}
2828

29-
3029
func AddSetupFn(fn func()) {
3130
defaultClient.AddSetupFn(fn)
3231
}
3332

34-
func RunMain() {
35-
defaultClient.RunMain()
36-
}
37-
3833
func SendAsyncInitiation() error {
3934
return defaultClient.SendAsyncInitiation()
4035
}
@@ -63,14 +58,14 @@ func RegisterFileHandler(path string, option FileHandlerOption) {
6358
defaultClient.RegisterFileHandler(path, option)
6459
}
6560

66-
func RegisterAssetsFS(filesystem fs.FS) {
67-
assetsFS = filesystem
68-
}
69-
70-
func RegisterStaticFS(filesystem fs.FS) {
71-
staticFS = filesystem
61+
// RunMain is used internally by generated code and should not be called directly.
62+
func RunMain() {
63+
defaultClient.RunMain()
7264
}
7365

74-
func RegisterManifestFile(option FileHandlerOption) {
75-
manifestFile = &option
66+
// RegisterEmbeds is used internally by generated code and should not be called directly.
67+
func RegisterEmbeds(assetsFilesystem fs.FS, staticFilesystem fs.FS, manifest []byte) {
68+
assetsFS = assetsFilesystem
69+
staticFS = staticFilesystem
70+
manifestFileBytes = manifest
7671
}

tsunami/app/serverhandlers.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,24 @@ func init() {
2626
mime.AddExtensionType(".json", "application/json")
2727
}
2828

29-
type HandlerOpts struct {
29+
type handlerOpts struct {
3030
AssetsFS fs.FS
3131
StaticFS fs.FS
3232
ManifestFile *FileHandlerOption
3333
}
3434

35-
type HTTPHandlers struct {
36-
Client *Client
35+
type httpHandlers struct {
36+
Client *clientImpl
3737
renderLock sync.Mutex
3838
}
3939

40-
func NewHTTPHandlers(client *Client) *HTTPHandlers {
41-
return &HTTPHandlers{
40+
func newHTTPHandlers(client *clientImpl) *httpHandlers {
41+
return &httpHandlers{
4242
Client: client,
4343
}
4444
}
4545

46-
func (h *HTTPHandlers) RegisterHandlers(mux *http.ServeMux, opts HandlerOpts) {
46+
func (h *httpHandlers) registerHandlers(mux *http.ServeMux, opts handlerOpts) {
4747
mux.HandleFunc("/api/render", h.handleRender)
4848
mux.HandleFunc("/api/updates", h.handleSSE)
4949
mux.HandleFunc("/api/data", h.handleData)
@@ -62,7 +62,7 @@ func (h *HTTPHandlers) RegisterHandlers(mux *http.ServeMux, opts HandlerOpts) {
6262
}
6363
}
6464

65-
func (h *HTTPHandlers) handleRender(w http.ResponseWriter, r *http.Request) {
65+
func (h *httpHandlers) handleRender(w http.ResponseWriter, r *http.Request) {
6666
defer func() {
6767
panicErr := util.PanicHandler("handleRender", recover())
6868
if panicErr != nil {
@@ -112,7 +112,7 @@ func (h *HTTPHandlers) handleRender(w http.ResponseWriter, r *http.Request) {
112112
}
113113
}
114114

115-
func (h *HTTPHandlers) processFrontendUpdate(feUpdate *rpctypes.VDomFrontendUpdate) (*rpctypes.VDomBackendUpdate, error) {
115+
func (h *httpHandlers) processFrontendUpdate(feUpdate *rpctypes.VDomFrontendUpdate) (*rpctypes.VDomBackendUpdate, error) {
116116
h.renderLock.Lock()
117117
defer h.renderLock.Unlock()
118118

@@ -136,7 +136,7 @@ func (h *HTTPHandlers) processFrontendUpdate(feUpdate *rpctypes.VDomFrontendUpda
136136
for _, event := range feUpdate.Events {
137137
if event.GlobalEventType != "" {
138138
if h.Client.GlobalEventHandler != nil {
139-
h.Client.GlobalEventHandler(h.Client, event)
139+
h.Client.GlobalEventHandler(event)
140140
}
141141
} else {
142142
h.Client.Root.Event(event.WaveId, event.EventType, event)
@@ -164,7 +164,7 @@ func (h *HTTPHandlers) processFrontendUpdate(feUpdate *rpctypes.VDomFrontendUpda
164164
return update, nil
165165
}
166166

167-
func (h *HTTPHandlers) handleData(w http.ResponseWriter, r *http.Request) {
167+
func (h *httpHandlers) handleData(w http.ResponseWriter, r *http.Request) {
168168
defer func() {
169169
panicErr := util.PanicHandler("handleData", recover())
170170
if panicErr != nil {
@@ -186,7 +186,7 @@ func (h *HTTPHandlers) handleData(w http.ResponseWriter, r *http.Request) {
186186
}
187187
}
188188

189-
func (h *HTTPHandlers) handleConfig(w http.ResponseWriter, r *http.Request) {
189+
func (h *httpHandlers) handleConfig(w http.ResponseWriter, r *http.Request) {
190190
defer func() {
191191
panicErr := util.PanicHandler("handleConfig", recover())
192192
if panicErr != nil {
@@ -204,7 +204,7 @@ func (h *HTTPHandlers) handleConfig(w http.ResponseWriter, r *http.Request) {
204204
}
205205
}
206206

207-
func (h *HTTPHandlers) handleConfigGet(w http.ResponseWriter, _ *http.Request) {
207+
func (h *httpHandlers) handleConfigGet(w http.ResponseWriter, _ *http.Request) {
208208
result := h.Client.Root.GetConfigMap()
209209

210210
w.Header().Set("Content-Type", "application/json")
@@ -214,7 +214,7 @@ func (h *HTTPHandlers) handleConfigGet(w http.ResponseWriter, _ *http.Request) {
214214
}
215215
}
216216

217-
func (h *HTTPHandlers) handleConfigPost(w http.ResponseWriter, r *http.Request) {
217+
func (h *httpHandlers) handleConfigPost(w http.ResponseWriter, r *http.Request) {
218218
body, err := io.ReadAll(r.Body)
219219
if err != nil {
220220
http.Error(w, fmt.Sprintf("failed to read request body: %v", err), http.StatusBadRequest)
@@ -235,7 +235,7 @@ func (h *HTTPHandlers) handleConfigPost(w http.ResponseWriter, r *http.Request)
235235
w.WriteHeader(http.StatusOK)
236236
}
237237

238-
func (h *HTTPHandlers) handleDynContent(w http.ResponseWriter, r *http.Request) {
238+
func (h *httpHandlers) handleDynContent(w http.ResponseWriter, r *http.Request) {
239239
defer func() {
240240
panicErr := util.PanicHandler("handleDynContent", recover())
241241
if panicErr != nil {
@@ -252,7 +252,7 @@ func (h *HTTPHandlers) handleDynContent(w http.ResponseWriter, r *http.Request)
252252
h.Client.UrlHandlerMux.ServeHTTP(w, r)
253253
}
254254

255-
func (h *HTTPHandlers) handleSSE(w http.ResponseWriter, r *http.Request) {
255+
func (h *httpHandlers) handleSSE(w http.ResponseWriter, r *http.Request) {
256256
defer func() {
257257
panicErr := util.PanicHandler("handleSSE", recover())
258258
if panicErr != nil {
@@ -342,7 +342,7 @@ func serveFileDirectly(w http.ResponseWriter, r *http.Request, embeddedFS fs.FS,
342342
return true
343343
}
344344

345-
func (h *HTTPHandlers) handleStaticFiles(embeddedFS fs.FS) http.HandlerFunc {
345+
func (h *httpHandlers) handleStaticFiles(embeddedFS fs.FS) http.HandlerFunc {
346346
fileServer := http.FileServer(http.FS(embeddedFS))
347347

348348
return func(w http.ResponseWriter, r *http.Request) {
@@ -377,7 +377,7 @@ func (h *HTTPHandlers) handleStaticFiles(embeddedFS fs.FS) http.HandlerFunc {
377377
}
378378
}
379379

380-
func (h *HTTPHandlers) handleManifest(manifestFile *FileHandlerOption) http.HandlerFunc {
380+
func (h *httpHandlers) handleManifest(manifestFile *FileHandlerOption) http.HandlerFunc {
381381
return func(w http.ResponseWriter, r *http.Request) {
382382
defer func() {
383383
panicErr := util.PanicHandler("handleManifest", recover())
@@ -396,11 +396,11 @@ func (h *HTTPHandlers) handleManifest(manifestFile *FileHandlerOption) http.Hand
396396
return
397397
}
398398

399-
ServeFileOption(w, r, *manifestFile)
399+
serveFileOption(w, r, *manifestFile)
400400
}
401401
}
402402

403-
func (h *HTTPHandlers) handleStaticPathFiles(staticFS fs.FS) http.HandlerFunc {
403+
func (h *httpHandlers) handleStaticPathFiles(staticFS fs.FS) http.HandlerFunc {
404404
return func(w http.ResponseWriter, r *http.Request) {
405405
defer func() {
406406
panicErr := util.PanicHandler("handleStaticPathFiles", recover())

0 commit comments

Comments
 (0)