vert-x3 / vertx-lang-js

Nashorn JavaScript implementation for Vert.x
Apache License 2.0
35 stars 23 forks source link

Handler subtype #13

Closed vietj closed 9 years ago

vietj commented 9 years ago

@purplefox please review

vietj commented 9 years ago

do you have some time to review this @purplefox ?

purplefox commented 9 years ago

Could you explain this a bit, and the fix?

vietj commented 9 years ago

currently we have usage of interfaces that extends Handler in Apex and we do use those sub interfaces as handle arguments.

In JS method arguments, such handlers are expected to be function type. Such handler subtypes are objects that provide an "handle" method.

This patch allows to use them directly as handlers (which is what is done in Java or Groovy) instead of referencing the handle method. Handlers are either function (like before) or objects that are subtypes of the io.vertx.core.Handler interface.

purplefox commented 9 years ago

Can't the user simply do:

router.route(handler.handle);

?

vietj commented 9 years ago

they can, however it helps the codetrans project to create correct JS code from Java code when creating such handlers in examples and doc.

vietj commented 9 years ago

for instance in Apex we do have examples like:

    router.route().handler(CookieHandler.create());
    router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));

    AuthService authService = AuthService.createEventBusProxy(vertx, "acme.authservice");
    AuthHandler redirectAuthHandler = RedirectAuthHandler.create(authService);

    // All requests to paths starting with '/private/' will be protected
    router.route("/private/").handler(redirectAuthHandler);

    // Handle the actual login
    router.route("/login").handler(FormLoginHandler.create(authService));

    // Set a static server to serve static resources, e.g. the login page
    router.route().handler(StaticHandler.create());

it should be rewritten:

    router.route().handler(CookieHandler.create()::handle);
    router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx))::handle);

    AuthService authService = AuthService.createEventBusProxy(vertx, "acme.authservice");
    AuthHandler redirectAuthHandler = RedirectAuthHandler.create(authService);

    // All requests to paths starting with '/private/' will be protected
    router.route("/private/").handler(redirectAuthHandler::handle);

    // Handle the actual login
    router.route("/login").handler(FormLoginHandler.create(authService)::handle);

    // Set a static server to serve static resources, e.g. the login page
    router.route().handler(StaticHandler.create()::handle);
purplefox commented 9 years ago

Need to think about this some more ;)

vietj commented 9 years ago

ok :-) , I will try in Codetrans to rewrite handler argument to "handler.handle" meanwhile.

vietj commented 9 years ago

I've handled in in the codetrans project