It should work but you also have to make sure that GWT code is loaded. So after the crash - hit F12 go to console and try to reference $wnd.test.JsOpClass or put a console print inside onModuleLoad to see when GWT code is loaded: before or after the crash
Vassilis On Tue, Apr 11, 2017 at 5:52 PM, Philipp Gloor <[email protected]> wrote: > Where do I use $wnd.test.JsOpClass()? It doesn't work within <script> tags > inside the HMTL file of my GWT project. > > The reason I'm looking at JsInterop was because we want to use web > workers. And since there is no GWT implementation of web workers I would do > this via native calls. And the web worker would only forward methods > because once I'm in the worker thread I have to call GWT functions again. > > GWT Mainthread ---> Worker.js ---> GWT in a worker thread > > The calls from Worker.js to GWT in the worker thread would also pass an > instance of the worker itself into GWT (as JavaScriptObject) so I could > call worker.postMessage to get back to the main thread. > > > > On 11 April 2017 at 16:42, Vassilis Virvilis <[email protected]> wrote: > >> Hi, >> >> 1. With jsinterop you won't need any JSNI normally. >> 2. If you have older JSNI code that calls your new code (can't really >> happen) you can >> a) use new $wnd.test.JsOpClass(); with -generateJsInteropExports as >> Thomas suggested >> b) use the old syntax found here http://www.gwtproject.org/doc/ >> latest/DevGuideCodingBasicsJSNI.html and that would be something like @ >> com.test.workertest.shared.JsOpClass::new()() Note the ()() double >> parenthesis. >> >> Do you want JsOpClass to be visible from both js and java? >> >> >> On Tue, Apr 11, 2017 at 5:29 PM, Philipp Gloor <[email protected]> >> wrote: >> >>> Can I access Classes and Methods decorated with JsType/JsMethod from >>> anywhere within GWT granted I'm inside a JSNI block? Or is it restricted to >>> packages? >>> >>> I added the -generateJsInteropExports to the run configuration arguments >>> but when I try to create a new object JsOpClass() it tells me $wnd.pdf is >>> undefined. >>> >>> On 11 April 2017 at 11:32, Thomas Broyer <[email protected]> wrote: >>> >>>> >>>> >>>> On Tuesday, April 11, 2017 at 10:43:06 AM UTC+2, Philipp wrote: >>>>> >>>>> If I have a java class and I mark it with @JsType I create a contract >>>>> between Java and Javascript that I can use this class with it's given Java >>>>> name in Javascript - is this correct? >>>>> >>>>> package com.test.workertest.shared; >>>>> >>>>> >>>>> import com.google.gwt.core.shared.GWT; >>>>> >>>>> >>>>> import jsinterop.annotations.*; >>>>> >>>>> >>>>> @JsType(namespace = "test", name = "JsOpClass") >>>>> public class JsOpClass >>>>> { >>>>> >>>>> >>>>> @JsMethod >>>>> public void printStuff() >>>>> { >>>>> GWT.log("asdfasdf"); >>>>> } >>>>> } >>>>> >>>>> >>>>> I would like to be able to create now a JsOpClass object in javascript >>>>> and call printStuff() on this object but I actually don't understand where >>>>> this is meant to be working. If I create for example a web worker which >>>>> would create this class it reports that >>>>> >>>>> com.google.gwt.event.shared.UmbrellaException: Exception caught: ( >>>>> ReferenceError) : testis not defined >>>>> >>>>> which makes sense because my worker.js knows nothing about GWT (would >>>>> this be possible?) >>>>> >>>>> And even if I try it in the GWT HTML file it doesn't seem to know >>>>> about this class and I get a test is not defined error. >>>>> >>>>> How do I actually call exposed classes/methods and from where is it >>>>> possible? >>>>> >>>> >>>> First, you have to pass -generateJsInteropExports to GWT (compiler, >>>> codeserver, devmode), to actually export the JsType to JavaScript. >>>> Then, from the context the GWT app (*.nocache.js) was loaded in, you >>>> should be able to do '(new test.JsOpClass()).printStuff()', *after* your >>>> GWT app has been loaded/started (once onModuleLoad has been called) >>>> >>>> >>>>> Is it only a JSNI substitute >>>>> >>>> >>>> Yes. >>>> >>>> >>>>> (but even then I was not able to call it from a JSNI method). >>>>> >>>> >>>> var o = new $wnd.test.JsOpClass(); >>>> o.printStuff(); >>>> >>>> …but maybe all you miss is the -generateJsInteropExports? >>>> >>>> -- >>>> You received this message because you are subscribed to a topic in the >>>> Google Groups "GWT Users" group. >>>> To unsubscribe from this topic, visit https://groups.google.com/d/to >>>> pic/google-web-toolkit/wpcpNJka5qo/unsubscribe. >>>> To unsubscribe from this group and all its topics, send an email to >>>> [email protected]. >>>> To post to this group, send email to google-web-toolkit@googlegroup >>>> s.com. >>>> Visit this group at https://groups.google.com/group/google-web-toolkit. >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "GWT Users" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> To post to this group, send email to [email protected] >>> . >>> Visit this group at https://groups.google.com/group/google-web-toolkit. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> >> >> -- >> Vassilis Virvilis >> >> -- >> You received this message because you are subscribed to a topic in the >> Google Groups "GWT Users" group. >> To unsubscribe from this topic, visit https://groups.google.com/d/to >> pic/google-web-toolkit/wpcpNJka5qo/unsubscribe. >> To unsubscribe from this group and all its topics, send an email to >> [email protected]. >> To post to this group, send email to [email protected]. >> Visit this group at https://groups.google.com/group/google-web-toolkit. >> For more options, visit https://groups.google.com/d/optout. >> > > -- > You received this message because you are subscribed to the Google Groups > "GWT Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/google-web-toolkit. > For more options, visit https://groups.google.com/d/optout. > -- Vassilis Virvilis -- You received this message because you are subscribed to the Google Groups "GWT Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/google-web-toolkit. For more options, visit https://groups.google.com/d/optout.
