all repos — archive/homestead @ be533ddc740c77551c714836da08a651b81825b6

My future indieweb platform

refactor: assign responders to actions via front controller

Alan Pearce
commit

be533ddc740c77551c714836da08a651b81825b6

parent

f1dabb589af4cfaf15d04ff7c399f8a9a2d5223a

1 file changed, 16 insertions(+), 9 deletions(-)

changed files
M src/actions.jssrc/actions.js
@@ -3,19 +3,22 @@
const fs = require("fs"); const path = require("path"); const send = require("koa-send"); -const responders = require("./responders"); -function home(config, posts) { +function home(config, responder, posts) { const postsArray = Array.from(posts.values()); return async function(ctx, next) { - responders.home(ctx, config, postsArray); + responder(ctx, config, { posts: postsArray }); }; } -function posts(config, posts) { +function posts(config, responder, posts) { const postsArray = Array.from(posts.values()); return async function(ctx, next) { - responders.list(ctx, config, null, "Posts", postsArray); + responder(ctx, config, { + listType: null, + listName: "Posts", + posts: postsArray + }); }; }
@@ -38,23 +41,27 @@ ctx.body = css;
}; } -function post(config, posts) { +function post(config, responder, posts) { return async function(ctx, next) { ctx.assert(posts.has(ctx.params.filename), 404, "Post not found"); const post = posts.get(ctx.params.filename); - responders.post(ctx, config, post); + responder(ctx, config, { post }); }; } -function taxonGenerator(config, term, items) { +function taxonGenerator(config, responder, term, items) { return async function(ctx, next) { const value = ctx.params.value; ctx.assert(items.has(ctx.params.value), 404, `${term} ${value} not found`); const taxonItems = items.get(value); - responders.list(ctx, config, term, value, taxonItems); + responder(ctx, config, { + listType: term, + listName: value, + posts: taxonItems + }); }; }