Description
I'm trying to do a gopherjs binding for VueJS. I found a clear way to do bidirectional data bindings from gopherjs to VueJS and so far it works great 😄 But I came into this problem when VueJS
trying to set time.Time
from javascript side to gopherjs code, error code is here: https://github.com/oskca/gopherjs-vue/blob/master/examples/unwritableTime/main.go#L20. (you can try it with gopherjs serve
)
The error stack goes to $internalize
, :
var timePkg = $packages["time"];
if (timePkg !== undefined && t === timePkg.Time) {
if (!(v !== null && v !== undefined && v.constructor === Date)) {
$throwRuntimeError("cannot internalize time.Time from " + typeof v + ", must be Date");
}
return timePkg.Unix(new $Int64(0, 0), new $Int64(0, v.getTime() * 1000000));
}
Normal gopherjs code with time.Time
works fine, but in this case VueJS
probably tries to set time.Time
with a function or some other customed data types.
How could this problem be solved? Isn't !(v !== null && v !== undefined && v.constructor === Date)
too much restricted? What about just return time.Time{}
with warning message instead?