Two way communication #2143
-
First I wish the documentation contains some examples around events. Second I am looking for a way to call the backend and get the result back (like http request). Is there any way to do so? For example the following event: https://wails.io/docs/reference/runtime/events#eventsemit
It does not send the data back to JS. It could be something like this: let data = {
route: "store/get_list",
body: {
query: {
page: 1,
page_size: 100
}
}
}
EventsEmit("request", data) // returns Promise
.then(result => my_grid.source = result.data) // returns a list of stores
.catch(error => alert(error.message)) // returns error if the go throws an error Go: EventsOn(ctx, "request", func(data) (result, error) {
var request := json.Parse(data).(*DataRequest)
switch (request.route) {
case "store/get_list":
var query := json.Parse(request.body).(*StoreListQuery)
result, error := dbRepository.GetStores(query)
return result, error
default:
return nil, fmt.Errorf("request: route not found %r", request.route)
}
}) Example: https://tauri.app/v1/guides/features/command/#returning-data Is it possible? Without that the Hybrid apps are not possible with Wails. That is the problem why Wails is not so popular. P.S. the Go -> JS communication could be one way only, as it is mostly used for push notifications, nothing else. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
There is an example included in every (I think) starter application of Wails. For example, I know for a fact - Svelte and React templates have it. Not only you get data returned back from Go, but it is also type safe because you have |
Beta Was this translation helpful? Give feedback.
-
Also, feel free to improve the documentation. |
Beta Was this translation helpful? Give feedback.
There is an example included in every (I think) starter application of Wails. For example, I know for a fact - Svelte and React templates have it.
When you have a method declared on your
App
struct, this method is exposed to your frontend after generating module bindings.Or simply put it - after you run
wails dev
orwails build
. Your frontend folder will containswailsjs
folder with all the bindings.I do however recommend checking out the templates and see how frontend makes the call to Go with a simple demo of Inputting your name, submitting it to the backend (Go) and it returns you a formatted string.
Not only you get data returned back from Go, but it is also type safe because you have