reactjs/React.NET — pull request #11 by prabirshrestha (2014-04-08 05:38:04+00:00)
Title: Nancy view engine for ReactJS

//cc @nancyfx

very basic PR based on https://gist.github.com/prabirshrestha/10028584 and https://gist.github.com/prabirshrestha/10028584

* [x] Nancy.ViewEngines.React.dll
* [ ] Nancy.ViewEngines.React nuget package
* [x] nancy react view engine sample
* [ ] cache jsx transforms
* [ ] proper common js module support (`require` should use the view locator). see #9 CJS doesn't seem popular in .NET community. should we support AMD too?
* [ ] unit tests
* [ ] customize extensions? currently supports `jsx` and `js` (@phillip-haydon didn't seem to like js extension. should we only support jsx by default?)
* [ ] xml comments
* [ ] docs
* [ ] nancy wiki docs?
* [x] auto prepend `` as reactjs doesn't support it.
* [ ] create `ReactResponse` which is similar to Nancy's `HtmlResponse` with a flag to disallow prepending doctype. (useful if devs want to render html fragments on the server) `Get["/docs"] = _ => new ReactResponse("docs") { PrependDoctype = false };`
* [ ] mono/v8/linux/mac support?

Just add reference to `Nancy.ViewEngines.React.dll` and let Nancy do the magic of auto registering the view engine. When we publish the nuget package should be as easy as `Install-Package Nancy.ViewEngines.React`.

Here is a sample. `Model` is passed as props to reactjs. `ViewBags` are ignored. What should we do with `ViewBags` prefix the key with `_`?

```c#
Get["/"] = _ => View["home"];

Get["/hi"] = _ => View["hi", new { name = Request.Query.name.Value }];
```

`module.exports` is defined by the ViewEngine before transforming. `require` isn't supported yet (need better commonjs support for this - see #9). ViewEngine will render the exported component. This is a workaround to render the component without knowing the variable name.

```js
/** @jsx React.DOM */

var Hi = React.createClass({
render: function () {
return (

Hi {this.props.name}

)
}
});

module.exports = Hi;
```

Since Nancy View Engine only cares about the core `React.dll` would love to see it not having dependency on `System.Web`. see #10

@Daniel15 this is a very early alpha release code just to get the discussion started. Feel free to comment on anything.

Once the core `React.dll` is stable should we move `Nancy.ViewEngines.React` to the core Nancy project like other view engines? https://github.com/NancyFx/Nancy/tree/master/src