Skip to content

Commit

Permalink
Remove support for classes
Browse files Browse the repository at this point in the history
  • Loading branch information
luisherranz committed Sep 20, 2023
1 parent e6405ec commit 73a48c1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
6 changes: 1 addition & 5 deletions packages/deepsignal/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,7 @@ const wellKnownSymbols = new Set(
const supported = new Set([Object, Array]);
const shouldProxy = (val: any): boolean => {
if (typeof val !== "object" || val === null) return false;
const isBuiltIn =
typeof val.constructor === "function" &&
val.constructor.name in globalThis &&
(globalThis as any)[val.constructor.name] === val.constructor;
return (!isBuiltIn || supported.has(val.constructor)) && !ignore.has(val);
return supported.has(val.constructor) && !ignore.has(val);
};

/** TYPES **/
Expand Down
28 changes: 14 additions & 14 deletions packages/deepsignal/core/test/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -874,13 +874,20 @@ describe("deepsignal/core", () => {
});
});

describe("built-ins", () => {
it("should throw when trying to deepsignal a built-in", () => {
window.MyClass = class MyClass {};
const obj = new window.MyClass();
describe("unsupported data structures", () => {
it("should throw when trying to deepsignal a class instance", () => {
class MyClass {}
const obj = new MyClass();
expect(() => deepSignal(obj)).to.throw();
});

it("should not wrap a class instance", () => {
class MyClass {}
const obj = new MyClass();
const store = deepSignal({ obj });
expect(store.obj).to.equal(obj);
});

it("should not wrap built-ins in proxies", () => {
window.MyClass = class MyClass {};
const obj = new window.MyClass();
Expand All @@ -903,19 +910,19 @@ describe("deepsignal/core", () => {
expect(store.$b.value).to.equal(2);
});

it("should not wrap Date", () => {
it("should not wrap dates", () => {
const date = new Date();
const store = deepSignal({ date });
expect(store.date).to.equal(date);
});

it("should not wrap RegExp", () => {
it("should not wrap regular expressions", () => {
const regex = new RegExp("");
const store = deepSignal({ regex });
expect(store.regex).to.equal(regex);
});

it("should not wrap Maps", () => {
it("should not wrap Map", () => {
const map = new Map();
const store = deepSignal({ map });
expect(store.map).to.equal(map);
Expand All @@ -926,13 +933,6 @@ describe("deepsignal/core", () => {
const store = deepSignal({ set });
expect(store.set).to.equal(set);
});

it("should not wrap built-ins in proxies", () => {
window.MyClass = class MyClass {};
const obj = new window.MyClass();
const store = deepSignal({ obj });
expect(store.obj).to.equal(obj);
});
});

describe("symbols", () => {
Expand Down

0 comments on commit 73a48c1

Please sign in to comment.