-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ErrEventUnhandled to indicate call next handler
- Loading branch information
Showing
14 changed files
with
70 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,45 @@ | ||
package jaws | ||
|
||
import "github.com/linkdata/jaws/what" | ||
import ( | ||
"github.com/linkdata/jaws/what" | ||
) | ||
|
||
type EventHandler interface { | ||
JawsEvent(e *Element, wht what.What, val string) (stop bool, err error) | ||
JawsEvent(e *Element, wht what.What, val string) (err error) | ||
} | ||
|
||
type errEventUnhandled struct{} | ||
|
||
func (errEventUnhandled) Error() string { | ||
return "event unhandled" | ||
} | ||
|
||
// ErrEventUnhandled returned by JawsEvent() or JawsClick() causes the next | ||
// available handler to be invoked. | ||
var ErrEventUnhandled = errEventUnhandled{} | ||
|
||
// EventFn is the signature of a event handling function to be called when JaWS receives | ||
// an event message from the Javascript via the WebSocket connection. | ||
type EventFn = func(e *Element, wht what.What, val string) (stop bool, err error) | ||
type EventFn = func(e *Element, wht what.What, val string) (err error) | ||
|
||
type eventFnWrapper struct{ EventFn } | ||
|
||
func (ehf eventFnWrapper) JawsEvent(e *Element, w what.What, v string) (stop bool, err error) { | ||
func (ehf eventFnWrapper) JawsEvent(e *Element, w what.What, v string) (err error) { | ||
return ehf.EventFn(e, w, v) | ||
} | ||
|
||
var _ EventFn = eventFnWrapper{}.JawsEvent // statically ensure JawsEvent and EventFn are compatible | ||
|
||
func callEventHandler(obj any, e *Element, wht what.What, val string) (stop bool, err error) { | ||
func callEventHandler(obj any, e *Element, wht what.What, val string) (err error) { | ||
if wht == what.Click { | ||
if h, ok := obj.(ClickHandler); ok { | ||
if stop, err = h.JawsClick(e, val); stop || err != nil { | ||
if err = h.JawsClick(e, val); err != ErrEventUnhandled { | ||
return | ||
} | ||
} | ||
} | ||
if h, ok := obj.(EventHandler); ok { | ||
return h.JawsEvent(e, wht, val) | ||
} | ||
return | ||
return ErrEventUnhandled | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters