remove jsutil.Global()

This commit is contained in:
syumai 2024-01-04 22:45:03 +09:00
parent 7025700201
commit 1f1d7bc2f1
6 changed files with 17 additions and 21 deletions

View File

@ -6,7 +6,7 @@ import (
"github.com/syumai/workers/internal/jsutil"
)
var cache = jsutil.Global.Get("caches")
var cache = js.Global().Get("caches")
// Cache
type Cache struct {

View File

@ -37,7 +37,7 @@ var scheduledTask Task
// ScheduleTask sets the Task to be executed
func ScheduleTask(task Task) {
scheduledTask = task
jsutil.Global.Call("ready")
js.Global().Call("ready")
select {}
}
@ -78,5 +78,5 @@ func init() {
return jsutil.NewPromise(cb)
})
jsutil.Global.Set("runScheduler", runSchedulerCallback)
js.Global().Set("runScheduler", runSchedulerCallback)
}

View File

@ -3,8 +3,6 @@ package fetch
import (
"net/http"
"syscall/js"
"github.com/syumai/workers/internal/jsutil"
)
// Client is an HTTP client.
@ -44,7 +42,7 @@ func WithBinding(bind js.Value) ClientOption {
// NewClient returns new Client
func NewClient(opts ...ClientOption) *Client {
c := &Client{
namespace: jsutil.Global,
namespace: js.Global(),
}
c.applyOptions(opts)

View File

@ -7,7 +7,6 @@ import (
"syscall/js"
"github.com/syumai/workers/cloudflare/internal/cfruntimecontext"
"github.com/syumai/workers/internal/jsutil"
)
@ -67,7 +66,7 @@ func (kv *KVNamespace) GetReader(key string, opts *KVNamespaceGetOptions) (io.Re
if err != nil {
return nil, err
}
jsutil.Global.Get("console").Call("log", v)
js.Global().Get("console").Call("log", v)
return jsutil.ConvertStreamReaderToReader(v.Call("getReader")), nil
}

View File

@ -40,7 +40,7 @@ func init() {
})
return jsutil.NewPromise(cb)
})
jsutil.Global.Set("handleRequest", handleRequestCallback)
js.Global().Set("handleRequest", handleRequestCallback)
}
// handleRequest accepts a Request object and returns Response object.
@ -78,6 +78,6 @@ func Serve(handler http.Handler) {
handler = http.DefaultServeMux
}
httpHandler = handler
jsutil.Global.Call("ready")
js.Global().Call("ready")
select {}
}

View File

@ -7,17 +7,16 @@ import (
)
var (
Global = js.Global()
ObjectClass = Global.Get("Object")
PromiseClass = Global.Get("Promise")
RequestClass = Global.Get("Request")
ResponseClass = Global.Get("Response")
HeadersClass = Global.Get("Headers")
ArrayClass = Global.Get("Array")
Uint8ArrayClass = Global.Get("Uint8Array")
ErrorClass = Global.Get("Error")
ReadableStreamClass = Global.Get("ReadableStream")
DateClass = Global.Get("Date")
ObjectClass = js.Global().Get("Object")
PromiseClass = js.Global().Get("Promise")
RequestClass = js.Global().Get("Request")
ResponseClass = js.Global().Get("Response")
HeadersClass = js.Global().Get("Headers")
ArrayClass = js.Global().Get("Array")
Uint8ArrayClass = js.Global().Get("Uint8Array")
ErrorClass = js.Global().Get("Error")
ReadableStreamClass = js.Global().Get("ReadableStream")
DateClass = js.Global().Get("Date")
Null = js.ValueOf(nil)
)