pmlopes / yoke

Yoke is a middleware framework for Vert.x
http://pmlopes.github.io/yoke/
Apache License 2.0
157 stars 44 forks source link

Fix some bugs and add some new features in js binding #116

Closed XiaochunLU closed 10 years ago

XiaochunLU commented 10 years ago

One of our prototype projects is using Yoke javascript as the frontend framework, but find its js binding is rudimentary as compared to the Java implementation. Still we think it could fulfill our need as long as some minor changes be made to it. Now our prototype is finished, and we think our changes could contribute back to Yoke.

Bugs or features that are fixed or added: a. In JSYokeRequest, createSession and destroySession should be function instead of property b. Create a shortcut to get response from request, so that you can write:

router.get('/hello', function(req) {
  req.res.end('Yoke');
});

c. Make it possible to pass native JSON to session or response.end(), such as:

router.get('/hello', function(req) {
  req.session.mydata = {
    foo: ['bar']
  };
  req.res.end({
    success: true,
    data: {
      foo: ['bar']
    }
  });
});

d. Add implementation for TODO tasks in JSUtil. Now use Rhino Context.javaToJS() to convert java object to js one e. Make session object save to store only when it is changed. A new com.jetdrone.vertx.yoke.store.json.SessionObject is added, a wrapper around the existing JsonObject, and it is aware of changes of its fields or field of fields. This is because most of the time the session object is retrieved but not changed, and saving to external store such as redis or mongodb would have performance impact.

pmlopes commented 10 years ago

Thank you very much, indeed the JS bindings have been getting less priority from my side due to the fact that:

1) my current projects are either java or groovy 2) lack of time 3) not really having a good idea on where to go Rhino/Nashorn (although Nashorm requires Java8 but Vert.x does not require it... so i still guess Rhino is here to stay for a while...)

If you are planning to support Nashorn i will be gladly open to any pull request, sugestions like this one :+1: