Skip to content

Error using jquery with time package #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
govlas opened this issue Aug 14, 2015 · 6 comments
Closed

Error using jquery with time package #10

govlas opened this issue Aug 14, 2015 · 6 comments

Comments

@govlas
Copy link

govlas commented Aug 14, 2015

code:

package main

import (
    "strconv"
    "time"

    "github.com/gopherjs/jquery"
)

var jq = jquery.NewJQuery

func main() {
    body := jq("body")
    content := jq("<div>").AppendTo(body)

    for i := 0; i < 10; i++ {

        content.SetHtml(strconv.Itoa(i))
        time.Sleep(time.Second)

    }
}

produces error in browser:

go-js.js:1738: Uncaught TypeError: Cannot read property 'ptr' of undefined

in function $externalize

    if (timePkg && v.constructor === timePkg.Time.ptr) {

timePkg.Time is not defined in javascript code

to solve the problem I add

var _ = time.Now()
@rusco
Copy link
Member

rusco commented Aug 17, 2015

Good catch !

I strongly suspect that it's a GopherJS isse and not related to any Dom manipulations done by jQuery or the jQuery Binding. For now my plan is trying to distill an example without jQuery involved and submit the issue to the GopherJS issues list . The following similar example works:

package main

import (
    "github.com/gopherjs/gopherjs/js"
    "github.com/gopherjs/jquery"
    "strconv"
    "time"
)

func log(i ...interface{}) {
    js.Global.Get("console").Call("log", i...)
}

var jq = jquery.NewJQuery

func main() {

    for i := 0; i < 10; i++ {

        jq("<div>" + strconv.Itoa(i) + "</div>").InsertAfter("body")
        log(strconv.Itoa(i))
        time.Sleep(time.Second)
    }
}

@rusco
Copy link
Member

rusco commented Aug 17, 2015

a shorter version to work on. I have a hard time to reproduce this without the jQuery dependency:

package main

import (
    "github.com/gopherjs/gopherjs/js"
    "github.com/gopherjs/jquery"
    "time"
)

func log(i ...interface{}) {
    js.Global.Get("console").Call("log", i...)
}

//activate one "main" func: 
func main_ok() {
    body := jquery.NewJQuery("body")
    //log(body)
    _ = body
    time.Sleep(time.Second)
    log("done.")
}

func main_bug() {
    body := jquery.NewJQuery("body")
    log(body)
    //_ = body
    time.Sleep(time.Second)
    log("done.")
}

@neelance : In the first case the "Time" struct of the time package is available, in the second case it is "undefined". Could you have a look at this ? looks like a GopherJS topic

@govlas
Copy link
Author

govlas commented Aug 26, 2015

So, this code without jquery does not work ;)

package main

import (
    "time"

    "github.com/gopherjs/gopherjs/js"
)

//var _ = time.Now()

func log(i ...interface{}) {
    js.Global.Get("console").Call("log", i...)
}

type Test struct {
    A int
    B string
}

func main() {
    log(Test{1, "hello"})
    time.Sleep(time.Second)
}

@rusco
Copy link
Member

rusco commented Aug 26, 2015

Excellent ! Now this bug can be assigned directly to the gopherjs/gopherjs project and not jQuery.
Can you do this ? Otherwise I will do it.

@govlas
Copy link
Author

govlas commented Aug 26, 2015

I'll do

@govlas
Copy link
Author

govlas commented Aug 26, 2015

up to gopherjs/gopherjs#279

@govlas govlas closed this as completed Aug 31, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants