From 9c3179b4b766fabf832152f7037410fbba6ffb6a Mon Sep 17 00:00:00 2001 From: Cole Lawrence Date: Tue, 19 Apr 2022 15:27:03 -0400 Subject: [PATCH] questions, cleaning, fix _sanitizeRgba undefined --- theatre/core/src/propTypes/index.ts | 16 +++++----------- theatre/core/src/propTypes/internals.ts | 2 ++ 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/theatre/core/src/propTypes/index.ts b/theatre/core/src/propTypes/index.ts index 3f07be4..80b5a8b 100644 --- a/theatre/core/src/propTypes/index.ts +++ b/theatre/core/src/propTypes/index.ts @@ -14,8 +14,7 @@ import type { IValidCompoundProps, ShorthandCompoundPropsToLonghandCompoundProps, } from './internals' -import {sanitizeCompoundProps} from './internals' -import {propTypeSymbol} from './internals' +import {propTypeSymbol, sanitizeCompoundProps} from './internals' // eslint-disable-next-line unused-imports/no-unused-imports import type SheetObject from '@theatre/core/sheetObjects/SheetObject' @@ -91,9 +90,7 @@ const validateCommonOpts = (fnCallSignature: string, opts?: CommonOpts) => { */ export const compound = ( props: Props, - opts: { - label?: string - } = {}, + opts: CommonOpts = {}, ): PropTypeConfig_Compound< ShorthandCompoundPropsToLonghandCompoundProps > => { @@ -287,9 +284,7 @@ const _interpolateNumber = ( export const rgba = ( defaultValue: Rgba = {r: 0, g: 0, b: 0, a: 1}, - opts: { - label?: string - } = {}, + opts: CommonOpts = {}, ): PropTypeConfig_Rgba => { if (process.env.NODE_ENV !== 'production') { validateCommonOpts('t.rgba(defaultValue, opts)', opts) @@ -337,6 +332,7 @@ export const rgba = ( } const _sanitizeRgba = (val: unknown): Rgba | undefined => { + if (!val) return undefined let valid = true for (const c of ['r', 'g', 'b', 'a']) { if ( @@ -555,8 +551,6 @@ export function stringLiteral< } } -export type Sanitizer = (value: unknown) => T | undefined - /** * A linear interpolator for a certain value type. * @@ -669,7 +663,7 @@ const defaultNumberNudgeFn: NumberNudgeFn = ({ export interface PropTypeConfig_Boolean extends ISimplePropType<'boolean', boolean> {} -interface CommonOpts { +type CommonOpts = { /** * Each prop type may be given a custom label instead of the name of the sub-prop * it is in. diff --git a/theatre/core/src/propTypes/internals.ts b/theatre/core/src/propTypes/internals.ts index 125cc45..61f062f 100644 --- a/theatre/core/src/propTypes/internals.ts +++ b/theatre/core/src/propTypes/internals.ts @@ -17,6 +17,8 @@ export type IValidCompoundProps = { [K in string]: PropTypeConfig } +// Question: Why doesn't this include Rgba? Should it include Marker? +// - Is this just for compound props? type IShorthandProp = | string | number