Static methods on interfaces is a Java8 only feature, but I prefer it.
Since you can use Java8 with GWT even if you are running Java7 or below as
a JVM, and since these features are not for shared code, but for Web code,
I'm kinda leaning towards the idea of JSNI 2.0 requiring Java8. We should
have a debate about this in the community. We get several benefits:

1. Static methods on interfaces
2. Defender methods to implement JSNI fragments on JsTypes
3. APIs designed for Lambdas everywhere.


Here's a motivating usecase right now:

@JsType
interface SomeJsType {
  void someMethod();
  default void anotherMethod(int arg) {
    js("this.doIt($0, "must be present", arg);
  }
}

That is, there are some cases in Js interfaces where default prototype
dispatch is not what you want, and you need wrapper code.


Another use case

@JsType
@IterateAsArray(getter = "item", length="length")
interface NodeList<T extends Element> extends Iterable<T> {
    T item(int x);
    int length();

   default Iterator<T> iterator() {
      return NodeListIterator(this);
   }
}


for (T x : nodeList) { ... }

Are we ballsy enough to say GWT 3.0 = Java8 source level enforced for
client side code?




On Wed, Aug 20, 2014 at 12:38 PM, 'Goktug Gokdogan' via GWT Contributors <
google-web-toolkit-contributors@googlegroups.com> wrote:

>
>
>
> On Wed, Aug 20, 2014 at 6:17 AM, Cristian Rinaldi <csrina...@gmail.com>
> 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+unsubscr...@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 google-web-toolkit-contributors+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-web-toolkit-contributors/CAN%3DyUA0ZpjT%2Bf%2ByqbwCHsSSPWaawLtJwf%2BPTTvbd68zE2Oxh%2Bw%40mail.gmail.com
> <https://groups.google.com/d/msgid/google-web-toolkit-contributors/CAN%3DyUA0ZpjT%2Bf%2ByqbwCHsSSPWaawLtJwf%2BPTTvbd68zE2Oxh%2Bw%40mail.gmail.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 google-web-toolkit-contributors+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-web-toolkit-contributors/CAPVRV7eq1ZNZKCj22mYk9ttKkE%2BammBWuV1KPDN5e%2BM_by5TsQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to