fix should be getChildRoutes
fix fromNodeCallback returns array of values from callback fix remove require.ensure - needs to be tested
This commit is contained in:
@ -1,24 +1,12 @@
|
|||||||
import Rx from 'rx';
|
import Rx from 'rx';
|
||||||
import React from 'react';
|
import { Router } from 'react-router';
|
||||||
import { Route, Router } from 'react-router';
|
import App from './App.jsx';
|
||||||
|
|
||||||
// components
|
import childRoutes from './routes';
|
||||||
import { App } from './App.jsx';
|
|
||||||
import { Jobs } from './routes/Jobs';
|
|
||||||
import { NotFound } from './components/NotFound';
|
|
||||||
|
|
||||||
const router$ = Rx.Observable.fromNodeCallback(Router.run, Router);
|
const router$ = Rx.Observable.fromNodeCallback(Router.run, Router);
|
||||||
|
|
||||||
const routes = (
|
const routes = Object.assign({ components: App }, childRoutes);
|
||||||
<Route handler={ App }>
|
|
||||||
<Route
|
|
||||||
component={ Jobs }
|
|
||||||
path='/jobs' />
|
|
||||||
<Route
|
|
||||||
component={ NotFound }
|
|
||||||
path='*' />
|
|
||||||
</Route>
|
|
||||||
);
|
|
||||||
|
|
||||||
export default function app$(location) {
|
export default function app$(location) {
|
||||||
return router$(routes, location);
|
return router$(routes, location);
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import Jobs from './components/Jobs.jsx';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* show: /jobs
|
* show: /jobs
|
||||||
* showOne: /jobs/:id
|
* showOne: /jobs/:id
|
||||||
@ -8,12 +10,9 @@
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
path: '/jobs/(:jobId)',
|
path: '/jobs/(:jobId)',
|
||||||
|
|
||||||
getComponents(cb) {
|
getComponents(cb) {
|
||||||
require.ensure([], require => {
|
setTimeout(() => {
|
||||||
cb(null, [
|
cb(null, Jobs);
|
||||||
require('./components/Jobs.jsx')
|
}, 0);
|
||||||
]);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
18
common/app/routes/Mobile/components/Mobile.jsx
Normal file
18
common/app/routes/Mobile/components/Mobile.jsx
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import React, { PropTypes } from 'react';
|
||||||
|
|
||||||
|
export default React.createClass({
|
||||||
|
displayName: 'Mobile',
|
||||||
|
propTypes: {
|
||||||
|
id: PropTypes.string
|
||||||
|
},
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const {
|
||||||
|
id
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<h2>Hello { id }</h2>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
11
common/app/routes/Mobile/index.js
Normal file
11
common/app/routes/Mobile/index.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import Mobile from './components/Mobile.jsx';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
path: 'mobile',
|
||||||
|
|
||||||
|
getComponents(cb) {
|
||||||
|
setTimeout(() => {
|
||||||
|
cb(null, Mobile);
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
};
|
@ -1,11 +1,15 @@
|
|||||||
|
import jobRoute from './Jobs';
|
||||||
|
import mobileRoute from './Mobile';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
path: '/',
|
path: '/',
|
||||||
getRoutes(cb) {
|
getChildRoutes(locationState, cb) {
|
||||||
require.ensure([], require => {
|
setTimeout(() => {
|
||||||
cb(null, [
|
cb(null, [
|
||||||
// require('./Bonfires'),
|
// require('./Bonfires'),
|
||||||
require('./Jobs')
|
jobRoute,
|
||||||
|
mobileRoute
|
||||||
]);
|
]);
|
||||||
});
|
}, 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
12
gulpfile.js
12
gulpfile.js
@ -1,5 +1,6 @@
|
|||||||
require('babel-core/register');
|
require('babel-core/register');
|
||||||
var gulp = require('gulp'),
|
var Rx = require('rx'),
|
||||||
|
gulp = require('gulp'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
|
|
||||||
// utils
|
// utils
|
||||||
@ -30,6 +31,7 @@ var gulp = require('gulp'),
|
|||||||
eslint = require('gulp-eslint');
|
eslint = require('gulp-eslint');
|
||||||
|
|
||||||
|
|
||||||
|
Rx.longStackSupport = true;
|
||||||
var reloadDelay = 1000;
|
var reloadDelay = 1000;
|
||||||
var reload = sync.reload;
|
var reload = sync.reload;
|
||||||
var paths = {
|
var paths = {
|
||||||
@ -105,6 +107,12 @@ gulp.task('pack-client', function() {
|
|||||||
.pipe(gulp.dest(webpackConfig.output.path));
|
.pipe(gulp.dest(webpackConfig.output.path));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
gulp.task('pack-watch', function() {
|
||||||
|
return gulp.src(webpackConfig.entry)
|
||||||
|
.pipe(webpack(Object.assign(webpackConfig, { watch: true })))
|
||||||
|
.pipe(gulp.dest(webpackConfig.output.path));
|
||||||
|
});
|
||||||
|
|
||||||
gulp.task('pack-node', function() {
|
gulp.task('pack-node', function() {
|
||||||
return gulp.src(webpackConfigNode.entry)
|
return gulp.src(webpackConfigNode.entry)
|
||||||
.pipe(webpack(webpackConfigNode))
|
.pipe(webpack(webpackConfigNode))
|
||||||
@ -175,7 +183,7 @@ gulp.task('watch', ['less', 'serve', 'sync'], function() {
|
|||||||
gulp.watch('./public/css/*.less', ['less']);
|
gulp.watch('./public/css/*.less', ['less']);
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('default', ['less', 'serve', 'sync', 'watch']);
|
gulp.task('default', ['less', 'serve', 'sync', 'watch', 'pack-watch']);
|
||||||
|
|
||||||
function errorNotifier() {
|
function errorNotifier() {
|
||||||
var args = Array.prototype.slice.call(arguments);
|
var args = Array.prototype.slice.call(arguments);
|
||||||
|
@ -90,7 +90,7 @@
|
|||||||
"ramda": "~0.10.0",
|
"ramda": "~0.10.0",
|
||||||
"react": "^0.13.3",
|
"react": "^0.13.3",
|
||||||
"react-bootstrap": "^0.23.5",
|
"react-bootstrap": "^0.23.5",
|
||||||
"react-router": "^1.0.0-beta1",
|
"react-router": "^1.0.0-beta3",
|
||||||
"request": "~2.53.0",
|
"request": "~2.53.0",
|
||||||
"rx": "^2.5.3",
|
"rx": "^2.5.3",
|
||||||
"sanitize-html": "~1.6.1",
|
"sanitize-html": "~1.6.1",
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import Router from 'react-router';
|
||||||
|
import Location from 'react-router/lib/Location';
|
||||||
import debugFactory from 'debug';
|
import debugFactory from 'debug';
|
||||||
import { app$ } from '../../common/app';
|
import { app$ } from '../../common/app';
|
||||||
import { Cat } from 'thundercats';
|
import { Cat } from 'thundercats';
|
||||||
@ -7,7 +10,7 @@ const debug = debugFactory('freecc:servereact');
|
|||||||
// add routes here as they slowly get reactified
|
// add routes here as they slowly get reactified
|
||||||
// remove their individual controllers
|
// remove their individual controllers
|
||||||
const routes = [
|
const routes = [
|
||||||
'/jobs'
|
'/mobile'
|
||||||
];
|
];
|
||||||
|
|
||||||
export default function reactSubRouter(app) {
|
export default function reactSubRouter(app) {
|
||||||
@ -20,13 +23,15 @@ export default function reactSubRouter(app) {
|
|||||||
app.use(router);
|
app.use(router);
|
||||||
|
|
||||||
function serveReactApp(req, res, next) {
|
function serveReactApp(req, res, next) {
|
||||||
var fcc = new Cat();
|
const fcc = new Cat();
|
||||||
var decodedUrl = decodeURI(req.path);
|
const location = new Location(req.path, req.query)
|
||||||
|
|
||||||
// returns a router wrapped app
|
// returns a router wrapped app
|
||||||
app$(decodedUrl)
|
app$(location)
|
||||||
// if react-router does not find a route send down the chain
|
// if react-router does not find a route send down the chain
|
||||||
.filter(function(data) {
|
.filter(function(initialState) {
|
||||||
|
console.log('initialState', initialState);
|
||||||
|
/*
|
||||||
var state = data.state;
|
var state = data.state;
|
||||||
// this may not work with react-router 1.0.0
|
// this may not work with react-router 1.0.0
|
||||||
var notFound = state.routes.some(route => route.isNotFound);
|
var notFound = state.routes.some(route => route.isNotFound);
|
||||||
@ -35,19 +40,23 @@ export default function reactSubRouter(app) {
|
|||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
return !notFound;
|
return !notFound;
|
||||||
|
*/
|
||||||
|
return true;
|
||||||
})
|
})
|
||||||
.flatMap(function(app) {
|
.flatMap(function(initialState) {
|
||||||
// call thundercats renderToString
|
// call thundercats renderToString
|
||||||
// prefetches data and sets up it up for current state
|
// prefetches data and sets up it up for current state
|
||||||
return fcc.renderToString(app);
|
return fcc.renderToString(
|
||||||
|
React.createElement(Router, initialState[0])
|
||||||
|
);
|
||||||
})
|
})
|
||||||
// makes sure we only get one onNext and closes subscription
|
// makes sure we only get one onNext and closes subscription
|
||||||
.firstOrDefault()
|
.firstOrDefault()
|
||||||
.flatMap(function(dats) {
|
.flatMap(function({ data, markup }) {
|
||||||
debug('react rendered');
|
debug('react rendered');
|
||||||
res.expose(dats.data, 'data');
|
res.expose(data, 'data');
|
||||||
// now render jade file with markup injected from react
|
// now render jade file with markup injected from react
|
||||||
return res.render$('layout-react', { markup: dats.markup });
|
return res.render$('layout-react', { markup: markup });
|
||||||
})
|
})
|
||||||
.subscribe(
|
.subscribe(
|
||||||
function(markup) {
|
function(markup) {
|
||||||
|
Reference in New Issue
Block a user