Skip to content

Commit f07cb84

Browse files
authored
Refactor type validation logic for uniformity checks (#16493)
Ensure all input types are defined before checking for uniformity, improving the validation process for input types. Small fix for PR #16486
1 parent fa55b83 commit f07cb84

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

packages/dev/loaders/src/glTF/2.0/Extensions/KHR_interactivity/declarationMapper.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,8 @@ const gltfToFlowGraphMapping: { [key: string]: IGLTFToFlowGraphMapping } = {
389389
validation(gltfBlock) {
390390
// make sure types are the same
391391
if (gltfBlock.values) {
392-
const types = Object.keys(gltfBlock.values).map((key) => gltfBlock.values![key].type);
393-
const allSameType = types.every((type) => type === undefined || type === types[0]);
394-
if (!allSameType) {
395-
return { valid: false, error: "All inputs must be of the same type" };
396-
}
392+
// make sure types are the same
393+
return ValidateTypes(gltfBlock);
397394
}
398395
return { valid: true };
399396
},
@@ -1619,19 +1616,26 @@ function getSimpleInputMapping(type: FlowGraphBlockNames, inputs: string[] = ["a
16191616
validation(gltfBlock) {
16201617
if (inferType) {
16211618
// make sure types are the same
1622-
if (gltfBlock.values) {
1623-
const types = Object.keys(gltfBlock.values).map((key) => gltfBlock.values![key].type);
1624-
const allSameType = types.every((type) => type === undefined || type === types[0]);
1625-
if (!allSameType) {
1626-
return { valid: false, error: "All inputs must be of the same type" };
1627-
}
1628-
}
1619+
return ValidateTypes(gltfBlock);
16291620
}
16301621
return { valid: true };
16311622
},
16321623
};
16331624
}
16341625

1626+
function ValidateTypes(gltfBlock: IKHRInteractivity_Node): { valid: boolean; error?: string } {
1627+
if (gltfBlock.values) {
1628+
const types = Object.keys(gltfBlock.values)
1629+
.map((key) => gltfBlock.values![key].type)
1630+
.filter((type) => type !== undefined);
1631+
const allSameType = types.every((type) => type === types[0]);
1632+
if (!allSameType) {
1633+
return { valid: false, error: "All inputs must be of the same type" };
1634+
}
1635+
}
1636+
return { valid: true };
1637+
}
1638+
16351639
export function getAllSupportedNativeNodeTypes(): string[] {
16361640
return Object.keys(gltfToFlowGraphMapping);
16371641
}

0 commit comments

Comments
 (0)