renamed routePayload to payload and generatePayload in the context object. added backwards compatability with string-only routes.

This commit is contained in:
Johan Roxendal 2017-05-24 11:32:17 +02:00
parent 64e7cab8fa
commit b2d5186e39
3 changed files with 11 additions and 9 deletions

View File

@ -61,7 +61,7 @@ export function getContext (context, app) {
app: app,
<%= (store ? 'store: context.store,' : '') %>
route: (context.to ? context.to : context.route),
routePayload : context.routePayload,
generatePayload : context.generatePayload,
error: context.error,
base: '<%= router.base %>',
env: <%= JSON.stringify(env) %>

View File

@ -81,11 +81,13 @@ export default async function () {
}
function decorateWithPayloads (routes) {
let routeMap = _(routes).map((route) => {
return [route, {route, routePayload: {}}]
return [route, {route, payload: {}}]
}).fromPairs().value()
generateRoutes.forEach(({route, routePayload}) => {
generateRoutes.forEach((route) => {
// route argument is either a string or like {route : "/my_route/1"}
route = _.isString(route) ? route : route.route
if (!routeMap[route]) {
routeMap[route] = {route, routePayload}
routeMap[route] = {route, payload: route.payload}
}
})
return _.values(routeMap)
@ -97,11 +99,11 @@ export default async function () {
while (routes.length) {
let n = 0
await Promise.all(routes.splice(0, 500).map(async ({route, routePayload}) => {
await Promise.all(routes.splice(0, 500).map(async ({route, payload}) => {
await waitFor(n++ * this.options.generate.interval)
let html
try {
const res = await this.renderRoute(route, { _generate: true, routePayload })
const res = await this.renderRoute(route, { _generate: true, generatePayload: payload })
html = res.html
if (res.error) {
errors.push({ type: 'handled', route, error: res.error })

View File

@ -1,9 +1,9 @@
module.exports = {
generate: {
routes: [
{route: '/users/1'},
{route: '/users/2'},
{route: '/users/3'}
'/users/1',
'/users/2',
'/users/3'
],
interval: 200
}