~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.


a70839b6 pyros2097

5 years ago
remove more stuff
Files changed (8) hide show
  1. app.go +0 -30
  2. app_nowasm.go +0 -4
  3. app_wasm.go +0 -8
  4. element.go +1 -11
  5. html.go +1 -1
  6. node.go +4 -14
  7. node_test.go +0 -2
  8. utils.go +0 -8
app.go CHANGED
@@ -1,19 +1,9 @@
1
1
  package app
2
2
 
3
- import (
4
- "strings"
5
- )
6
-
7
3
  var (
8
4
  staticResourcesURL string
9
5
  )
10
6
 
11
- // KeepBodyClean prevents third-party Javascript libraries to add nodes to the
12
- // body element.
13
- func KeepBodyClean() (close func()) {
14
- return keepBodyClean()
15
- }
16
-
17
7
  // Reload reloads the current page.
18
8
  func Reload() {
19
9
  dispatch(func() {
@@ -29,26 +19,6 @@ func Run(r RenderFunc) {
29
19
  run(r)
30
20
  }
31
21
 
32
- // StaticResource makes a static resource path point to the right
33
- // location whether the root directory is remote or not.
34
- //
35
- // Static resources are resources located in the web directory.
36
- //
37
- // This call is used internally to resolve paths within Cite, Data, Href, Src,
38
- // and SrcSet. Paths already resolved are skipped.
39
- func StaticResource(path string) string {
40
- if !strings.HasPrefix(path, "/web/") &&
41
- !strings.HasPrefix(path, "web/") {
42
- return path
43
- }
44
-
45
- if !strings.HasPrefix(path, "/") {
46
- path = "/" + path
47
- }
48
-
49
- return staticResourcesURL + path
50
- }
51
-
52
22
  // Window returns the JavaScript "window" object.
53
23
  func Window() BrowserWindow {
54
24
  return window
app_nowasm.go CHANGED
@@ -15,10 +15,6 @@ func getenv(k string) string {
15
15
  return os.Getenv(k)
16
16
  }
17
17
 
18
- func keepBodyClean() func() {
19
- panic("wasm required")
20
- }
21
-
22
18
  func navigate(u *url.URL, updateHistory bool) error {
23
19
  panic("wasm required")
24
20
  }
app_wasm.go CHANGED
@@ -90,11 +90,3 @@ func isFragmentNavigation(u *url.URL) bool {
90
90
  func reload() {
91
91
  Window().Get("location").Call("reload")
92
92
  }
93
-
94
- func keepBodyClean() func() {
95
- close := Window().Call("goappKeepBodyClean")
96
-
97
- return func() {
98
- close.Invoke()
99
- }
100
- }
element.go CHANGED
@@ -10,8 +10,6 @@ import (
10
10
  type elem struct {
11
11
  attrs map[string]string
12
12
  body []UI
13
- ctx context.Context
14
- ctxCancel func()
15
13
  events map[string]eventHandler
16
14
  jsvalue Value
17
15
  parentElem UI
@@ -29,8 +27,7 @@ func (e *elem) JSValue() Value {
29
27
  }
30
28
 
31
29
  func (e *elem) Mounted() bool {
32
- return e.ctx != nil && e.ctx.Err() == nil &&
33
- e.self() != nil &&
30
+ return e.self() != nil &&
34
31
  e.jsvalue != nil
35
32
  }
36
33
 
@@ -46,10 +43,6 @@ func (e *elem) setSelf(n UI) {
46
43
  e.this = n
47
44
  }
48
45
 
49
- func (e *elem) context() context.Context {
50
- return e.ctx
51
- }
52
-
53
46
  func (e *elem) attributes() map[string]string {
54
47
  return e.attrs
55
48
  }
@@ -78,8 +71,6 @@ func (e *elem) mount() error {
78
71
  Tag("kind", e.Kind())
79
72
  }
80
73
 
81
- e.ctx, e.ctxCancel = context.WithCancel(context.Background())
82
-
83
74
  v := Window().Get("document").Call("createElement", e.tag)
84
75
  if !v.Truthy() {
85
76
  return errors.New("mounting ui element failed").
@@ -118,7 +109,6 @@ func (e *elem) dismount() {
118
109
  e.delJsEventHandler(k, v)
119
110
  }
120
111
 
121
- e.ctxCancel()
122
112
  e.jsvalue = nil
123
113
  }
124
114
 
html.go CHANGED
@@ -80,7 +80,7 @@ func mergeAttributes(parent *elem, uis ...UI) {
80
80
  parent.setAttr("class", c.classes)
81
81
  }
82
82
  case OnClickAttribute:
83
- parent.setEventHandler("click", func(ctx Context, e Event) {
83
+ parent.setEventHandler("click", func(e Event) {
84
84
  c.cb()
85
85
  })
86
86
  }
node.go CHANGED
@@ -1,7 +1,6 @@
1
1
  package app
2
2
 
3
3
  import (
4
- "context"
5
4
  "fmt"
6
5
  "io"
7
6
  "reflect"
@@ -24,7 +23,6 @@ type UI interface {
24
23
  name() string
25
24
  self() UI
26
25
  setSelf(UI)
27
- context() context.Context
28
26
  attributes() map[string]string
29
27
  eventHandlers() map[string]eventHandler
30
28
  parent() UI
@@ -127,7 +125,7 @@ func FilterUIElems(uis ...UI) []UI {
127
125
 
128
126
  // EventHandler represents a function that can handle HTML events. They are
129
127
  // always called on the UI goroutine.
130
- type EventHandler func(ctx Context, e Event)
128
+ type EventHandler func(e Event)
131
129
 
132
130
  type eventHandler struct {
133
131
  event string
@@ -146,19 +144,11 @@ func makeJsEventHandler(src UI, h EventHandler) Func {
146
144
  if !src.Mounted() {
147
145
  return
148
146
  }
149
-
150
- ctx := Context{
151
- Context: src.context(),
152
- Src: src,
153
- JSSrc: src.JSValue(),
154
- }
155
-
156
- event := Event{
147
+ e := Event{
157
148
  Value: args[0],
158
149
  }
159
-
160
- trackMousePosition(event)
150
+ trackMousePosition(e)
161
- h(ctx, event)
151
+ h(e)
162
152
  })
163
153
 
164
154
  return nil
node_test.go CHANGED
@@ -118,7 +118,6 @@ func testMounted(t *testing.T, n UI) {
118
118
 
119
119
  switch n.Kind() {
120
120
  case HTML, Component:
121
- require.NoError(t, n.context().Err())
122
121
  require.NotNil(t, n.self())
123
122
  }
124
123
 
@@ -134,7 +133,6 @@ func testDismounted(t *testing.T, n UI) {
134
133
 
135
134
  switch n.Kind() {
136
135
  case HTML, Component:
137
- require.Error(t, n.context().Err())
138
136
  require.Nil(t, n.self())
139
137
  }
140
138
 
utils.go CHANGED
@@ -1,7 +1,6 @@
1
1
  package app
2
2
 
3
3
  import (
4
- "context"
5
4
  "io"
6
5
  "unsafe"
7
6
  )
@@ -11,14 +10,7 @@ var (
11
10
  uiChan = make(chan func(), 512)
12
11
  )
13
12
 
14
- // Context represents a context that is tied to a UI element. It is canceled
15
- // when the element is dismounted.
16
- //
17
- // It implements the context.Context interface.
18
- // https://golang.org/pkg/context/#Context
19
13
  type Context struct {
20
- context.Context
21
-
22
14
  // The UI element tied to the context.
23
15
  Src UI
24
16