Skip to content

Commit

Permalink
style: 🚨 fix all the linter warnings!
Browse files Browse the repository at this point in the history
  • Loading branch information
meisZWFLZ committed Dec 18, 2023
1 parent bf56048 commit 149d258
Showing 1 changed file with 2 additions and 75 deletions.
77 changes: 2 additions & 75 deletions src/VexDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,23 +119,6 @@ export async function sleep(ms: number): Promise<unknown> {
return await new Promise((resolve) => setTimeout(resolve, ms));
}

function shallowEqual(object1: object, object2: object): boolean {
const keys1 = Object.keys(object1);
const keys2 = Object.keys(object2);
if (keys1.length !== keys2.length) {
return false;
}
for (const key of keys1) {
if (
object1[key as keyof typeof object1] !==
object2[key as keyof typeof object2]
) {
return false;
}
}
return true;
}

export abstract class VexSerialDevice extends VexEventTarget {
connection: V5SerialConnection | undefined;
defaultSerial: Serial;
Expand All @@ -160,58 +143,6 @@ export abstract class VexSerialDevice extends VexEventTarget {
abstract disconnect(): void;
}

class V5SerialDeviceProxyHandler implements ProxyHandler<V5SerialDeviceState> {
constructor(
protected device?: V5SerialDevice,
protected parent?: V5SerialDeviceProxyHandler,
protected rootkey?: keyof V5SerialDeviceState,
) {}

get(target: V5SerialDeviceState, key: keyof V5SerialDeviceState): unknown {
if (
typeof target[key] === "object" &&
target[key] !== null &&
(typeof key !== "string" ? true : !key.startsWith("_"))
) {
return new Proxy(
target[key],
new V5SerialDeviceProxyHandler(this.device, this, key),
);
} else {
return target[key];
}
}

set<K extends keyof V5SerialDeviceState>(
target: V5SerialDeviceState,
key: K,
value: V5SerialDeviceState[K],
): boolean {
const oldValue = target[key];
if (oldValue === value) {
return true;
} else if (
typeof oldValue === "object" &&
typeof value === "object" &&
oldValue !== null &&
value !== null
) {
if (shallowEqual(oldValue, value)) return true;
}
target[key] = value;

this.parent?.childSet(this.rootkey, key, value);

return true;
}

childSet(rootkey: string | undefined, subkey: string, value: any): void {
if (this.parent)
this.parent.childSet(this.rootkey, rootkey + "." + subkey, value);
else console.log("changed", rootkey + "." + subkey, value); // TODO
}
}

class V5SerialDeviceState {
_instance: V5SerialDevice;
_isFileTransferring = false;
Expand Down Expand Up @@ -903,11 +834,7 @@ export class V5SerialDevice extends VexSerialDevice {
pauseRefreshOnFileTransfer = true;

protected _isReconnecting = false;
protected proxy = new V5SerialDeviceProxyHandler(this);
state = new Proxy<V5SerialDeviceState>(
new V5SerialDeviceState(this),
this.proxy,
);
state: V5SerialDeviceState = new V5SerialDeviceState(this);

constructor(defaultSerial: Serial) {
super(defaultSerial);
Expand Down Expand Up @@ -1095,7 +1022,7 @@ export class V5SerialDevice extends VexSerialDevice {

if (!this.isConnected) return false;

this.doAfterConnect();
void this.doAfterConnect();

return true;
}
Expand Down

0 comments on commit 149d258

Please sign in to comment.