diff options
author | Alan Pearce | 2017-07-08 22:30:36 +0200 |
---|---|---|
committer | Alan Pearce | 2017-07-08 22:30:36 +0200 |
commit | be533ddc740c77551c714836da08a651b81825b6 (patch) | |
tree | a0ec9e5d4d3f14f0b6afaa3d0f8a84e02d9c1cf7 /src/actions.js | |
parent | f1dabb589af4cfaf15d04ff7c399f8a9a2d5223a (diff) | |
download | homestead-be533ddc740c77551c714836da08a651b81825b6.tar.lz homestead-be533ddc740c77551c714836da08a651b81825b6.tar.zst homestead-be533ddc740c77551c714836da08a651b81825b6.zip |
refactor: assign responders to actions via front controller
Diffstat (limited to 'src/actions.js')
-rw-r--r-- | src/actions.js | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/actions.js b/src/actions.js index e6d7f98..2ad0c77 100644 --- a/src/actions.js +++ b/src/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 @@ function highlightTheme(config) { }; } -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 + }); }; } |