SolidJSS
SolidJS2y ago
6 replies
skrebbel

captureStoreUpdates vs reconcile

Hi!

I'm trying to get a stream of immutable object values from a store. The store is frequently updated from a data source that sends big chunky records with minimal actual changes, so I use reconcile to keep the amount of signalled changes to a minimum. This works very well, but the captureStoreUpdates primitive from https://primitives.solidjs.community/package/deep somehow doesn't play ball and I can't figure out why not.

  const [state, setState] = createStore({ foo: { dummy: "a", count: 1 } });
  const increment = () =>
    setState(
      reconcile(
        { foo: { dummy: "a", count: state.foo.count + 1 } },
        { merge: true },
      ),
    );

  const getDelta = captureStoreUpdates(state as any);
  createEffect(() => {
    const delta = getDelta();

    // after an increment(), i'd expect to get:
    //       [{path: ["foo", "count"], value: 2}]
    // but i get the entire reconciled value:
    //       [{path: ["foo"], value: {dummy: "a", count: 2}}]
    console.log("delta:", delta);
  });


Full playground example: https://playground.solidjs.com/anonymous/f5d92603-c66c-4d00-82ba-9cce9ca452fe

Is there any way to get captureStoreUpdates to only see the data that actually changed, post reconcile, and to not have it assume that the entire object changed?
Was this page helpful?