Skip to content

Commit

Permalink
correct routing and add newstorage method
Browse files Browse the repository at this point in the history
  • Loading branch information
realPy committed Nov 3, 2024
1 parent 6057f93 commit 9058403
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 13 deletions.
56 changes: 56 additions & 0 deletions base/blob/blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import (
"github.com/realPy/hogosuru/base/array"
"github.com/realPy/hogosuru/base/arraybuffer"
"github.com/realPy/hogosuru/base/baseobject"
"github.com/realPy/hogosuru/base/initinterface"
"github.com/realPy/hogosuru/base/typedarray"
"github.com/realPy/hogosuru/testingutils"
)

func TestMain(m *testing.M) {
baseobject.SetSyscall()
initinterface.Init()
m.Run()
}

Expand Down Expand Up @@ -189,3 +191,57 @@ func TestText(t *testing.T) {
}

}

/*
func TestNewTransformStream(t *testing.T) {
if ts, err := stream.NewTransformStream(
func(controller stream.TransformStreamDefaultController) {
},
func(chunk interface{}, controller stream.TransformStreamDefaultController) {
if buffer, ok := chunk.(typedarray.Uint8Array); ok {
size, _ := buffer.Length()
gobuff := make([]byte, size)
buffer.CopyBytes(gobuff)
s := string(gobuff)
s = strings.ToUpper(s)
buffer.CopyFromBytes([]byte(s)[:])
controller.Enqueue(buffer.BaseObject)
}
}); testingutils.AssertErr(t, err) {
c := make(chan bool, 1)
testingutils.AssertExpect(t, "[object TransformStream]", ts.ToString_())
b, _ := New("hello world")
inputstream, _ := b.Stream()
pipt, _ := inputstream.PipeThrough(ts)
rsp, _ := response.New(pipt)
p, _ := rsp.ArrayBuffer()
p.Then(func(i interface{}) *promise.Promise {
if ab, ok := i.(arraybuffer.ArrayBuffer); ok {
size, _ := ab.ByteLength()
gobuff := make([]byte, size)
abb, _ := typedarray.NewUint8Array(ab)
abb.CopyBytes(gobuff)
fmt.Printf("-->%s\n", string(gobuff))
}
return nil
}, func(e error) {
t.Error(e.Error())
})
select {
case <-c:
case <-time.After(800 * time.Millisecond):
t.Error("stop")
}
}
}
*/
24 changes: 24 additions & 0 deletions base/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ var singleton sync.Once

var storageinterface js.Value

type StorageType string

const (
StorageTypeSession StorageType = "sessionStorage"
StorageTypeLocal StorageType = "localStorage"
)

// GetInterface get the Storage interface
func GetInterface() js.Value {

Expand Down Expand Up @@ -48,6 +55,23 @@ func (s Storage) Storage_() Storage {
return s
}

func NewStorage(storageType StorageType) (*Storage, error) {

winobj, err := baseobject.Get(js.Global(), "window")
if err != nil {
return nil, err
}

storageobj, err := baseobject.Get(winobj, string(storageType))
if err != nil {
return nil, err
}

store, err := NewFromJSObject(storageobj)
return &store, err

}

func NewFromJSObject(obj js.Value) (Storage, error) {
var s Storage
var err error
Expand Down
8 changes: 8 additions & 0 deletions base/storage/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ func TestNewStorage(t *testing.T) {

})

t.Run("new", func(t *testing.T) {

if stor, err := NewStorage(StorageTypeLocal); testingutils.AssertErr(t, err) {
testingutils.AssertExpect(t, "[object Storage]", stor.ToString_())
}

})

}

func TestGetItem(t *testing.T) {
Expand Down
13 changes: 0 additions & 13 deletions routing/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,6 @@ func Router() *RouteMap {
singletonRoute.Do(func() {
route.routing = make(map[string]Rendering)
if w, err := window.New(); err == nil {
/*
//Vérifier si cette fonction a du sens
w.OnHashChange(func(e event.Event) {
if route.mode == HASHROUTE {
fmt.Printf("onurlhash\n")
route.onurlchange()
}
})*/

w.OnPopState(func(e event.Event) {

Expand Down Expand Up @@ -158,9 +148,6 @@ func (r *RouteMap) loadChilds(d document.Document, obj Rendering, node node.Node
}

obj.OnEndChildsRendering()
if r.defaultRendering == obj {
r.onurlchange()
}

})
}
Expand Down

0 comments on commit 9058403

Please sign in to comment.