~repos /gromer

#golang#htmx#ssr

git clone https://pyrossh.dev/repos/gromer.git

gromer is a framework and cli to build multipage web apps in golang using htmx and alpinejs.


d8e3b1a8 pyros2097

5 years ago
remove "context"
Files changed (9) hide show
  1. app.go +0 -16
  2. app_wasm.go +13 -13
  3. attributes.go +0 -6
  4. component.go +1 -6
  5. element.go +0 -5
  6. js/js.go +2 -0
  7. js/js_nowasm.go +12 -0
  8. raw.go +0 -5
  9. selectors.go +0 -9
app.go DELETED
@@ -1,16 +0,0 @@
1
- package app
2
-
3
- // Reload reloads the current page.
4
- func Reload() {
5
- dispatch(func() {
6
- reload()
7
- })
8
- }
9
-
10
- // Run starts the wasm app and displays the UI node associated with the
11
- // requested URL path.
12
- //
13
- // It panics if Go architecture is not wasm.
14
- func Run(r RenderFunc) {
15
- run(r)
16
- }
app_wasm.go CHANGED
@@ -1,8 +1,9 @@
1
1
  package app
2
2
 
3
3
  import (
4
- "context"
5
4
  "net/url"
5
+
6
+ "github.com/pyros2097/wapp/js"
6
7
  )
7
8
 
8
9
  var (
@@ -11,7 +12,7 @@ var (
11
12
  rootPrefix string
12
13
  )
13
14
 
14
- func run(render RenderFunc) {
15
+ func Run(render RenderFunc) {
15
16
  defer func() {
16
17
  err := recover()
17
18
  // show alert
@@ -33,25 +34,24 @@ func run(render RenderFunc) {
33
34
  }
34
35
  }
35
36
 
37
+ func Reload() {
38
+ dispatch(func() {
39
+ js.Window.Location().Reload()
40
+ })
41
+ }
42
+
36
43
  func initBody() {
37
- ctx, cancel := context.WithCancel(context.Background())
38
44
  body = &elem{
39
- ctx: ctx,
40
- ctxCancel: cancel,
41
- jsvalue: Window().Get("document").Get("body"),
45
+ jsvalue: js.Window.Get("document").Get("body"),
42
- tag: "body",
46
+ tag: "body",
43
47
  }
44
48
  body.setSelf(body)
45
49
  }
46
50
 
47
51
  func initContent() {
48
- ctx, cancel := context.WithCancel(context.Background())
49
-
50
52
  content := &elem{
51
- ctx: ctx,
52
- ctxCancel: cancel,
53
- jsvalue: body.JSValue().Get("firstElementChild"),
53
+ jsvalue: body.JSValue().Get("firstElementChild"),
54
- tag: "div",
54
+ tag: "div",
55
55
  }
56
56
 
57
57
  content.setSelf(content)
attributes.go CHANGED
@@ -1,8 +1,6 @@
1
1
  package app
2
2
 
3
3
  import (
4
- "context"
5
-
6
4
  "github.com/pyros2097/wapp/js"
7
5
  )
8
6
 
@@ -33,10 +31,6 @@ func (c baseAttribute) self() UI {
33
31
  func (c baseAttribute) setSelf(UI) {
34
32
  }
35
33
 
36
- func (c baseAttribute) context() context.Context {
37
- return nil
38
- }
39
-
40
34
  func (c baseAttribute) attributes() map[string]string {
41
35
  return nil
42
36
  }
component.go CHANGED
@@ -1,7 +1,6 @@
1
1
  package app
2
2
 
3
3
  import (
4
- "context"
5
4
  "reflect"
6
5
  "strings"
7
6
 
@@ -69,7 +68,7 @@ func (r RenderFunc) self() UI {
69
68
  func (r RenderFunc) setSelf(n UI) {
70
69
  c := getCurrentContext()
71
70
  if n != nil {
72
- println("new context")
71
+ println("xnew render context")
73
72
  c := NewRenderContext()
74
73
  c.this = n.(RenderFunc)
75
74
  return
@@ -78,10 +77,6 @@ func (r RenderFunc) setSelf(n UI) {
78
77
  c.this = nil
79
78
  }
80
79
 
81
- func (r RenderFunc) context() context.Context {
82
- return nil
83
- }
84
-
85
80
  func (r RenderFunc) attributes() map[string]string {
86
81
  return nil
87
82
  }
element.go CHANGED
@@ -1,7 +1,6 @@
1
1
  package app
2
2
 
3
3
  import (
4
- "context"
5
4
  "io"
6
5
 
7
6
  "github.com/pyros2097/wapp/errors"
@@ -438,10 +437,6 @@ func (t *text) self() UI {
438
437
  func (t *text) setSelf(n UI) {
439
438
  }
440
439
 
441
- func (t *text) context() context.Context {
442
- return context.TODO()
443
- }
444
-
445
440
  func (t *text) attributes() map[string]string {
446
441
  return nil
447
442
  }
js/js.go CHANGED
@@ -195,6 +195,8 @@ type BrowserWindow interface {
195
195
  // returns a function that must be called to unsubscribe the handler and
196
196
  // release allocated resources.
197
197
  AddEventListener(event string, h EventHandler) func()
198
+
199
+ Location() Location
198
200
  }
199
201
 
200
202
  // Event is the interface that describes a javascript event.
js/js_nowasm.go CHANGED
@@ -134,6 +134,10 @@ func (w *browserWindow) AddEventListener(event string, h EventHandler) func() {
134
134
  panic("wasm required")
135
135
  }
136
136
 
137
+ func (w *browserWindow) Location() Location {
138
+ panic("wasm required")
139
+ }
140
+
137
141
  func copyBytesToGo(dst []byte, src Value) int {
138
142
  panic("wasm required")
139
143
  }
@@ -141,3 +145,11 @@ func copyBytesToGo(dst []byte, src Value) int {
141
145
  func copyBytesToJS(dst Value, src []byte) int {
142
146
  panic("wasm required")
143
147
  }
148
+
149
+ type Location struct {
150
+ value
151
+ }
152
+
153
+ func (l *Location) Reload() {
154
+ panic("wasm required")
155
+ }
raw.go CHANGED
@@ -1,7 +1,6 @@
1
1
  package app
2
2
 
3
3
  import (
4
- "context"
5
4
  "io"
6
5
  "strings"
7
6
 
@@ -59,10 +58,6 @@ func (r *raw) self() UI {
59
58
  func (r *raw) setSelf(UI) {
60
59
  }
61
60
 
62
- func (r *raw) context() context.Context {
63
- return nil
64
- }
65
-
66
61
  func (r *raw) attributes() map[string]string {
67
62
  return nil
68
63
  }
selectors.go CHANGED
@@ -1,7 +1,6 @@
1
1
  package app
2
2
 
3
3
  import (
4
- "context"
5
4
  "net/url"
6
5
  "reflect"
7
6
  "sort"
@@ -110,10 +109,6 @@ func (r rangeLoop) self() UI {
110
109
  func (r rangeLoop) setSelf(UI) {
111
110
  }
112
111
 
113
- func (r rangeLoop) context() context.Context {
114
- return nil
115
- }
116
-
117
112
  func (r rangeLoop) attributes() map[string]string {
118
113
  return nil
119
114
  }
@@ -223,10 +218,6 @@ func (c condition) self() UI {
223
218
  func (c condition) setSelf(UI) {
224
219
  }
225
220
 
226
- func (c condition) context() context.Context {
227
- return nil
228
- }
229
-
230
221
  func (c condition) attributes() map[string]string {
231
222
  return nil
232
223
  }