Browse Source

PD.ValuesFor

David Sehnal 5 years ago
parent
commit
7b5dc3ef96

+ 2 - 2
src/mol-plugin-state/helpers/structure-component.ts

@@ -39,10 +39,10 @@ export const StructureComponentParams = {
         bundle: PD.Value<StructureElement.Bundle>(StructureElement.Bundle.Empty),
         script: PD.Script({ language: 'mol-script', expression: '(sel.atom.all)' }),
     }, { isHidden: true }),
-    nullIfEmpty: PD.Boolean(true, { isHidden: true }),
+    nullIfEmpty: PD.Optional(PD.Boolean(true, { isHidden: true })),
     label: PD.Text('', { isHidden: true })
 };
-export type StructureComponentParams = PD.Values<typeof StructureComponentParams>
+export type StructureComponentParams = PD.ValuesFor<typeof StructureComponentParams>
 
 export function createStructureComponent(a: Structure, params: StructureComponentParams, cache: { source: Structure, entry?: StructureQueryHelper.CacheEntry }) {
     cache.source = a;

+ 7 - 0
src/mol-util/param-definition.ts

@@ -279,6 +279,8 @@ export namespace ParamDefinition {
 
     export type Params = { [k: string]: Any }
     export type Values<T extends Params> = { [k in keyof T]: T[k]['defaultValue'] }
+    /** This is required for params with optional values */
+    export type ValuesFor<T extends For<any>> = Normalize<{ [k in keyof T]: T[k]['defaultValue'] }>
 
     type Optionals<P> = { [K in keyof P]-?: undefined extends P[K] ? K : never }[keyof P]
     type NonOptionals<P> = { [K in keyof P]-?: undefined extends P[K] ? never: K }[keyof P]
@@ -286,6 +288,11 @@ export namespace ParamDefinition {
     export type For<P> = { [K in keyof P]-?: Base<P[K]> }
     export type Def<P> = { [K in keyof P]: Any }
 
+
+    export function For<P>(params: For<P>): For<P> {
+        return 0 as any;
+    }
+
     export function getDefaultValues<T extends Params>(params: T) {
         const d: { [k: string]: any } = {}
         for (const k of Object.keys(params)) {