refactor(client): add proper types to never[] (#9340)
This commit is contained in:
parent
af9034355c
commit
bb3d274db6
5 changed files with 78 additions and 28 deletions
|
|
@ -123,7 +123,7 @@ export function lessThan(xs: number[], ys: number[]): boolean {
|
|||
* Returns the longest prefix of elements that satisfy the predicate
|
||||
*/
|
||||
export function takeWhile<T>(f: Predicate<T>, xs: T[]): T[] {
|
||||
const ys = [];
|
||||
const ys: T[] = [];
|
||||
for (const x of xs) {
|
||||
if (f(x)) {
|
||||
ys.push(x);
|
||||
|
|
|
|||
|
|
@ -1,42 +1,62 @@
|
|||
export function collectPageVars(content) {
|
||||
const pageVars = [];
|
||||
const collect = (xs: any[]) => {
|
||||
interface StringPageVar {
|
||||
name: string,
|
||||
type: 'string',
|
||||
value: string
|
||||
}
|
||||
|
||||
interface NumberPageVar {
|
||||
name: string,
|
||||
type: 'number',
|
||||
value: number
|
||||
}
|
||||
|
||||
interface BooleanPageVar {
|
||||
name: string,
|
||||
type: 'boolean',
|
||||
value: boolean
|
||||
}
|
||||
|
||||
type PageVar = StringPageVar | NumberPageVar | BooleanPageVar;
|
||||
|
||||
export function collectPageVars(content): PageVar[] {
|
||||
const pageVars: PageVar[] = [];
|
||||
const collect = (xs: any[]): void => {
|
||||
for (const x of xs) {
|
||||
if (x.type === 'textInput') {
|
||||
pageVars.push({
|
||||
name: x.name,
|
||||
type: 'string',
|
||||
value: x.default || ''
|
||||
value: x.default || '',
|
||||
});
|
||||
} else if (x.type === 'textareaInput') {
|
||||
pageVars.push({
|
||||
name: x.name,
|
||||
type: 'string',
|
||||
value: x.default || ''
|
||||
value: x.default || '',
|
||||
});
|
||||
} else if (x.type === 'numberInput') {
|
||||
pageVars.push({
|
||||
name: x.name,
|
||||
type: 'number',
|
||||
value: x.default || 0
|
||||
value: x.default || 0,
|
||||
});
|
||||
} else if (x.type === 'switch') {
|
||||
pageVars.push({
|
||||
name: x.name,
|
||||
type: 'boolean',
|
||||
value: x.default || false
|
||||
value: x.default || false,
|
||||
});
|
||||
} else if (x.type === 'counter') {
|
||||
pageVars.push({
|
||||
name: x.name,
|
||||
type: 'number',
|
||||
value: 0
|
||||
value: 0,
|
||||
});
|
||||
} else if (x.type === 'radioButton') {
|
||||
pageVars.push({
|
||||
name: x.name,
|
||||
type: 'string',
|
||||
value: x.default || ''
|
||||
value: x.default || '',
|
||||
});
|
||||
} else if (x.children) {
|
||||
collect(x.children);
|
||||
|
|
|
|||
|
|
@ -55,13 +55,13 @@ export function physics(container: HTMLElement) {
|
|||
//wallLeft,
|
||||
]);
|
||||
|
||||
const objEls = Array.from(container.children);
|
||||
const objs = [];
|
||||
const objEls = Array.from(container.children) as HTMLElement[];
|
||||
const objs: Matter.Body[] = [];
|
||||
for (const objEl of objEls) {
|
||||
const left = objEl.dataset.physicsX ? parseInt(objEl.dataset.physicsX) : objEl.offsetLeft;
|
||||
const top = objEl.dataset.physicsY ? parseInt(objEl.dataset.physicsY) : objEl.offsetTop;
|
||||
|
||||
let obj;
|
||||
let obj: Matter.Body;
|
||||
if (objEl.classList.contains('_physics_circle_')) {
|
||||
obj = Matter.Bodies.circle(
|
||||
left + (objEl.offsetWidth / 2),
|
||||
|
|
@ -84,7 +84,7 @@ export function physics(container: HTMLElement) {
|
|||
}
|
||||
);
|
||||
}
|
||||
objEl.id = obj.id;
|
||||
objEl.id = obj.id.toString();
|
||||
objs.push(obj);
|
||||
}
|
||||
|
||||
|
|
@ -109,10 +109,10 @@ export function physics(container: HTMLElement) {
|
|||
render.mouse = mouse;
|
||||
|
||||
for (const objEl of objEls) {
|
||||
objEl.style.position = `absolute`;
|
||||
objEl.style.top = 0;
|
||||
objEl.style.left = 0;
|
||||
objEl.style.margin = 0;
|
||||
objEl.style.position = 'absolute';
|
||||
objEl.style.top = '0';
|
||||
objEl.style.left = '0';
|
||||
objEl.style.margin = '0';
|
||||
}
|
||||
|
||||
window.requestAnimationFrame(update);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue