diff --git a/CHANGELOG.md b/CHANGELOG.md index ad49862..2c86513 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/README.md b/README.md index bc2fa3e..5833793 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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`: - to collects [perf stats](#performance-profiling) - `routesFilePath`: - 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 @@ -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(); @@ -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` : - 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` @@ -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) diff --git a/lib/server.js b/lib/server.js index f180570..aba82b5 100644 --- a/lib/server.js +++ b/lib/server.js @@ -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); @@ -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); } diff --git a/package.json b/package.json index 3c0bf5d..cda66d4 100644 --- a/package.json +++ b/package.json @@ -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": {