From 73592aca3597214db1e9b7a44ed56915eb930f38 Mon Sep 17 00:00:00 2001 From: Manuel Penaloza Date: Thu, 18 Oct 2018 09:16:16 +0200 Subject: [PATCH] use closures with preserved names as option handler functions this pr aims to simplify this file in terms of: - no need to actively declare new functions `state` gets passed to - no need to pass through `state` down the runtime chain --- src/utils/options.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/utils/options.js b/src/utils/options.js index 5c319cd..4d91e26 100644 --- a/src/utils/options.js +++ b/src/utils/options.js @@ -1,14 +1,12 @@ -function getOption({ opts }, name, defaultValue = true) { +const getOption = (name, defaultValue = true) => ({ opts }) => { return opts[name] === undefined || opts[name] === null ? defaultValue - : opts[name] + : opts[name] } -export const useDisplayName = state => getOption(state, 'displayName') -export const useSSR = state => getOption(state, 'ssr', true) -export const useFileName = state => getOption(state, 'fileName') -export const useMinify = state => getOption(state, 'minify') -export const useTranspileTemplateLiterals = state => - getOption(state, 'transpileTemplateLiterals') - -export const usePureAnnotation = state => getOption(state, 'pure', false) +export const useDisplayName = getOption('displayName'); +export const useSSR = getOption('ssr', true); +export const useFileName = getOption('fileName'); +export const useMinify = getOption('minify'); +export const useTranspileTemplateLiterals = getOption('transpileTemplateLiterals'); +export const usePureAnnotation = getOption('pure', false);