Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use closures with preserved names as option handler functions #171

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 8 additions & 10 deletions src/utils/options.js
Original file line number Diff line number Diff line change
@@ -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);