Skip to content

Commit 607feea

Browse files
committed
add custom validations
1 parent da93e3c commit 607feea

File tree

4 files changed

+11
-30
lines changed

4 files changed

+11
-30
lines changed

src-runtime/customValidations.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* @type {Function[]}
3+
*/
4+
const customValidations = [];
5+
export {customValidations};

src-runtime/index.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from './assertType.mjs';
22
export * from './createDiv.mjs';
3+
export * from './customValidations.mjs';
34
export * from './makeJSDoc.mjs';
45
export * from './registerClass.mjs';
56
export * from './registerTypedef.mjs';

src-runtime/typecheckOptions.mjs

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,9 @@ const typecheckOptions = {
1212
warned: {},
1313
logSuperfluousProperty: false,
1414
/**
15-
* @todo integrate PC/Transformers Examples browser + custom config for each project
15+
* @type {Record<string, (value: any) => boolean>}
1616
*/
17-
customTypes: {
18-
AnimSetter(value) {
19-
//console.log("@todo Is AnimSetter?", value);
20-
return true;
21-
},
22-
AnimBinder(value) {
23-
//console.log("@todo Is AnimBinder?", value);
24-
return true;
25-
},
26-
AnimCurvePath(value) {
27-
//console.log("@todo Is AnimCurvePath?", value);
28-
return true;
29-
},
30-
ComponentData(value) {
31-
//console.log("@todo Is ComponentData?", value);
32-
return true;
33-
},
34-
Renderer(value) {
35-
// E.g. instance of `ForwardRenderer`
36-
//debugger;
37-
return value?.constructor?.name?.endsWith("Renderer");
38-
},
39-
IArguments(value) {
40-
//console.log("@todo Is IArguments?", value);
41-
return true;
42-
},
43-
// @todo validate textures having width != 0 and height != 0
44-
// @todo validate integers
45-
},
17+
customTypes: {},
4618
count: 0,
4719
};
4820
function typecheckReport() {

src-runtime/validateType.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ function validateType(value, expect, loc, name, critical = true) {
7676
return false;
7777
}
7878
}
79+
for (const customValidation of customValidations) {
80+
customValidation(value, expect, loc, name, critical);
81+
}
7982
if (typeof window !== 'undefined' && window.pc) {
8083
const {pc} = window;
8184
/**

0 commit comments

Comments
 (0)