Skip to content
This repository has been archived by the owner on Jan 22, 2020. It is now read-only.

Commit

Permalink
Merge pull request #77 from samsel/issues
Browse files Browse the repository at this point in the history
resolve cache clear logic based on the 'view cache' and other readme updates
  • Loading branch information
vuhwang committed Aug 21, 2015
2 parents 71ac271 + ad56651 commit 8026e5b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
## 2.0.0 (TBD)
## 2.1.0 (Aug 20 2015)

* resolve cache clear logic based on the 'view cache' (https://github.com/paypal/react-engine/issues/74)
* updated readme with migration to v2.x notes (https://github.com/paypal/react-engine/issues/75)
* updated readme references of Isomorphic JavaScript to Universal JavaScript (https://github.com/paypal/react-engine/issues/60)

## 2.0.0 (Aug 1 2015)

* Major API changes (specifically the options object property name changes)
* React-Router config properties can be passed through the react engine now.
Expand Down
27 changes: 17 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
[![Build Status](https://travis-ci.org/paypal/react-engine.svg?branch=master)](https://travis-ci.org/paypal/react-engine)

### What is react-engine?
* a composite render engine for express apps to render both plain react views and react-router views on server
* a react render engine for [Universal](https://medium.com/@mjackson/universal-javascript-4761051b7ae9) (previously [Isomorphic](http://nerds.airbnb.com/isomorphic-javascript-future-web-apps/)) JavaScript apps written with express
* renders both plain react views and react-router views
* enables server rendered views to be client mountable


Expand Down Expand Up @@ -72,12 +73,12 @@
Pass in an optional JavaScript object as options to the react-engine's [server engine create method](#setup-in-an-express-app).
The options object can contain properties from [react router's create configuration object](http://rackt.github.io/react-router/#Router.create).

Additionally, it can contain the following optional properties,
Additionally, it can contain the following optional properties,

- `performanceCollector`: <function> - to collects [perf stats](#performance-profiling)
- `routesFilePath`: <string> - path for the file that contains the react router routes.
react-engine used this behind the scenes to reload the routes file in
development mode, this way you don't need to restart the server every time a change is made in the view files or routes file.
react-engine uses this behind the scenes to reload the routes file in
cases where [express's app property](http://expressjs.com/api.html#app.set) `view cache` is false, this way you don't need to restart the server every time a change is made in the view files or routes file.

###### Rendering views on server side
```js
Expand Down Expand Up @@ -109,7 +110,7 @@ document.addEventListener('DOMContentLoaded', function onLoad() {
});
};

// if the data is needed before booting on
// if the data is needed before booting on
// client, call `data` function anytime to get it.
// example:
var data = client.data();
Expand All @@ -119,18 +120,18 @@ var data = client.data();
Pass in a JavaScript object as options to the react-engine's client boot function.
The options object can contain properties from [react router's create configuration object](http://rackt.github.io/react-router/#Router.create).
Additionally, it should contain the following `required` property,
Additionally, it should contain the following `required` property,
- `viewResolver` : <function> - a function that react-engine needs to resolve the view file.
an example of the viewResolver can be [found here](https://github.com/paypal/react-engine/blob/ecd27b30a9028d3f02b8f8e89d355bb5fc909de9/examples/simple/public/index.js#L29).
### Yeoman Generator
There is a Yeoman generator available to create a new express or KrakenJS application which uses react-engine:
There is a Yeoman generator available to create a new express or KrakenJS application which uses react-engine:
[generator-react-engine](https://www.npmjs.com/package/generator-react-engine).
### Performance Profiling
Pass in a function to the `performanceCollector` property to collect the `stats`
Pass in a function to the `performanceCollector` property to collect the `stats`
object for every render.
##### `stats`
Expand All @@ -153,12 +154,18 @@ var engine = require('react-engine').server.create({
});
```
### Notes
* On the client side, the state is exposed on the window object's property `__REACT_ENGINE__`
* In development mode, views are automatically reloaded before render. So there is no need to restart the server for seeing the changes.
* When Express's `view cache` app property is false (mostly in non-production environments), views are automatically reloaded before render. So there is no need to restart the server for seeing the changes.
* You can use `js` as the engine if you decide not to write your react views in `jsx`.
* [Blog on react-engine](https://www.paypal-engineering.com/2015/04/27/isomorphic-react-apps-with-react-engine/)
### Migration from 1.x to 2.x
2.x version of react-engine brought in a major api change. Basically it affects the property names of the [object that gets passed in during the engine creation](https://github.com/paypal/react-engine#server-options-spec) on the server side and also how routes definition is passed into react-engine.
In v2.x, `routes` need to be explicitly required and passed in to the engine creation method. Also, any [react-router known properties can be passed in](http://rackt.github.io/react-router/#Router.create).
An example engine creation can be found [here](https://github.com/paypal/react-engine/blob/71ac27196e72059484332a491cd66982797a60a3/examples/complex/index.js#L28).
### License
[Apache Software License v2.0](http://www.apache.org/licenses/LICENSE-2.0)
6 changes: 3 additions & 3 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ exports.create = function create(createOptions) {
}

function done(err, html) {
if (options.settings.env === 'development') {
if (!options.settings['view cache']) {
// remove all the files under the express's view folder from require cache.
// Helps in making changes to react views without restarting the server.
util.clearRequireCache(createOptions.routesFilePath);
Expand All @@ -70,8 +70,8 @@ exports.create = function create(createOptions) {
}

if (createOptions.routes && createOptions.routesFilePath) {
// if `routesFilePath` property is provided, in
// development env the routes are reloaded for every render.
// if `routesFilePath` property is provided, then in
// cases where 'view cache' is false, the routes are reloaded for every render.
createOptions.routes = require(createOptions.routesFilePath);
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-engine",
"version": "2.0.0",
"version": "2.1.0",
"description": "a composite render engine for express apps to render both plain react views and react-router views",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 8026e5b

Please sign in to comment.