Skip to content

Commit

Permalink
[#393] Exports ServerSsrContext type
Browse files Browse the repository at this point in the history
  • Loading branch information
birdofpreyru committed Oct 13, 2024
1 parent 87fd790 commit abea9a3
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 2 deletions.
2 changes: 2 additions & 0 deletions __tests__/type-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import {
type BeforeRenderResT,
type BeforeRenderT,
type ConfigT,
type ServerSsrContext,
type ServerT,
} from '../src';

test('type exports', () => {
expect<BeforeRenderResT>().type.toBe<BeforeRenderResT>();
expect<BeforeRenderT>().type.toBe<BeforeRenderT>();
expect<ConfigT>().type.toBe<ConfigT>();
expect<ServerSsrContext<unknown>>().type.toBe<ServerSsrContext<unknown>>();
expect<ServerT>().type.toBe<ServerT>();
});
35 changes: 35 additions & 0 deletions docs/docs/api/classes/ServerSsrContext.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# ServerSsrContext
[ServerSsrContext]: /docs/api/classes/ServerSsrContext
```tsx
import { ServerSsrContext } from '@dr.pogodin/react-utils';
```

The [ServerSsrContext] class extends
[SsrContext](https://dr.pogodin.studio/docs/react-global-state/docs/api/classes/ssrcontext)
class from the
[React Global State](https://dr.pogodin.studio/docs/react-global-state)
library; it is used by React Utils [server()](/docs/api/functions/server)
factory as a part of SSR setup.

## Generic Parameters
- `StateT` &mdash; The type of global state object.

## Properties
- `chunkGroups` &mdash; **ChunkGroupsT**
- `chunks` &mdash; **string[]** &mdash; Defaults empty array.
- `req` &mdash; **Request** &mdash; ExpressJS request being handled.
- `status` &mdash; **number** &mdash; HTTP status for the response.
Defaults 200 (OK).

## Methods

### constructor()
```tsx
constructor(req: Request, chunkGroups: ChunkGroupsT, initialState?: StateT)
```
Creates a new [ServerSsrContext] instance.

**Arguments**
- `res` &mdash; **Request**
- `chunkGroups` &mdash; **ChunkGroupsT**
- `initialState` &mdash; **StateT** &mdash; Optional. Initial global state value.
2 changes: 2 additions & 0 deletions docs/docs/api/classes/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
execution of Webpack-built code.
- [Emitter](/docs/api/classes/Emitter) - Simple listeneable data emitter.
- [Semaphore](/docs/api/classes/Semaphore) - Synchronization primitive.
- [ServerSsrContext](/docs/api/classes/ServerSsrContext) &mdash;
SSR context class being used by the library.

<!-- Link -->
[Barrier]: /docs/api/classes/Barrier
Expand Down
2 changes: 1 addition & 1 deletion docs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export {
type BeforeRenderResT,
type BeforeRenderT,
type ConfigT,
type ServerSsrContext,
type ServerT,
} from './server';

Expand Down
1 change: 1 addition & 0 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export {
type BeforeRenderResT,
type BeforeRenderT,
type ConfigT,
type ServerSsrContext,
} from './renderer';

export { errors, getDefaultCspSettings, type ServerT };
Expand Down
2 changes: 1 addition & 1 deletion src/server/renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export enum SCRIPT_LOCATIONS {
HEAD_OPEN = 'HEAD_OPEN',
}

class ServerSsrContext<StateT>
export class ServerSsrContext<StateT>
extends SsrContext<StateT>
implements SsrContextT<StateT> {
chunkGroups: ChunkGroupsT;
Expand Down

0 comments on commit abea9a3

Please sign in to comment.