How to provide signatures for JQuery plugins?

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

How to provide signatures for JQuery plugins?

sledorze
Hi!

I think it is not possible to provide signatures 'extensions' for JQuery plugins..
I can rely on simple extensions but then miss overloading.

Looks hard to grasp the javascript possibilities with these tools.
The ability to provide additional signatures for an already defined extern typedef / class would solve this issue.

Anything I missed?
Stephane
Reply | Threaded
Open this post in threaded view
|

Re: How to provide signatures for JQuery plugins?

Nicolas Cannasse
Le 18/10/2011 21:58, sledorze a écrit :

> Hi!
>
> I think it is not possible to provide signatures 'extensions' for JQuery
> plugins..
> I can rely on simple extensions but then miss overloading.
>
> Looks hard to grasp the javascript possibilities with these tools.
> The ability to provide additional signatures for an already defined extern
> typedef / class would solve this issue.
>
> Anything I missed?

@:native("js.JQuery") extern class MyQuery extends js.JQuery ?

Best,
Nicolas

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

Re: How to provide signatures for JQuery plugins?

sledorze
Yes, I think so.. :p

@:native("js.JQuery") extern class MyQuery extends js.JQuery {
  public function myExternFunction() : Void {}
  public function new() : Void {}
}

new MyQuery("#id").whateverJQueryFunctionWithChaining().myExternFunction(); // Won't compile as it is now back to its JQuery super type.

A solution would be to change JQuery signature to specify a type parameter and use it wherever JQuery is used.
(Not to mention existing non polymorphic code can't be extended).

Another one would be to introduce self type.. (I haven't though much about it but it is must be very involving for the compiler).

Stephane
Reply | Threaded
Open this post in threaded view
|

Re: How to provide signatures for JQuery plugins?

Juraj Kirchheim
Well, here's a workaround:

@:autoBuild(JQueryExtensionBuilder.build()) interface JQueryExtension {}

class MyExtension implements JQueryExtension {
 public function myExternFunction1() : A;
 public function myExternFunction2(x:X) : B;
}

The autoBuild will transform that to:

class MyExtension implements JQueryExtension {
 static public inline function myExternFunction1(__jq:JQuery) : A {
       return untyped __jq.myExternFunction1();
 }
 static public inline function myExternFunction2(__jq:JQuery, x:X) : B {
       return untyped __jq.myExternFunction2(x);
 }
}

The macro should be pretty straight forward to implement.
And you simply use the extension with `using MyExtension;`

You could also have the marco pickup an @:compile(pathToLocalFile) or
@:load(aURLtoJSFile) to inject the JavaScript during compilation or
generate a statement that will cause loading at runtime. This would
create a very neat and clean way to bundle JQuery extensions for haXe
and to only use them on demand.


On Wed, Oct 19, 2011 at 11:06 AM, sledorze <[hidden email]> wrote:

> Yes, I think so.. :p
>
> @:native("js.JQuery") extern class MyQuery extends js.JQuery {
>  public function myExternFunction() : Void {}
>  public function new() : Void {}
> }
>
> new MyQuery("#id").whateverJQueryFunctionWithChaining().myExternFunction();
> // Won't compile as it is now back to its JQuery super type.
>
> A solution would be to change JQuery signature to specify a type parameter
> and use it wherever JQuery is used.
> (Not to mention existing non polymorphic code can't be extended).
>
> Another one would be to introduce self type.. (I haven't though much about
> it but it is must be very involving for the compiler).
>
> Stephane
>
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/How-to-provide-signatures-for-JQuery-plugins-tp6906149p6907831.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: How to provide signatures for JQuery plugins?

Nicolas Cannasse
Le 19/10/2011 13:37, Juraj Kirchheim a écrit :

> Well, here's a workaround:
>
> @:autoBuild(JQueryExtensionBuilder.build()) interface JQueryExtension {}
>
> class MyExtension implements JQueryExtension {
>   public function myExternFunction1() : A;
>   public function myExternFunction2(x:X) : B;
> }
>
> The autoBuild will transform that to:
>
> class MyExtension implements JQueryExtension {
>   static public inline function myExternFunction1(__jq:JQuery) : A {
>         return untyped __jq.myExternFunction1();
>   }
>   static public inline function myExternFunction2(__jq:JQuery, x:X) : B {
>         return untyped __jq.myExternFunction2(x);
>   }
> }
>
> The macro should be pretty straight forward to implement.
> And you simply use the extension with `using MyExtension;`

Nice one !

Best,
Nicolas

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

Re: How to provide signatures for JQuery plugins?

sledorze
In reply to this post by Juraj Kirchheim
Looks interesting BUT (let me ask further) wouldn't still be able to have @:overload I guess..
Maybe you may prove *again* my limited judgement :) (please, oh please.. lol)

Have to invest some time doing some macros stuff soon for nodeJs so maybe a good starter :)


On Wed, Oct 19, 2011 at 1:39 PM, Juraj Kirchheim [via Haxe] <[hidden email]> wrote:
Well, here's a workaround:

@:autoBuild(JQueryExtensionBuilder.build()) interface JQueryExtension {}

class MyExtension implements JQueryExtension {
 public function myExternFunction1() : A;
 public function myExternFunction2(x:X) : B;
}

The autoBuild will transform that to:

class MyExtension implements JQueryExtension {
 static public inline function myExternFunction1(__jq:JQuery) : A {
       return untyped __jq.myExternFunction1();
 }
 static public inline function myExternFunction2(__jq:JQuery, x:X) : B {
       return untyped __jq.myExternFunction2(x);
 }
}

The macro should be pretty straight forward to implement.
And you simply use the extension with `using MyExtension;`

You could also have the marco pickup an @:compile(pathToLocalFile) or
@:load(aURLtoJSFile) to inject the JavaScript during compilation or
generate a statement that will cause loading at runtime. This would
create a very neat and clean way to bundle JQuery extensions for haXe
and to only use them on demand.


On Wed, Oct 19, 2011 at 11:06 AM, sledorze <[hidden email]> wrote:

> Yes, I think so.. :p
>
> @:native("js.JQuery") extern class MyQuery extends js.JQuery {
>  public function myExternFunction() : Void {}
>  public function new() : Void {}
> }
>
> new MyQuery("#id").whateverJQueryFunctionWithChaining().myExternFunction();
> // Won't compile as it is now back to its JQuery super type.
>
> A solution would be to change JQuery signature to specify a type parameter
> and use it wherever JQuery is used.
> (Not to mention existing non polymorphic code can't be extended).
>
> Another one would be to introduce self type.. (I haven't though much about
> it but it is must be very involving for the compiler).
>
> Stephane
>
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/How-to-provide-signatures-for-JQuery-plugins-tp6906149p6907831.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



If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/How-to-provide-signatures-for-JQuery-plugins-tp6906149p6908258.html
To unsubscribe from How to provide signatures for JQuery plugins?, click here.



--
Stéphane Le Dorze


Reply | Threaded
Open this post in threaded view
|

Re: How to provide signatures for JQuery plugins?

Juraj Kirchheim
I suppose overload would be a little hard here.
You could however refine the macro further as follows:

class MyExtension implements JQueryExtension {
      @:native(overloadedJQueryFunction) public function myOwnFunction():B;
}

And let that be translated to:

class MyExtension implements JQueryExtension {
      static public inline function myOwnFunction(__jq:JQuery):B {
               return untyped __jq.overloadedJQueryFunction();
      }
}

>From a haXe perspective, this is actually cleaner than resorting to @:overload.
Overloading is less a real haXe feature, but more of a compromise to
bend its type system around JavaScript.

On Wed, Oct 19, 2011 at 2:11 PM, sledorze <[hidden email]> wrote:
> Looks interesting BUT (let me ask further) wouldn't still be able to have
> @:overload I guess..
> Maybe you may prove *again* my limited judgement :) (please, oh please..
> lol)
> Have to invest some time doing some macros stuff soon for nodeJs so maybe a
> good starter :)

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

Re: How to provide signatures for JQuery plugins?

rammserker
Hi.

Sorry, perhaps is my ignorance buuut... Where is JQueryExtensionBuilder macro class? I can't see it :(

Max
0 1 0 | 0 0 1 | 1 1 1

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

Re: How to provide signatures for JQuery plugins?

Juraj Kirchheim
It's in Stephane's capable hands. Or yours, if you prefer ;)

It's really not so hard to implement. Loop all buildfields. Those with
no AStatic in the access and a kind of FFun(f) where f.expr is null
are the once you want. Just slap AStatic and AInline on it, prepend an
argument to f and set f.expr to a forwarding call.
And then of course you can add the little gimmicks I proposed.

2011/10/20 Maximiliano Fernández <[hidden email]>:

> Hi.
>
> Sorry, perhaps is my ignorance buuut... Where is JQueryExtensionBuilder
> macro class? I can't see it :(
>
> Max
> 0 1 0 | 0 0 1 | 1 1 1
>
> --
> 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: How to provide signatures for JQuery plugins?

rammserker
Oh, I see. I was asking because, perhaps, I was missing some attached file :P I'm experimenting with macro and if there was a file, I could check it, but wasn't there. I can implement it ;) Thanks!

Max
0 1 0 | 0 0 1 | 1 1 1



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