wailsapp / wails

Create beautiful applications using Go
https://wails.io
MIT License
25.34k stars 1.22k forks source link

window.backend.SomeStruct.SomeMethod is not a function #243

Closed bh90210 closed 5 years ago

bh90210 commented 5 years ago

Description

I have an issue when trying to use methods of structs in the frontend.

Let's say we have this main.go

package main

import (
  "github.com/leaanthony/mewn"
  "github.com/wailsapp/wails"
)

func basic() string {
  return "Hello World!"
}

func basic2() string {
  return "Hello World!"
}

type Testio struct {
    test2 int
}

func (t *Testio) Testio1() {
}

func (t *Testio) Testio2() {
}

func main() {

  js := mewn.String("./frontend/dist/app.js")
  css := mewn.String("./frontend/dist/app.css")

  app := wails.CreateApp(&wails.AppConfig{
    Width:  1024,
    Height: 768,
    Title:  "testio2",
    JS:     js,
    CSS:    css,
    Colour: "#131313",
  })
  app.Bind(basic)
  app.Bind(basic2)
  app.Bind(&Testio{})
  app.Run()
}

while serving, I try to check the methods are working via the console and I get:

VM1315:1 Uncaught TypeError: window.backend.Testio.Testio1 is not a function
    at <anonymous>:1:23

this is the log of when wails serve starts

INFO[0000] [Bind] Binding Go Functions/Methods          
INFO[0000] [Bind] Bound Function: main.basic()          
INFO[0000] [Bind] Bound Function: main.basic2()         
INFO[0000] [Bind] Bound Method: main.Testio.Testio1()   
INFO[0000] [Bind] Bound Method: main.Testio.Testio2()   

if then I remove the second method func (t *Testio) Testio2() the first method works fine (see screenshots)

To Reproduce Steps to reproduce the behaviour:

  1. Initialise a new project (I have reproduced it with react and vue, but seems irrelevant)
  2. make a struct with as least two methods
  3. bind the struct and serve the app
  4. go to browser's console, try the methods and see the error

Expected behaviour Having all methods of a binded struct exported

Screenshots Screenshot_20190928_161543 Screenshot_20190928_161841

System Details

Name Value
Wails Version v0.17.15-pre
Go Version go1.13
Platform linux
Arch amd64
GO111MODULE on
GCC 8.3.0
Npm v12.10.0
Node 6.10.3
leaanthony commented 5 years ago

I've identified the issue and got a fix. However there appears to be another related bug that needs to be fixed first. I'M ON IT! :joy:

leaanthony commented 5 years ago

Fixed by #245 - in develop.

bh90210 commented 5 years ago

~I am afraid it didn't fix it :/~ it works fine!

for future reference replace github.com/wailsapp/wails v0.17.15-pre => /path/to/wails/

:+1: