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, app: app,
<%= (store ? 'store: context.store,' : '') %> <%= (store ? 'store: context.store,' : '') %>
route: (context.to ? context.to : context.route), route: (context.to ? context.to : context.route),
routePayload : context.routePayload, generatePayload : context.generatePayload,
error: context.error, error: context.error,
base: '<%= router.base %>', base: '<%= router.base %>',
env: <%= JSON.stringify(env) %> env: <%= JSON.stringify(env) %>

View File

@ -81,11 +81,13 @@ export default async function () {
} }
function decorateWithPayloads (routes) { function decorateWithPayloads (routes) {
let routeMap = _(routes).map((route) => { let routeMap = _(routes).map((route) => {
return [route, {route, routePayload: {}}] return [route, {route, payload: {}}]
}).fromPairs().value() }).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]) { if (!routeMap[route]) {
routeMap[route] = {route, routePayload} routeMap[route] = {route, payload: route.payload}
} }
}) })
return _.values(routeMap) return _.values(routeMap)
@ -97,11 +99,11 @@ export default async function () {
while (routes.length) { while (routes.length) {
let n = 0 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) await waitFor(n++ * this.options.generate.interval)
let html let html
try { try {
const res = await this.renderRoute(route, { _generate: true, routePayload }) const res = await this.renderRoute(route, { _generate: true, generatePayload: payload })
html = res.html html = res.html
if (res.error) { if (res.error) {
errors.push({ type: 'handled', route, error: res.error }) errors.push({ type: 'handled', route, error: res.error })

View File

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