hexonaut / haxe-dom

A cross-platform implementation of the DOM. Built to reduce duplicate code across server and client.
MIT License
47 stars 4 forks source link

Move client only code to a macro #11

Closed hexonaut closed 10 years ago

hexonaut commented 10 years ago

Client-only code is currently handled by @clientInit meta data attached to a method. This is okay, but it leads to extra code required to invoke the function upon construction of the object on the client. IE

class MyObject {
    public function new () {
        //Generic setup

        #if js
        clientCode();
        #end
    }
    @clientInit
    public function clientCode ():Void {
        //Do something only on the client
    }
}

This should be switched to a macro that not only invokes the method upon load, but also if the constructor is called on the client.