@npio/internals
Version:
A free visual website editor, powered with your own SolidJS components.
23 lines (19 loc) • 715 B
text/typescript
import { startTransition } from "solid-js";
import { produce, reconcile, SetStoreFunction } from "solid-js/store";
export const modernizeSetStore = <T>(setter: SetStoreFunction<T>) => {
function modernSetStore(fn: T, transition?: boolean): void;
function modernSetStore(fn: (s: T) => void, transition?: boolean): void;
function modernSetStore(fn: T | ((s: T) => void), transition?: boolean) {
if (!transition) {
return typeof fn === "function"
? setter(produce(fn as any))
: setter(reconcile(fn));
}
startTransition(() => {
return typeof fn === "function"
? setter(produce(fn as any))
: setter(reconcile(fn));
});
}
return modernSetStore;
};