Diffs data changes when we can't apply granular updates. Useful for when dealing with immutable data from stores or large API responses.
The key option is used when available to match items. By default the merge option false does referential checks where possible to determine equality and replaces where items are not referentially equal. merge true pushes all diffing to the leaves and effectively morphs the previous data to the new value.
12345
// subscribing to an observableconstunsubscribe=store.subscribe(({todos})=>(setState('todos',reconcile(todos))););onCleanup(()=>unsubscribe());
Creates a new mutable Store proxy object. Stores only trigger updates on values changing. Tracking is done by intercepting property access and automatically tracks deep nesting via proxy.
Useful for integrating external systems or as a compatibility layer with MobX/Vue.
1 2 3 4 5 6 7 8 91011121314
import{createMutable}from"solid-js/store";conststate=createMutable({someValue:0,list:[],});// read valuestate.someValue;// set valuestate.someValue=5;state.list.push(anotherValue);
This helper function simplifies making multiple changes to a mutable Store (as returned by createMutable) in a single batch, so that dependant computations update just once instead of once per update. The first argument is the mutable Store to modify, and the second argument is a Store modifier such as those returned by reconcile or produce. (If you pass in your own modifier function, beware that its argument is an unwrapped version of the Store.)
For example, suppose we have a UI depending on multiple fields of a mutable:
modifyMutable combined with reconcile or produce provides two alternate ways to do similar things:
1 2 3 4 5 6 7 8 910
import { modifyMutable, reconcile } from "solid-js/store";
// Replace state.user with the specified object (deleting any other fields)
modifyMutable(
state.user,
reconcile({
firstName: "Jane",
lastName: "Doe",
})
);
1 2 3 4 5 6 7 8 910
import { modifyMutable, produce } from "solid-js/store";
// Modify two fields in batch, triggering just one update
modifyMutable(
state,
produce((state) => {
state.user.firstName = "Jane";
state.user.lastName = "Doe";
})
);