Skip to content
Snippets Groups Projects
Commit 8d783660 authored by Jonah Husson's avatar Jonah Husson
Browse files

Use reduced interface in impl

parent 8f6efbd4
No related branches found
No related tags found
2 merge requests!128Project/base32768,!109Project/haven beta
...@@ -12,7 +12,7 @@ package main ...@@ -12,7 +12,7 @@ package main
import ( import (
"encoding/json" "encoding/json"
"github.com/pkg/errors" "github.com/pkg/errors"
"gitlab.com/elixxir/wasm-utils/storage" "gitlab.com/elixxir/xxdk-wasm/indexedDb/impl"
stateWorker "gitlab.com/elixxir/xxdk-wasm/indexedDb/worker/state" stateWorker "gitlab.com/elixxir/xxdk-wasm/indexedDb/worker/state"
"gitlab.com/elixxir/xxdk-wasm/worker" "gitlab.com/elixxir/xxdk-wasm/worker"
...@@ -22,7 +22,7 @@ import ( ...@@ -22,7 +22,7 @@ import (
// send information between the model and the main thread. // send information between the model and the main thread.
type manager struct { type manager struct {
wtm *worker.ThreadManager wtm *worker.ThreadManager
model storage.LocalStorage model impl.WebState
} }
// registerCallbacks registers all the reception callbacks to manage messages // registerCallbacks registers all the reception callbacks to manage messages
......
...@@ -12,7 +12,6 @@ package main ...@@ -12,7 +12,6 @@ package main
import ( import (
"github.com/hack-pad/go-indexeddb/idb" "github.com/hack-pad/go-indexeddb/idb"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/v4/storage/utility"
"gitlab.com/elixxir/xxdk-wasm/indexedDb/impl" "gitlab.com/elixxir/xxdk-wasm/indexedDb/impl"
"syscall/js" "syscall/js"
) )
...@@ -23,7 +22,7 @@ const currentVersion uint = 1 ...@@ -23,7 +22,7 @@ const currentVersion uint = 1
// NewState returns a [utility.WebState] backed by IndexedDb. // NewState returns a [utility.WebState] backed by IndexedDb.
// The name should be a base64 encoding of the users public key. // The name should be a base64 encoding of the users public key.
func NewState(databaseName string) (utility.WebState, error) { func NewState(databaseName string) (impl.WebState, error) {
return newState(databaseName) return newState(databaseName)
} }
......
...@@ -32,6 +32,13 @@ const ( ...@@ -32,6 +32,13 @@ const (
ErrDoesNotExist = "result is undefined" ErrDoesNotExist = "result is undefined"
) )
// WebState defines an interface for setting persistent state in a KV format
// specifically for web-based implementations.
type WebState interface {
Get(key string) ([]byte, error)
Set(key string, value []byte) error
}
// NewContext builds a context for indexedDb operations. // NewContext builds a context for indexedDb operations.
func NewContext() (context.Context, context.CancelFunc) { func NewContext() (context.Context, context.CancelFunc) {
return context.WithTimeout(context.Background(), dbTimeout) return context.WithTimeout(context.Background(), dbTimeout)
......
...@@ -11,11 +11,11 @@ package dm ...@@ -11,11 +11,11 @@ package dm
import ( import (
"encoding/json" "encoding/json"
"gitlab.com/elixxir/xxdk-wasm/indexedDb/impl"
"time" "time"
"github.com/pkg/errors" "github.com/pkg/errors"
"gitlab.com/elixxir/client/v4/storage/utility"
"gitlab.com/elixxir/xxdk-wasm/storage" "gitlab.com/elixxir/xxdk-wasm/storage"
"gitlab.com/elixxir/xxdk-wasm/worker" "gitlab.com/elixxir/xxdk-wasm/worker"
) )
...@@ -29,9 +29,16 @@ type NewStateMessage struct { ...@@ -29,9 +29,16 @@ type NewStateMessage struct {
DatabaseName string `json:"databaseName"` DatabaseName string `json:"databaseName"`
} }
// WebState defines an interface for setting persistent state in a KV format
// specifically for web-based implementations.
type WebState interface {
Get(key string) ([]byte, error)
Set(key string, value []byte) error
}
// NewState returns a [utility.WebState] backed by indexeddb. // NewState returns a [utility.WebState] backed by indexeddb.
// The name should be a base64 encoding of the users public key. // The name should be a base64 encoding of the users public key.
func NewState(path, wasmJsPath string) (utility.WebState, error) { func NewState(path, wasmJsPath string) (impl.WebState, error) {
databaseName := path + databaseSuffix databaseName := path + databaseSuffix
wh, err := worker.NewManager(wasmJsPath, "stateIndexedDb", true) wh, err := worker.NewManager(wasmJsPath, "stateIndexedDb", true)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment