From cb8ce8ac680a38af64bde57062f9e7dae079a9d0 Mon Sep 17 00:00:00 2001 From: Alexey Gurianov Date: Fri, 15 Jul 2016 12:17:21 +0400 Subject: [PATCH] refactor: use lodash.get to extract service --- index.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 45cad8d..865dda0 100644 --- a/index.js +++ b/index.js @@ -191,16 +191,9 @@ function Router (routesConfig, options) { } } -var getRouterServices = function (context) { - var modulePath = context[MODULE].path - return modulePath.reduce(function (services, key) { - return services[key] - }, context.services) -} - Router.redirect = function (url, params) { - function action (context) { - var services = getRouterServices(context) + function action (ctx) { + var services = get(ctx.services, ctx[MODULE].path) return services.redirect(url, params) }