@dxos/echo-atom 0.8.4-main.1068cf700f → 0.8.4-main.2244d791bb

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/echo-atom",
3
- "version": "0.8.4-main.1068cf700f",
3
+ "version": "0.8.4-main.2244d791bb",
4
4
  "description": "Effect Atom wrappers for ECHO objects with explicit subscriptions.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -30,16 +30,16 @@
30
30
  "dependencies": {
31
31
  "@effect-atom/atom": "^0.5.1",
32
32
  "lodash.isequal": "^4.5.0",
33
- "@dxos/echo-db": "0.8.4-main.1068cf700f",
34
- "@dxos/echo": "0.8.4-main.1068cf700f",
35
- "@dxos/util": "0.8.4-main.1068cf700f",
36
- "@dxos/invariant": "0.8.4-main.1068cf700f"
33
+ "@dxos/echo": "0.8.4-main.2244d791bb",
34
+ "@dxos/echo-db": "0.8.4-main.2244d791bb",
35
+ "@dxos/invariant": "0.8.4-main.2244d791bb",
36
+ "@dxos/util": "0.8.4-main.2244d791bb"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/lodash.isequal": "^4.5.0",
40
40
  "effect": "3.19.16",
41
- "@dxos/random": "0.8.4-main.1068cf700f",
42
- "@dxos/test-utils": "0.8.4-main.1068cf700f"
41
+ "@dxos/test-utils": "0.8.4-main.2244d791bb",
42
+ "@dxos/random": "0.8.4-main.2244d791bb"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "effect": "3.19.16"
package/src/atom.ts CHANGED
@@ -7,7 +7,6 @@ import * as Result from '@effect-atom/atom/Result';
7
7
  import * as Effect from 'effect/Effect';
8
8
  import * as Function from 'effect/Function';
9
9
  import * as Option from 'effect/Option';
10
- import isEqual from 'lodash.isequal';
11
10
 
12
11
  import { Obj, Ref } from '@dxos/echo';
13
12
  import { assertArgument } from '@dxos/invariant';
@@ -84,7 +83,7 @@ const propertyFamily = Atom.family(<T extends Obj.Unknown>(obj: T) =>
84
83
 
85
84
  const unsubscribe = Obj.subscribe(obj, () => {
86
85
  const newValue = obj[key];
87
- if (!isEqual(previousSnapshot, newValue)) {
86
+ if (previousSnapshot !== newValue) {
88
87
  previousSnapshot = snapshotForComparison(newValue);
89
88
  // Return a snapshot copy so React sees a new reference.
90
89
  get.setSelf(snapshotForComparison(newValue));
@@ -8,6 +8,7 @@ import { describe, expect, test } from 'vitest';
8
8
  import { Obj } from '@dxos/echo';
9
9
  import { TestSchema } from '@dxos/echo/testing';
10
10
  import { createObject } from '@dxos/echo-db';
11
+ import { arrayMove } from '@dxos/util';
11
12
 
12
13
  import * as AtomObj from './atom';
13
14
 
@@ -203,4 +204,30 @@ describe('Echo Atom - Reactivity', () => {
203
204
 
204
205
  unsubscribe();
205
206
  });
207
+
208
+ test('property atom for array property updates when array is reordered in place', () => {
209
+ // Verifies that makeProperty(obj, 'columns')-style atoms subscribe to in-place
210
+ // array mutations (e.g. arrayMove), so UI stays in sync after column reorder.
211
+ const obj = createObject(Obj.make(TestSchema.Example, { stringArray: ['a', 'b', 'c'] }));
212
+
213
+ const registry = Registry.make();
214
+ const atom = AtomObj.makeProperty(obj, 'stringArray');
215
+
216
+ const initial = registry.get(atom);
217
+ expect(initial).toEqual(['a', 'b', 'c']);
218
+
219
+ let updateCount = 0;
220
+ registry.subscribe(atom, () => {
221
+ updateCount++;
222
+ });
223
+
224
+ // Reorder in place (e.g. move first to last).
225
+ Obj.change(obj, (obj) => {
226
+ arrayMove(obj.stringArray!, 0, 2);
227
+ });
228
+
229
+ expect(updateCount).toBe(1);
230
+ const afterReorder = registry.get(atom);
231
+ expect(afterReorder).toEqual(['b', 'c', 'a']);
232
+ });
206
233
  });