@tanstack/solid-router
Version:
Modern and scalable routing for Solid applications
40 lines • 1.28 kB
JavaScript
import * as Solid from 'solid-js';
import { createNonReactiveMutableStore, createNonReactiveReadonlyStore, } from '@tanstack/router-core';
import { isServer } from '@tanstack/router-core/isServer';
function createSolidMutableStore(initialValue) {
const [signal, setSignal] = Solid.createSignal(initialValue);
return { get: signal, set: setSignal };
}
function createSolidReadonlyStore(read) {
return { get: Solid.createRoot(() => Solid.createMemo(read)) };
}
export const getStoreFactory = (opts) => {
if (isServer ?? opts.isServer) {
return {
createMutableStore: createNonReactiveMutableStore,
createReadonlyStore: createNonReactiveReadonlyStore,
batch: (fn) => fn(),
};
}
let depth = 0;
return {
createMutableStore: createSolidMutableStore,
createReadonlyStore: createSolidReadonlyStore,
batch: (fn) => {
depth++;
try {
fn();
}
finally {
depth--;
if (depth === 0) {
try {
Solid.flush();
}
catch { }
}
}
},
};
};
//# sourceMappingURL=routerStores.js.map