-
Notifications
You must be signed in to change notification settings - Fork 0
/
events-dom_dummy.go
46 lines (37 loc) · 1.76 KB
/
events-dom_dummy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// +build !wasm
package vugu
// NOTE: Dummy implementation allows code that does JS things to compile in non-wasm,
// even though that code will never get called - needed so we can do server side rendering of components.
// DOMEventStub is used as a value to mean "replace this with the actual event that came in".
// In .vugu files, "event" points to this.
var DOMEventStub = &DOMEvent{}
// DOMEvent is an event originated in the browser. It wraps the JS event that comes in.
// It is meant to be used in WebAssembly but some methods exist here so code can compile
// server-side as well (although DOMEvents should not ever be generated server-side).
type DOMEvent struct {
}
// JSEvent this returns a js.Value in wasm that corresponds to the event object.
// Non-wasm implementation returns nil.
func (e *DOMEvent) JSEvent() interface{} {
return nil
}
// JSEventThis returns a js.Value in wasm that corresponds to the "this" variable from the event callback.
// It is the DOM element the event was attached to.
// Non-wasm implementation returns nil.
func (e *DOMEvent) JSEventThis() interface{} {
return nil
}
// RequestRender tells the environment it should be re-rendered as soon as possible (as soon as it can obtain a read lock).
// Non-wasm implementation is nop.
func (e *DOMEvent) RequestRender() {
}
// PreventDefault calls preventDefault() on the JS event object.
// Non-wasm implementation is nop.
func (e *DOMEvent) PreventDefault() {
}
// EventEnv returns the EventEnv for the current environment and allows locking and unlocking around modifications.
// See EventEnv struct.
// Non-wasm implementation returns nil.
func (e *DOMEvent) EventEnv() EventEnv {
return nil // do we need to do anything with this? in static html rendering the events are never called... right?
}