fix bugs with checkMatchesObjectStructure
This commit is contained in:
@@ -8,6 +8,10 @@ export function checkMatchesObjectStructure(
|
||||
objectToCheck: any,
|
||||
reference: any
|
||||
): boolean {
|
||||
if (typeof reference != "object") {
|
||||
return typeof objectToCheck == typeof reference;
|
||||
}
|
||||
|
||||
for (const key of Object.keys(reference)) {
|
||||
const requiredType = typeof reference[key];
|
||||
const actualType = typeof objectToCheck[key];
|
||||
@@ -18,15 +22,17 @@ export function checkMatchesObjectStructure(
|
||||
if (objectToCheck[key].length == 0) continue;
|
||||
|
||||
// check first item of array
|
||||
const requiredType = typeof reference[key][0];
|
||||
const actualType = typeof objectToCheck[key][0];
|
||||
|
||||
if (requiredType != actualType) return false;
|
||||
// recurse into objects
|
||||
const doesFirstItemMatch = checkMatchesObjectStructure(
|
||||
objectToCheck[key][0],
|
||||
reference[key][0]
|
||||
);
|
||||
if (doesFirstItemMatch == false) return false;
|
||||
} else if (requiredType == "object") {
|
||||
// recurse into objects
|
||||
const doesNestedObjectMatch = checkMatchesObjectStructure(
|
||||
reference[key],
|
||||
objectToCheck[key]
|
||||
objectToCheck[key],
|
||||
reference[key]
|
||||
);
|
||||
if (doesNestedObjectMatch == false) return false;
|
||||
}
|
||||
|
||||
+1
-3
@@ -1,8 +1,6 @@
|
||||
import "./base.css";
|
||||
import "./colors.css";
|
||||
|
||||
import * as React from "bloatless-react";
|
||||
|
||||
import ChatListModel from "./Model/chatListModel";
|
||||
import ChatListViewModel from "./ViewModel/chatListViewModel";
|
||||
import { ChatPageWrapper } from "./View/chatPageWrapper";
|
||||
@@ -63,4 +61,4 @@ document
|
||||
ChatPageWrapper(chatListViewModel),
|
||||
ConnectionModal(connectionViewModel),
|
||||
StorageModal(storageViewModel)
|
||||
);
|
||||
);
|
||||
Reference in New Issue
Block a user