JQueryPluginExtension and more..

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

JQueryPluginExtension and more..

sledorze
Thanks Juraj for the idea, had a great moment!

http://lambdabrella.blogspot.com/2011/10/compile-time-extension-generation-in.html

You can use it now..

Stéphane
Reply | Threaded
Open this post in threaded view
|

Re: JQueryPluginExtension and more..

blackdog
On 10/20/2011 06:54 PM, sledorze wrote:

> Thanks Juraj for the idea, had a great moment!
>
> http://lambdabrella.blogspot.com/2011/10/compile-time-extension-generation-in.html
>
> You can use it now..
>
> Stéphane
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/JQueryPluginExtension-and-more-tp6914974p6914974.html
> Sent from the Haxe mailing list archive at Nabble.com.
>
Very useful, thanks.

R

--
Simplicity is the ultimate sophistication. ~ Leonardo da Vinci


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: JQueryPluginExtension and more..

Justin Donaldson-3
Nice job, was just thinking along these lines lately. 

-Justin

On Thu, Oct 20, 2011 at 4:28 PM, blackdog <[hidden email]> wrote:
On 10/20/2011 06:54 PM, sledorze wrote:
> Thanks Juraj for the idea, had a great moment!
>
> http://lambdabrella.blogspot.com/2011/10/compile-time-extension-generation-in.html
>
> You can use it now..
>
> Stéphane
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/JQueryPluginExtension-and-more-tp6914974p6914974.html
> Sent from the Haxe mailing list archive at Nabble.com.
>
Very useful, thanks.

R

--
Simplicity is the ultimate sophistication. ~ Leonardo da Vinci


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: JQueryPluginExtension and more..

Juraj Kirchheim
In reply to this post by sledorze
Bien joué, Stéphane! :)

After a little testing and refining, this should definitely go on
haxelib or maybe even into the std lib (haxe.macro package) in one
form or another.

I think you should decouple it from jQuery however. Here's an idea:
- Make it an interface like Wrapper<Wrappee> (use a better name,
that's clearer, yet generic enough) that uses a niladic
autoBuild-macro.
- In that build-macro, read out the value of Wrappee
(Context.getLocalClass().get().interfaces or so)
- Convert the Type back to a ComplexType, but if you implement this
solely for classes without type parameters, this is both simple and
good enough for a start
- Use that type for the first parameter of the generated static methods

Also, I think one should be able to use strings or identifiers for the
@:native metadata. Unless the identifier is invalid in haXe, I think
using one is preferable. And I think it would make sense to make the
generated methods public, unless they're explicitly private.

Usage would be:

class MyJQuery implements Wrapper<js.JQuery> {
    /** and so on **/
}

Also, you could define an empty interface called Self or so and then
do something like:

extern class Db implements Wrapper<Self> {//taken from your blog post
      @:native(collectionsInfo) function cursor():Cursor;
      @:native(collectionsInfo) function getCursor(cb:Error->Cursor->Void):Void;
      @:native(collectionsInfo) function
getCollectionCursor(name:String, cb:Error->Cursor->Void):Cursor;
}

Apparently, static inline methods on external classes always get
inlined (even when --no-inline is set).
So it would seem, that one can create a very nice way to write clean
wrappers over overloaded functions or to merely rename methods in
wrappers. And the ability to integrate jQuery extension signatures is
actually just a pleasant side-effect :)

On Thu, Oct 20, 2011 at 11:54 PM, sledorze <[hidden email]> wrote:

> Thanks Juraj for the idea, had a great moment!
>
> http://lambdabrella.blogspot.com/2011/10/compile-time-extension-generation-in.html
>
> You can use it now..
>
> Stéphane
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/JQueryPluginExtension-and-more-tp6914974p6914974.html
> Sent from the Haxe mailing list archive at Nabble.com.
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: JQueryPluginExtension and more..

sledorze
this, now works with trunk:


import com.mindrocks.macros.ExtendsType;
import js.JQuery;

class Foo<T, U> {
  public function new() {
   
  }
}

class Tata {
 
}
class Toto {
 
}

class MyJQueryPluginExtension implements ExtendsType<JQuery> {
  @:native("val") public function valGet() : Dynamic;
  @:native("val") public function valSet(x : Dynamic) : JQuery;
  @:native("val") public function valFun(f : Int -> Dynamic -> Dynamic) : JQuery;
}

class TestExtension implements ExtendsType<Foo<Toto, Tata>> {
  @:native("val") public function valGet() : Dynamic;
  @:native("val") public function valSet(x : Dynamic) : JQuery;
  @:native("val") public function valFun(f : Int -> Dynamic -> Dynamic) : JQuery;
}

typedef Joe = {
  tata : Int, toto : String
}

class TestTypedefExtension implements ExtendsType<Joe> {
  @:native("val") public function valGet() : Dynamic;
  @:native("val") public function valSet(x : Dynamic) : JQuery;
  @:native("val") public function valFun(f : Int -> Dynamic -> Dynamic) : JQuery;
}

class TestStructExtension implements ExtendsType<{ tata : Int, toto : Array<String> -> Int -> { b : Bool, c : Int } }> {
  @:native("val") public function valGet() : Dynamic;
  @:native("val") public function valSet(x : Dynamic) : JQuery;
  @:native("val") public function valFun(f : Int -> Dynamic -> Dynamic) : JQuery;
}
Reply | Threaded
Open this post in threaded view
|

Re: JQueryPluginExtension and more..

sledorze
In reply to this post by Juraj Kirchheim
French?
Ou es tu en france? (suis à Lille).

++
Reply | Threaded
Open this post in threaded view
|

Re: JQueryPluginExtension and more..

Juraj Kirchheim
Non, pas French. Je viens de Leipzig. Mais j'ai passé une annee à
Lyon. Histoire d'apprendre la langue et apprécier la cuisine :)

On Sat, Oct 22, 2011 at 3:39 PM, sledorze <[hidden email]> wrote:

> French?
> Ou es tu en france? (suis à Lille).
>
> ++
>
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/JQueryPluginExtension-and-more-tp6914974p6920131.html
> Sent from the Haxe mailing list archive at Nabble.com.
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org