[add] Upgrade ThunderCats react

This commit is contained in:
Berkeley Martinez
2015-12-22 19:28:07 -08:00
parent 1799322661
commit cec243b032
3 changed files with 24 additions and 20 deletions

View File

@@ -6,7 +6,7 @@ import debugFactory from 'debug';
import { Router } from 'react-router'; import { Router } from 'react-router';
import { createLocation, createHistory } from 'history'; import { createLocation, createHistory } from 'history';
import { hydrate } from 'thundercats'; import { hydrate } from 'thundercats';
import { Render } from 'thundercats-react'; import { render$ } from 'thundercats-react';
import { app$ } from '../common/app'; import { app$ } from '../common/app';
@@ -72,7 +72,7 @@ app$({ history, location: appLocation })
}) })
.flatMap(({ props, appCat }) => { .flatMap(({ props, appCat }) => {
props.history = history; props.history = history;
return Render( return render$(
appCat, appCat,
React.createElement(Router, props), React.createElement(Router, props),
DOMContianer DOMContianer

View File

@@ -115,9 +115,10 @@
"rx": "^4.0.0", "rx": "^4.0.0",
"sanitize-html": "^1.11.1", "sanitize-html": "^1.11.1",
"sort-keys": "^1.1.1", "sort-keys": "^1.1.1",
"stampit": "^2.1.1",
"store": "https://github.com/berkeleytrue/store.js.git#feature/noop-server", "store": "https://github.com/berkeleytrue/store.js.git#feature/noop-server",
"thundercats": "^3.0.0", "thundercats": "^3.1.0",
"thundercats-react": "~0.4.0", "thundercats-react": "~0.5.1",
"twit": "^2.1.1", "twit": "^2.1.1",
"uglify-js": "^2.5.0", "uglify-js": "^2.5.0",
"url-regex": "^3.0.0", "url-regex": "^3.0.0",

View File

@@ -3,8 +3,10 @@ import { RoutingContext } from 'react-router';
import Fetchr from 'fetchr'; import Fetchr from 'fetchr';
import { createLocation } from 'history'; import { createLocation } from 'history';
import debugFactory from 'debug'; import debugFactory from 'debug';
import { dehydrate } from 'thundercats';
import { renderToString$ } from 'thundercats-react';
import { app$ } from '../../common/app'; import { app$ } from '../../common/app';
import { RenderToString } from 'thundercats-react';
const debug = debugFactory('freecc:react-server'); const debug = debugFactory('freecc:react-server');
@@ -12,14 +14,13 @@ const debug = debugFactory('freecc:react-server');
// remove their individual controllers // remove their individual controllers
const routes = [ const routes = [
'/jobs', '/jobs',
'/jobs/*' '/jobs/*',
];
const devRoutes = [
'/hikes', '/hikes',
'/hikes/*' '/hikes/*'
]; ];
const devRoutes = [];
export default function reactSubRouter(app) { export default function reactSubRouter(app) {
var router = app.loopback.Router(); var router = app.loopback.Router();
@@ -51,20 +52,22 @@ export default function reactSubRouter(app) {
return !!props; return !!props;
}) })
.flatMap(function({ props, AppCat }) { .flatMap(function({ props, AppCat }) {
// call thundercats renderToString const cat = AppCat(null, services);
// prefetches data and sets up it up for current state debug('render react markup and pre-fetch data');
debug('rendering to string'); return renderToString$(
return RenderToString( cat,
AppCat(null, services),
React.createElement(RoutingContext, props) React.createElement(RoutingContext, props)
); )
.flatMap(
dehydrate(cat),
({ markup }, data) => ({ markup, data, cat })
);
}) })
// makes sure we only get one onNext and closes subscription .flatMap(function({ data, markup, cat }) {
.flatMap(function({ data, markup }) { debug('react markup rendered, data fetched');
debug('react rendered'); cat.dispose();
const { title } = data.AppStore; const { title } = data.AppStore;
res.expose(data, 'data'); res.expose(data, 'data');
// now render jade file with markup injected from react
return res.render$( return res.render$(
'layout-react', 'layout-react',
{ markup, title } { markup, title }
@@ -72,7 +75,7 @@ export default function reactSubRouter(app) {
}) })
.subscribe( .subscribe(
function(markup) { function(markup) {
debug('jade rendered'); debug('html rendered and ready to send');
res.send(markup); res.send(markup);
}, },
next next