diff --git a/theatre/core/src/propTypes/index.ts b/theatre/core/src/propTypes/index.ts index 897a0df..746e6e2 100644 --- a/theatre/core/src/propTypes/index.ts +++ b/theatre/core/src/propTypes/index.ts @@ -109,7 +109,7 @@ export const compound = ( [propTypeSymbol]: 'TheatrePropType', label: opts.label, default: mapValues(sanitizedProps, (p) => p.default) as $IntentionalAny, - deserialize: (json: unknown) => { + deserializeAndSanitize: (json: unknown) => { if (typeof json !== 'object' || !json) return undefined if (deserializationCache.has(json)) { return deserializationCache.get(json) @@ -123,7 +123,7 @@ export const compound = ( let atLeastOnePropWasDeserialized = false for (const [key, propConfig] of Object.entries(sanitizedProps)) { if (Object.prototype.hasOwnProperty.call(json, key)) { - const deserializedSub = propConfig.deserialize( + const deserializedSub = propConfig.deserializeAndSanitize( (json as $IntentionalAny)[key] as unknown, ) if (deserializedSub != null) { @@ -262,7 +262,7 @@ export const number = ( nudgeMultiplier: typeof opts.nudgeMultiplier === 'number' ? opts.nudgeMultiplier : 1, interpolate: _interpolateNumber, - deserialize: numberDeserializer(opts.range), + deserializeAndSanitize: numberDeserializer(opts.range), } } @@ -332,7 +332,7 @@ export const rgba = ( [propTypeSymbol]: 'TheatrePropType', label: opts.label, interpolate: _interpolateRgba, - deserialize: _sanitizeRgba, + deserializeAndSanitize: _sanitizeRgba, } } @@ -426,7 +426,7 @@ export const boolean = ( [propTypeSymbol]: 'TheatrePropType', label: opts.label, interpolate: opts.interpolate ?? leftInterpolate, - deserialize: _ensureBoolean, + deserializeAndSanitize: _ensureBoolean, } } @@ -483,7 +483,7 @@ export const string = ( [propTypeSymbol]: 'TheatrePropType', label: opts.label, interpolate: opts.interpolate ?? leftInterpolate, - deserialize: _ensureString, + deserializeAndSanitize: _ensureString, } } @@ -540,7 +540,9 @@ export function stringLiteral( as: opts.as ?? 'menu', label: opts.label, interpolate: opts.interpolate ?? leftInterpolate, - deserialize(json: unknown): undefined | Extract { + deserializeAndSanitize( + json: unknown, + ): undefined | Extract { if (typeof json !== 'string') return undefined if (Object.prototype.hasOwnProperty.call(options, json)) { return json as $IntentionalAny @@ -584,13 +586,13 @@ export interface IBasePropType< label: string | undefined default: ValueType /** - * Each prop config has a `deserialize()` function that deserializes + * Each prop config has a `deserializeAndSanitize()` function that deserializes and sanitizes * any js value into one that is acceptable by this prop config, or `undefined`. * * The `DeserializeType` is usually equal to `ValueType`. That is the case with * all simple prop configs, such as `number`, `string`, or `rgba`. However, composite - * configs such as `compound` or `enum` may deserialize into a partial value. For example, - * a prop config of `t.compound({x: t.number(0), y: t.number(0)})` may deserialize into `{x: 10}`. + * configs such as `compound` or `enum` may deserialize+sanitize into a partial value. For example, + * a prop config of `t.compound({x: t.number(0), y: t.number(0)})` may deserialize+sanitize into `{x: 10}`. * This behavior is used by {@link SheetObject.getValues} to replace the missing sub-props * with their default value. * @@ -601,7 +603,7 @@ export interface IBasePropType< * Additionally, returning an `undefined` allows {@link SheetObject.getValues} to * replace the `undefined` with the default value of that prop. */ - deserialize: (json: unknown) => undefined | DeserializeType + deserializeAndSanitize: (json: unknown) => undefined | DeserializeType } interface ISimplePropType diff --git a/theatre/core/src/sequences/interpolationTripleAtPosition.ts b/theatre/core/src/sequences/interpolationTripleAtPosition.ts index 109676b..dd663c4 100644 --- a/theatre/core/src/sequences/interpolationTripleAtPosition.ts +++ b/theatre/core/src/sequences/interpolationTripleAtPosition.ts @@ -19,7 +19,7 @@ export type InterpolationTriple = { // low-hanging fruit for perf optimization. // It can be improved by: // 1. Not creating a new InterpolationTriple object on every change -// 2. Caching propConfig.deserialize(value) +// 2. Caching propConfig.deserializeAndSanitize(value) export default function interpolationTripleAtPosition( trackP: Pointer, diff --git a/theatre/core/src/sheetObjects/SheetObject.ts b/theatre/core/src/sheetObjects/SheetObject.ts index 5bdd738..4fc7689 100644 --- a/theatre/core/src/sheetObjects/SheetObject.ts +++ b/theatre/core/src/sheetObjects/SheetObject.ts @@ -152,7 +152,7 @@ export default class SheetObject implements IdentityDerivationProvider { pathToProp, )! as Extract - const deserialize = propConfig.deserialize + const deserializeAndSanitize = propConfig.deserializeAndSanitize const interpolate = propConfig.interpolate! as Interpolator<$IntentionalAny> @@ -161,7 +161,7 @@ export default class SheetObject implements IdentityDerivationProvider { if (!triple) return valsAtom.setIn(pathToProp, undefined) - const leftDeserialized = deserialize(triple.left) + const leftDeserialized = deserializeAndSanitize(triple.left) const left = typeof leftDeserialized === 'undefined' @@ -171,7 +171,7 @@ export default class SheetObject implements IdentityDerivationProvider { if (triple.right === undefined) return valsAtom.setIn(pathToProp, left) - const rightDeserialized = deserialize(triple.right) + const rightDeserialized = deserializeAndSanitize(triple.right) const right = typeof rightDeserialized === 'undefined' ? propConfig.default diff --git a/theatre/core/src/sheetObjects/SheetObjectTemplate.ts b/theatre/core/src/sheetObjects/SheetObjectTemplate.ts index 9261b0c..0ee0f0d 100644 --- a/theatre/core/src/sheetObjects/SheetObjectTemplate.ts +++ b/theatre/core/src/sheetObjects/SheetObjectTemplate.ts @@ -102,7 +102,7 @@ export default class SheetObjectTemplate { ) || {} const config = val(this._config.pointer) - const deserialized = config.deserialize(json) || {} + const deserialized = config.deserializeAndSanitize(json) || {} return deserialized }), ) diff --git a/theatre/shared/src/propTypes/utils.ts b/theatre/shared/src/propTypes/utils.ts index 26e4c03..3731b27 100644 --- a/theatre/shared/src/propTypes/utils.ts +++ b/theatre/shared/src/propTypes/utils.ts @@ -43,9 +43,7 @@ export function valueInProp( ): PropConfig extends IBasePropType<$IntentionalAny, $IntentionalAny, infer T> ? T : never { - const deserialize = propConfig.deserialize - - const sanitizedVal = deserialize(value) + const sanitizedVal = propConfig.deserializeAndSanitize(value) if (typeof sanitizedVal === 'undefined') { return propConfig.default } else { diff --git a/theatre/studio/src/StudioStore/createTransactionPrivateApi.ts b/theatre/studio/src/StudioStore/createTransactionPrivateApi.ts index b41b519..8fd5303 100644 --- a/theatre/studio/src/StudioStore/createTransactionPrivateApi.ts +++ b/theatre/studio/src/StudioStore/createTransactionPrivateApi.ts @@ -105,7 +105,7 @@ export default function createTransactionPrivateApi( } const deserialized = cloneDeepSerializable( - propConfig.deserialize(value), + propConfig.deserializeAndSanitize(value), ) if (typeof deserialized === 'undefined') { throw new Error(