Skip to content

Commit

Permalink
Merge pull request #114 from chunkerchunker/master
Browse files Browse the repository at this point in the history
bugfix: passing Date proxy to Date constructor
  • Loading branch information
giusepperaso authored Jul 14, 2024
2 parents ecc4b86 + 0d6dc1a commit ec0a72d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/proxy/proxyHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ export class CreateProxyHandler {
}
if (type === Types.Date) {
if (typeof v === Types.function) {
if ((p as string).indexOf(Methods.set) === 0) {
if ((p !== Symbol.toPrimitive) && (
(typeof p === 'symbol' && Symbol.keyFor(p)?.indexOf(Methods.set) === 0) ||
((p as string).indexOf(Methods.set) === 0)
)) {
return function (...args: unknown[]) {
walkParents(state, Actions.set_date, data, pStore, t, p, args);
return r;
Expand Down
2 changes: 2 additions & 0 deletions src/tests/integration/basics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ runMultiple("tests all(most) of the basic types", () => {
const result = produce(myDate, (draft) => {
draft.a.setSeconds(draft.a.getSeconds() + 1);
draft.a.setSeconds(draft.a.getSeconds() + 1);

expect((new Date(draft.a)).toString()).toBe(draft.a.toString()); // compare to the second, since the constructor will drop milliseconds
});

expect(myDate.a.getTime()).not.toBe(result.a.getTime());
Expand Down

0 comments on commit ec0a72d

Please sign in to comment.