On Fri, Aug 22, 2014 at 10:00 AM, Cristian Rinaldi <[email protected]> wrote:
> I followed with JsInterop and implement a basic version of Promise (not > full implemented). > The code is here: > 1) > > https://github.com/workingflows/gwt-jscore/tree/master/src/main/java/com/workingflows/js/jscore/client/api/promise > <https://github.com/workingflows/gwt-jscore/tree/master/src/main/java/com/workingflows/js/jscore/client/api/promise> > (Promise > API) > 2) > https://github.com/workingflows/gwt-jscore/tree/master/src/main/java/com/workingflows/js/jscore/client/factory > (Factory API) > > I found some things, for example: > > Promise has the "catch" method, and this is a reserved word in Java. > Then, on the interface that represents Promise, can not be put this > method. Perhaps, there could be a JsAlias for functions: > > @JsType(isNative = true, prototype = "Promise") > public interface Promise { > > > Promise then(PromiseThenFn f, PromiseThenFn error); > > @JsAlias(value="catch") > Promise catchError(PromiseThenFn error); > } > > Hmm, we probably going to need something like that. > > Another annoying thing is the management function as a parameter, for > example: > > In JS: > > var p = new Promise (function (resolved, rejected) {...}); > > In Java I emulated it this way, and if not the best: > > @JsType > public interface PromiseFn { > void f(Resolve resolve, Rejected rejected); > } > > // In JS Class Factory > public static native PromiseFn Function(PromiseFn fn) /*-{ > return function(resolve, rejected){ > fn.f(resolve, rejected); > } > }-*/; > > For single-abstract-method classes (SAM) without @JsType (or perhaps only the SAMs marked with Java8 @Functional), we are planning to do an auto conversion into real javascript function so that you can directly do this: @Functionalpublic interface PromiseFn { void f(Resolve resolve, Rejected rejected); } final Promise p3 = Browser.newPromise(new PromiseFn() { @Override public void f(Resolve resolve, Rejected rejected) { resolve.resolve("Resolve Promise P3"); } }); > And use this: > > final Promise p3 = Browser.newPromise(JS.Function(new PromiseFn() { > @Override > public void f(Resolve resolve, Rejected rejected) { > resolve.resolve("Resolve Promise P3"); > } > })); > > I do not know if they are working in a cleaner way to work with functions > to JS style. > > Example Usage of Promise: > > Promise p1 = Browser.newPromise(JS.Function(new PromiseFn() { > @Override > public void f(Resolve resolve, Rejected rejected) { > resolve.resolve("Resolve Promise P1"); > } > })); > > p1.then( > JS.Function( > new PromiseThenFn() { > @Override > public Promise f(final Object changed) { > Browser.getWindow().getConsole().log("Promise Complete: " > + changed); > return Browser.newPromise(JS.Function(new PromiseFn() { > @Override > public void f(Resolve resolve, Rejected rejected) { > resolve.resolve(changed + " > Other Promise"); > } > })); > } > }), JS.Function( > new PromiseThenFn() { > @Override > public Promise f(final Object changed) { > Browser.getWindow().getConsole().log("Promise with Error: > " + changed); > return Browser.newPromise(JS.Function(new PromiseFn() { > @Override > public void f(Resolve resolve, Rejected rejected) { > rejected.rejected(changed + " > Other With Error > Promise"); > } > })); > } > }) > ).then( > JS.Function( > new PromiseThenFn() { > @Override > public Promise f(final Object changed) { > Browser.getWindow().getConsole().log("Promise Complete: > " + changed); > return null; > } > }), > JS.Function( > new PromiseThenFn() { > @Override > public Promise f(Object changed) { > Browser.getWindow().getConsole().log("Promise with Error: > " + changed); > return null; > } > }) > ); > > The Result: > > ["Promise Complete: Resolve Promise P1", cZ: ph, cM: Object, tM: function > , __elementTypeId$: 1, __elementTypeCategory$: 3] > ["Promise Complete: Resolve Promise P1 > Other Promise", cZ: ph, cM: > Object, tM: function, __elementTypeId$: 1, __elementTypeCategory$: 3] > > Thanks and hope to suggestions. > > > > El jueves, 21 de agosto de 2014 13:33:38 UTC-3, Goktug Gokdogan escribió: > >> >> >> >> On Thu, Aug 21, 2014 at 5:29 AM, Cristian Rinaldi <[email protected]> >> wrote: >> >>> Thanks +Goktug Gokdogan for response. >>> >>> APT is very good option and java 8 support for GWT 3.0 would be a >>> amazing thing. >>> You have a planning for Elemental 2.0 or initial documentation to share, >>> to how you plan address the desing? >>> >>> >> Nothing planned yet other than the plan to work on it :) My anticipation >> is. initially we will auto generate JsTyped DOM, deal with problems and >> incrementally improve it. >> >> >>> El miércoles, 20 de agosto de 2014 16:38:31 UTC-3, Goktug Gokdogan >>> escribió: >>> >>>> >>>> >>>> >>>> On Wed, Aug 20, 2014 at 6:17 AM, Cristian Rinaldi <[email protected]> >>>> wrote: >>>> >>>>> Community: >>>>> I'm playing with JsInterop , and I have two questions: >>>>> >>>>> 1) Are you planning to try the static methods of JS objects, such >>>>> as Object, Promise, etc.? >>>>> >>>> >>>> >>>> There will be some static helpers provided from the SDK. I originally >>>> started the JSNI 2.0 document but it is basically waiting for me to start >>>> on Elemental 2.0 and accumulate more experience to turn it into something >>>> more concrete. >>>> >>>> >>>> >>>>> 2) How do when an instance is mapped to an existing Object, eg >>>>> Promise, has a constructor with parameters? >>>>> >>>>> >>>> >>>> Actually I have new ideas on this derived from how some other APTs work. >>>> >>>> I need to update the JsInterop doc but these are the options that I'm >>>> thinking right now: >>>> >>>> *Option 1 (works better for extending):* >>>> >>>> @JsType(prototype = "Promise")public interface Promise { >>>> /* Protoype_Promise is an autogenerated package visible class */ >>>> public static class Prototype extends Protoype_Promise { >>>> public Prototype(Function... functions) { >>>> super(functions); >>>> } >>>> } >>>> >>>> void then(Function f); >>>> >>>> void cath(Function f); >>>> } >>>> >>>> >>>> >>>> *Option 2 (works better for general use):* >>>> >>>> @JsType(prototype = "Promise")public interface Promise { >>>> /* Protoype_Promise is an autogenerated package visible class */ >>>> public static Promise create(Function... functions) { >>>> return new Protoype_Promise(functions); >>>> } >>>> >>>> void then(Function f); >>>> >>>> void cath(Function f); >>>> } >>>> >>>> >>>> >>>> *Of course one can do both:* >>>> >>>> @JsType(prototype = "Promise")public interface Promise { >>>> >>>> public static class Prototype extends Protoype_Promise { >>>> public Prototype(Function... functions) { >>>> super(functions); >>>> } >>>> } >>>> >>>> public static Promise create(Function... functions) { >>>> return new Prototype(functions); >>>> } >>>> >>>> void then(Function f); >>>> >>>> void cath(Function f); >>>> } >>>> >>>> >>>> >>>> >>>>> Currently to resolve this 1) I created the following class >>>>> Factory: JS >>>>> <https://github.com/workingflows/gwt-jscore/blob/master/src/main/java/com/workingflows/js/jscore/client/factory/JS.java> >>>>> >>>>> But the interfaces define a contract at the level instance of a >>>>> class or object, this way of doing things, I do not know if it is >>>>> semantically correct. >>>>> >>>>> To solve 2) there are not many options: >>>>> >>>>> Create a Factory that returns an instance of the object, because >>>>> it has no meaning, only to make the new, implement the interface, because >>>>> the compiler already does. >>>>> There is some progress in this? >>>>> >>>>> I saw in one of the post a proposal to do something like this: >>>>> >>>>> Promise Promise.Prototype p = new (new Function ....., new >>>>> Function ....); >>>>> >>>>> Where Promise, is the interface defined with prototype = >>>>> "Promise". >>>>> >>>>> @JsType(isNative = true, prototype = "Promise") >>>>> public interface Promise { >>>>> >>>>> void then(Function f); >>>>> >>>>> void cath(Function f); >>>>> } >>>>> >>>>> Here 'access to jsCore project: >>>>> >>>>> https://github.com/workingflows/gwt-jscore/ >>>>> <https://github.com/workingflows/gwt-jscore/> >>>>> >>>>> >>>> Great work. This kind of stuff is also very valuable as a feedback. >>>> >>>> >>>>> I hope the answers ... >>>>> >>>>> greetings >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "GWT Contributors" group. >>>>> To unsubscribe from this group and stop receiving emails from it, send >>>>> an email to google-web-toolkit-contributors+unsubscribe@ >>>>> googlegroups.com. >>>>> To view this discussion on the web visit https://groups.google.com/d/ >>>>> msgid/google-web-toolkit-contributors/3268ccc7-9953-49c9-9079- >>>>> 574096f0d5d3%40googlegroups.com >>>>> <https://groups.google.com/d/msgid/google-web-toolkit-contributors/3268ccc7-9953-49c9-9079-574096f0d5d3%40googlegroups.com?utm_medium=email&utm_source=footer> >>>>> . >>>>> For more options, visit https://groups.google.com/d/optout. >>>>> >>>> >>>> -- >>> You received this message because you are subscribed to the Google >>> Groups "GWT Contributors" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected] >>> . >>> To view this discussion on the web visit https://groups.google.com/d/ >>> msgid/google-web-toolkit-contributors/44fbf2d1-d791- >>> 4e7b-8078-5e804c3da99e%40googlegroups.com >>> <https://groups.google.com/d/msgid/google-web-toolkit-contributors/44fbf2d1-d791-4e7b-8078-5e804c3da99e%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> -- > You received this message because you are subscribed to the Google Groups > "GWT Contributors" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/google-web-toolkit-contributors/b4c4bfb4-9470-49a0-9ab2-67e855ed1a0c%40googlegroups.com > <https://groups.google.com/d/msgid/google-web-toolkit-contributors/b4c4bfb4-9470-49a0-9ab2-67e855ed1a0c%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "GWT Contributors" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit-contributors/CAN%3DyUA3J482ob7Na9-P1OE1ZXTwijpmZvyXycYbrQqHsdW0nWg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
