Skip to content

Commit

Permalink
added documentation for express-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
warmuuh committed Apr 5, 2013
1 parent c0909c4 commit c3ad218
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -8,6 +8,7 @@ See [Readme](yaap) for more information.
There are also two examples for server and client scenario: There are also two examples for server and client scenario:


* On [Node](node-example) * On [Node](node-example)
* With [Express.js] [Node](express-example)
* In [Browser](browser-example) * In [Browser](browser-example)




Expand Down
22 changes: 22 additions & 0 deletions yaap/README.md
Expand Up @@ -6,6 +6,8 @@ Yaap is a generic annotation processor for javascript. It can be used to impleme
It [integrates](#wirejs-integration) with [wire.js](https://github.com/cujojs/wire) (part of [cujo.js](http://cujojs.com)), which enables Spring-style wiring (i.e. dependency injection) of your javascript applications. It [integrates](#wirejs-integration) with [wire.js](https://github.com/cujojs/wire) (part of [cujo.js](http://cujojs.com)), which enables Spring-style wiring (i.e. dependency injection) of your javascript applications.
With the `yaap/wire` plugin, @Autowired applications are possible With the `yaap/wire` plugin, @Autowired applications are possible


It also [integrates](#expressjs-integration) with Express.js to achieve a SpringMVC-style framework for webapps.

`Remark:` This is an experimentational library and should not be used in production. `Remark:` This is an experimentational library and should not be used in production.


An overview of out-of-the-box supported annotations is available [here](docs/annotations.md) An overview of out-of-the-box supported annotations is available [here](docs/annotations.md)
Expand All @@ -17,6 +19,7 @@ Installation for node: `npm install yaap`


* [Annotations for JavaScript](http://cubiccow.blogspot.com/2013/02/yaap-annotations-for-javascript.html) * [Annotations for JavaScript](http://cubiccow.blogspot.com/2013/02/yaap-annotations-for-javascript.html)
* [@Autowired for JavaScript](http://cubiccow.blogspot.de/2013/02/autowire-for-javascript.html) * [@Autowired for JavaScript](http://cubiccow.blogspot.de/2013/02/autowire-for-javascript.html)
* [Express.js the SpringMVC-way](http://cubiccow.blogspot.com/2013/04/expressjs-springmvc-way.html)


##Example ##Example


Expand Down Expand Up @@ -115,3 +118,22 @@ module.exports = {
The yaap/wire plugin will be called after the bean was created. That means, the constructor itself will not be affected by annotations. The yaap/wire plugin will be called after the bean was created. That means, the constructor itself will not be affected by annotations.


As a workaround, use a separate initialize-method (using the [init-facade](https://github.com/cujojs/wire/blob/master/docs/configure.md#init-methods) of wire). As a workaround, use a separate initialize-method (using the [init-facade](https://github.com/cujojs/wire/blob/master/docs/configure.md#init-methods) of wire).

##Express.js integration
There are also out-of-the-box annotations included for creating webapps in a springMVC-like manner. A simple example of a service:

```js
MyService.prototype = {
index: function ()/*@GET*/ {
return 'index';
},

submit: function (name, age)/*@POST @Param*/ {
var msg = (age < 18)? "You are too young" : "You are welcome!";
return {view:'greet', model:{name: name, msg: msg}};
}
};
```
As known from SpringMVC, the returned values determine, which view will be called and with what parameters.
More details on this in my [blogpost](http://cubiccow.blogspot.com/2013/02/autowire-for-javascript.html).

13 changes: 12 additions & 1 deletion yaap/docs/annotations.md
Expand Up @@ -23,11 +23,22 @@ Some annotations can only be used on parameters while others can also be used at
* `@PreDestroy` (function): the annotated function will be called, if context.destroy() is called. * `@PreDestroy` (function): the annotated function will be called, if context.destroy() is called.


###browser-specific wire annotations ###browser-specific wire annotations
for these annotations, you need to add the additional `yaao/wire/html`-plugin! for these annotations, you need to add the additional `yaap/wire/html`-plugin! (as shown in the browser-example)


* `@On(<refName>, <event>)` (function): the annotated function will automatically be bound the the event of the given dom-node. * `@On(<refName>, <event>)` (function): the annotated function will automatically be bound the the event of the given dom-node.
This is intended to be used with the `wire/dom`-plugin. <refName> can reference one or more elements in the dom (though This is intended to be used with the `wire/dom`-plugin. <refName> can reference one or more elements in the dom (though
it is probably better practice to reference a bean in the wirecontext, which itself references the dom-nodes). it is probably better practice to reference a bean in the wirecontext, which itself references the dom-nodes).
For example, you could bind a clickhandler with this annotation: `@On("dom.all!.btn","click")`. For example, you could bind a clickhandler with this annotation: `@On("dom.all!.btn","click")`.
The annotated method accepts one argument that is the event (though you could add additional @autowired arguments, if you want) The annotated method accepts one argument that is the event (though you could add additional @autowired arguments, if you want)


###Node-Specific wire-annotations (Express.js)
for these annotations, you need to add the additional `yaap/wire/express`-plugin! (and you need to feed the express-application into the plugin as shown in the express-example)

* `@GET/POST/PUT/DELETE([<pathspec>])` (function): registeres the function as an endpoint in an express-application with either the given path
or the functionname as path, if omitted.
* `@Param([<name>])` (parameter/function): fetches the annotated parameter from the query/path/post parameters.
If annotation is on function-level, all parameters (except `@Body`-annotated parameters) are injected by-name.
* `@Body` (parameter/function): if parameter-level, then the request-body will be injected. If on function-level,
it states that the return-value will be returned as-is (Just like @ResponseBody does in SpringMVC).
* `@JSON` (function): states, that the returned value will be send as response in json-format. (using [response.json](http://expressjs.com/api.html#res.json)).
*

0 comments on commit c3ad218

Please sign in to comment.