Skip to content

Commit

Permalink
merge indexed_db CursorValue and CursorWithValue
Browse files Browse the repository at this point in the history
  • Loading branch information
nasdf committed May 22, 2024
1 parent 34859f3 commit 5a714e2
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
deps\:test:
go install github.com/agnivade/wasmbrowsertest@latest

.PHONY: test\:js
.PHONY: test
test:
GOOS=js GOARCH=wasm go test -timeout 30s -exec wasmbrowsertest ./...
12 changes: 1 addition & 11 deletions indexed_db/cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,9 @@ func (c CursorValue) Update(value any) RequestValue[js.Value] {
return RequestValue[js.Value](res)
}

// CursorWithValue is an instance of IDBCursorWithValue
//
// https://developer.mozilla.org/en-US/docs/Web/API/IDBCursorWithValue
type CursorWithValue CursorValue

// Value returns the IDBCursorWithValue value property.
//
// https://developer.mozilla.org/en-US/docs/Web/API/IDBCursorWithValue/value
func (c CursorWithValue) Value() js.Value {
func (c CursorValue) Value() js.Value {
return js.Value(c).Get("value")
}

// Cursor returns the IDBCursor.
func (c CursorWithValue) Cursor() CursorValue {
return CursorValue(c)
}
5 changes: 2 additions & 3 deletions indexed_db/cursor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ func TestCursor(t *testing.T) {
require.NoError(t, err)

var cursorWait sync.WaitGroup
var cursorReq RequestValue[CursorWithValue]
var cursorReq RequestValue[CursorValue]
cursorSuccess := goji.EventListener(func(event goji.EventValue) {
value := cursorReq.Result()
if !js.Value(value).IsNull() {
value.Cursor().Continue()
value.Continue()
}
cursorWait.Done()

})
defer cursorSuccess.Release()

Expand Down
4 changes: 2 additions & 2 deletions indexed_db/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ func (i IndexValue) GetKey(key any) RequestValue[js.Value] {
// OpenCursor wraps the IDBIndex openCursor instance method.
//
// https://developer.mozilla.org/en-US/docs/Web/API/IDBIndex/openCursor
func (i IndexValue) OpenCursor(args ...any) RequestValue[CursorWithValue] {
func (i IndexValue) OpenCursor(args ...any) RequestValue[CursorValue] {
res := js.Value(i).Call("openCursor", args...)
return RequestValue[CursorWithValue](res)
return RequestValue[CursorValue](res)
}

// OpenKeyCursor wraps the IDBIndex openKeyCursor instance method.
Expand Down
4 changes: 2 additions & 2 deletions indexed_db/object_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ func (o ObjectStoreValue) Index(name string) IndexValue {
// OpenCursor wraps the IDBObjectStore openCursor instance method.
//
// https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/openCursor
func (o ObjectStoreValue) OpenCursor(args ...any) RequestValue[CursorWithValue] {
func (o ObjectStoreValue) OpenCursor(args ...any) RequestValue[CursorValue] {
res := js.Value(o).Call("openCursor", args...)
return RequestValue[CursorWithValue](res)
return RequestValue[CursorValue](res)
}

// OpenKeyCursor wraps the IDBObjectStore openKeyCursor instance method.
Expand Down
2 changes: 1 addition & 1 deletion indexed_db/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (

// RequestResult is the type union for request results.
type RequestResult interface {
js.Value | DatabaseValue | CursorValue | CursorWithValue
js.Value | DatabaseValue | CursorValue
}

// RequestValue is an instance of IDBRequest.
Expand Down

0 comments on commit 5a714e2

Please sign in to comment.