@dksolid/solid-globals
v1.0.0
Published
Layered architecture for Solid.js
Downloads
15
Readme
solid-globals
I CURRENTLY WRITE THIS DOCUMENTATION, IT'S NOT READY YET
This library is intended to be used in SSR projects with a layered architecture. For SPA it's not helpful because you can directly import all the layers where needed as Singletones. But in SSR the only way to configure DI is to use a context. So, this library helps with that.
Setup (SSR)
This example is based on the documentation of @dksolid/solid-router. But you may use any routing library that supports async loaded page chunks.
The setup consists of two parts:
- TypeGlobals: TS-model which describes global and modular layers
- Global object: an object representing TypeGlobals
- Install
@dksolid/solid-globals,dk-localizeanddk-request - Create
models/TypeGlobals.ts
import { getLn } from 'dk-localize';
import { TypeGlobalsGenerator } from '@dksolid/solid-globals';
import { RouterStore } from '../stores/routerStore';
export type TypeGlobals = TypeGlobalsGenerator<
any,
{ routerStore: typeof RouterStore },
any,
any,
any,
typeof getLn
>;- Create
globals.ts
import { createContextProps } from '@dksolid/solid-globals';
import { RouterStore } from './stores/routerStore';
import { TypeGlobals } from './models/TypeGlobals';
const globals = createContextProps<TypeGlobals>({
api: {},
request: () => Promise.resolve(),
staticStores: { routerStore: RouterStore },
apiValidators: {},
globalActions: {},
});
export { globals };