mobx-state-tree icon indicating copy to clipboard operation
mobx-state-tree copied to clipboard

Use getTime() to check for Date equality

Open davetapley opened this issue 9 months ago • 8 comments

Bug report

A new snapshot is created for the same Date.getTime() but different Date object.

Sandbox link or minimal reproduction code

https://github.com/JEFuller/mobx-state-tree/blob/7d8c20321959e51a0607b4a524f407b400a7a92b/packages/mobx-state-tree/tests/core/date.test.ts#L47-L57

Describe the expected behavior

MobX-State-Tree is smart enough to know two Date are the same because:

  1. This is almost certainly what the user wants, and:

  2. The value in the JSONPatch is stored as the getTime() anyway (so, you can end up with multiple identical replace patches, which doesn't make sense semantically).

Describe the observed behavior

MobX-State-Tree creates a new snapshot every time.

davetapley avatar Sep 11 '23 23:09 davetapley