From 6411ee4e345e463b7ca85bbc686716d0516906c8 Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Thu, 23 Jun 2022 11:30:15 -0500 Subject: [PATCH] Replace isPlainObject --- package-lock.json | 44 ++++++++++++++++++++++++++++++-------------- package.json | 1 + src/game/player.ts | 8 ++------ src/util/common.ts | 4 ---- 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4b7d91e..fceff1b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "dependencies": { "@pixi/particle-emitter": "^5.0.4", "core-js": "^3.6.5", + "is-plain-object": "^5.0.0", "jest-environment-jsdom": "^28.1.1", "lodash.clonedeep": "^4.5.0", "lz-string": "^1.4.4", @@ -6053,6 +6054,18 @@ "node": ">=6" } }, + "node_modules/clone-deep/node_modules/is-plain-object": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz", + "integrity": "sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og==", + "dev": true, + "dependencies": { + "isobject": "^3.0.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/co": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", @@ -9173,13 +9186,9 @@ } }, "node_modules/is-plain-object": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz", - "integrity": "sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og==", - "dev": true, - "dependencies": { - "isobject": "^3.0.1" - }, + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.0.0.tgz", + "integrity": "sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==", "engines": { "node": ">=0.10.0" } @@ -21484,6 +21493,17 @@ "is-plain-object": "^2.0.4", "kind-of": "^6.0.2", "shallow-clone": "^3.0.0" + }, + "dependencies": { + "is-plain-object": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz", + "integrity": "sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og==", + "dev": true, + "requires": { + "isobject": "^3.0.1" + } + } } }, "co": { @@ -23777,13 +23797,9 @@ "dev": true }, "is-plain-object": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz", - "integrity": "sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og==", - "dev": true, - "requires": { - "isobject": "^3.0.1" - } + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.0.0.tgz", + "integrity": "sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==" }, "is-potential-custom-element-name": { "version": "1.0.1", diff --git a/package.json b/package.json index 9a54924..4cb6a6d 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "dependencies": { "@pixi/particle-emitter": "^5.0.4", "core-js": "^3.6.5", + "is-plain-object": "^5.0.0", "jest-environment-jsdom": "^28.1.1", "lodash.clonedeep": "^4.5.0", "lz-string": "^1.4.4", diff --git a/src/game/player.ts b/src/game/player.ts index f181b49..e6ed9d7 100644 --- a/src/game/player.ts +++ b/src/game/player.ts @@ -1,5 +1,5 @@ import Decimal from "util/bignum"; -import { isPlainObject } from "util/common"; +import { isPlainObject } from "is-plain-object"; import { ProxiedWithState, ProxyPath, ProxyState } from "util/proxies"; import { reactive, unref } from "vue"; import transientState from "./state"; @@ -51,11 +51,7 @@ const playerHandler: ProxyHandler> = { } const value = target[ProxyState][key]; - if ( - key !== "value" && - (isPlainObject(value) || Array.isArray(value)) && - !(value instanceof Decimal) - ) { + if (key !== "value" && (isPlainObject(value) || Array.isArray(value))) { if (value !== target[key]?.[ProxyState]) { const path = [...target[ProxyPath], key]; target[key] = new Proxy({ [ProxyState]: value, [ProxyPath]: path }, playerHandler); diff --git a/src/util/common.ts b/src/util/common.ts index 3a7d217..0e4f829 100644 --- a/src/util/common.ts +++ b/src/util/common.ts @@ -8,10 +8,6 @@ export function camelToTitle(camel: string): string { return title; } -export function isPlainObject(object: unknown): boolean { - return Object.prototype.toString.call(object) === "[object Object]"; -} - // eslint-disable-next-line @typescript-eslint/ban-types export function isFunction(func: unknown): func is Function { return typeof func === "function";