Skip to content

Commit 06edd17

Browse files
committed
docs: title code blocks by their project files
1 parent 5e4d571 commit 06edd17

18 files changed

Lines changed: 79 additions & 81 deletions

todo.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
- tweak colors on the website
22
- no-magic-numbers pain
3-
- correct sandbox for session example
43
- inspect object copies
54
- check === / !== undefined ? perf
6-
- complete guide
75

86
## Agera/Kida/Store
97

website/src/content/docs/articles/april-update.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ For React apps, [`@nano_kit/react-ssr`](/integrations/react-ssr) is the main new
1515

1616
In practice, the setup starts with the plugin:
1717

18-
```js
18+
```js title="vite.config.js"
1919
import ssr from '@nano_kit/react-ssr/vite-plugin'
2020

2121
export default {
@@ -58,7 +58,7 @@ For production, it does not generate a complete HTTP server. You bring your own
5858

5959
For example, a small Hono server can look like this:
6060

61-
```js
61+
```js title="src/server.js"
6262
import { serve } from '@hono/node-server'
6363
import { serveStatic } from '@hono/node-server/serve-static'
6464
import { Hono } from 'hono'

website/src/content/docs/integrations/preact-ssr.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ The SSR plugin can provide request-bound browser-like dependencies for stores th
118118

119119
Use `inject.cookieStore: true` when the renderer should provide a request-bound `CookieStore$` during SSR. This feature uses the optional peer package `@nano_kit/platform-web`, so install it in the app before enabling the option. See [SSR Cookies](/ssr/cookies) for the full setup, including store code and `Set-Cookie` forwarding.
120120

121-
```js
121+
```js title="vite.config.js"
122122
ssr({
123123
index: 'src/index.tsx',
124124
inject: {
@@ -131,7 +131,7 @@ ssr({
131131

132132
Use `inject.browserLocale: true` when the renderer should provide request-bound `Locales$` during SSR. This feature uses the optional peer package `@nano_kit/platform-web`, so install it in the app before enabling the option. The renderer parses the incoming `Accept-Language` header with [`parseLocales`](/platform/web/#locale), so universal stores can inject `Locales$` and resolve the same locale shape on the server and in the browser. See [SSR Locale](/ssr/locale) for the full setup.
133133

134-
```js
134+
```js title="vite.config.js"
135135
ssr({
136136
index: 'src/index.tsx',
137137
inject: {
@@ -144,7 +144,7 @@ ssr({
144144

145145
Use `inject.userAgent: true` when the renderer should provide request-bound `UserAgent$` during SSR. This feature uses the optional peer package `@nano_kit/platform-web`, so install it in the app before enabling the option. The renderer reads the incoming `User-Agent` header, so universal stores can inject `UserAgent$` and read a user agent string on the server and in the browser.
146146

147-
```js
147+
```js title="vite.config.js"
148148
ssr({
149149
index: 'src/index.tsx',
150150
inject: {

website/src/content/docs/integrations/react-ssr.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ The SSR plugin can provide request-bound browser-like dependencies for stores th
118118

119119
Use `inject.cookieStore: true` when the renderer should provide a request-bound `CookieStore$` during SSR. This feature uses the optional peer package `@nano_kit/platform-web`, so install it in the app before enabling the option. See [SSR Cookies](/ssr/cookies) for the full setup, including store code and `Set-Cookie` forwarding.
120120

121-
```js
121+
```js title="vite.config.js"
122122
ssr({
123123
index: 'src/index.ts',
124124
inject: {
@@ -131,7 +131,7 @@ ssr({
131131

132132
Use `inject.browserLocale: true` when the renderer should provide request-bound `Locales$` during SSR. This feature uses the optional peer package `@nano_kit/platform-web`, so install it in the app before enabling the option. The renderer parses the incoming `Accept-Language` header with [`parseLocales`](/platform/web/#locale), so universal stores can inject `Locales$` and resolve the same locale shape on the server and in the browser. See [SSR Locale](/ssr/locale) for the full setup.
133133

134-
```js
134+
```js title="vite.config.js"
135135
ssr({
136136
index: 'src/index.ts',
137137
inject: {
@@ -144,7 +144,7 @@ ssr({
144144

145145
Use `inject.userAgent: true` when the renderer should provide request-bound `UserAgent$` during SSR. This feature uses the optional peer package `@nano_kit/platform-web`, so install it in the app before enabling the option. The renderer reads the incoming `User-Agent` header, so universal stores can inject `UserAgent$` and read a user agent string on the server and in the browser.
146146

147-
```js
147+
```js title="vite.config.js"
148148
ssr({
149149
index: 'src/index.ts',
150150
inject: {

website/src/content/docs/integrations/svelte-ssr.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ The SSR plugin can provide request-bound browser-like dependencies for stores th
118118

119119
Use `inject.cookieStore: true` when the renderer should provide a request-bound `CookieStore$` during SSR. This feature uses the optional peer package `@nano_kit/platform-web`, so install it in the app before enabling the option. See [SSR Cookies](/ssr/cookies) for the full setup, including store code and `Set-Cookie` forwarding.
120120

121-
```js
121+
```js title="vite.config.js"
122122
ssr({
123123
index: 'src/index.ts',
124124
inject: {
@@ -131,7 +131,7 @@ ssr({
131131

132132
Use `inject.browserLocale: true` when the renderer should provide request-bound `Locales$` during SSR. This feature uses the optional peer package `@nano_kit/platform-web`, so install it in the app before enabling the option. The renderer parses the incoming `Accept-Language` header with [`parseLocales`](/platform/web/#locale), so universal stores can inject `Locales$` and resolve the same locale shape on the server and in the browser. See [SSR Locale](/ssr/locale) for the full setup.
133133

134-
```js
134+
```js title="vite.config.js"
135135
ssr({
136136
index: 'src/index.ts',
137137
inject: {
@@ -144,7 +144,7 @@ ssr({
144144

145145
Use `inject.userAgent: true` when the renderer should provide request-bound `UserAgent$` during SSR. This feature uses the optional peer package `@nano_kit/platform-web`, so install it in the app before enabling the option. The renderer reads the incoming `User-Agent` header, so universal stores can inject `UserAgent$` and read a user agent string on the server and in the browser.
146146

147-
```js
147+
```js title="vite.config.js"
148148
ssr({
149149
index: 'src/index.ts',
150150
inject: {

website/src/content/docs/ssr/index.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ The SSR plugin can provide request-bound browser-like dependencies for stores th
193193
194194
Use `inject.cookieStore: true` when the renderer should provide a request-bound `CookieStore$` during SSR. This feature uses the optional peer package `@nano_kit/platform-web`, so install it in the app before enabling the option. See [SSR Cookies](/ssr/cookies) for the full setup, including store code and `Set-Cookie` forwarding.
195195
196-
```js
196+
```js title="vite.config.js"
197197
ssr({
198198
index: 'src/index.js',
199199
inject: {
@@ -206,7 +206,7 @@ ssr({
206206
207207
Use `inject.browserLocale: true` when the renderer should provide request-bound `Locales$` during SSR. This feature uses the optional peer package `@nano_kit/platform-web`, so install it in the app before enabling the option. The renderer parses the incoming `Accept-Language` header with [`parseLocales`](/platform/web/#locale), so universal stores can inject `Locales$` and resolve the same locale shape on the server and in the browser. See [SSR Locale](/ssr/locale) for the full setup.
208208
209-
```js
209+
```js title="vite.config.js"
210210
ssr({
211211
index: 'src/index.js',
212212
inject: {
@@ -219,7 +219,7 @@ ssr({
219219
220220
Use `inject.userAgent: true` when the renderer should provide request-bound `UserAgent$` during SSR. This feature uses the optional peer package `@nano_kit/platform-web`, so install it in the app before enabling the option. The renderer reads the incoming `User-Agent` header, so universal stores can inject `UserAgent$` and read a user agent string on the server and in the browser.
221221
222-
```js
222+
```js title="vite.config.js"
223223
ssr({
224224
index: 'src/index.js',
225225
inject: {

website/src/content/docs/tutorial/api-services.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ As an app grows, API calls tend to spread. Every request repeats the same transp
99

1010
In our example, the stores are injectable factories now, but the API layer is still a set of standalone functions:
1111

12-
```ts title="services/events.ts"
12+
```ts title="src/services/events.ts"
1313
export async function fetchEvent(slug: string) {
1414
const response = await fetch(`/api/events/${slug}`)
1515

@@ -43,7 +43,7 @@ The class itself is the DI token. The first `inject(EventsService$)` call create
4343

4444
The transport differs between the browser and the server, so it gets two implementations behind one interface. The browser one stays relative to the page origin:
4545

46-
```ts title="services/api/api.client.ts"
46+
```ts title="src/services/api/api.client.ts"
4747
import { Injectable$ } from '@nano_kit/store'
4848
import type { ApiService$ } from './api'
4949

@@ -66,7 +66,7 @@ export class ClientApiService$ extends Injectable$ implements ApiService$ {
6666

6767
The server one targets the API origin directly:
6868

69-
```ts title="services/api/api.server.ts"
69+
```ts title="src/services/api/api.server.ts"
7070
import { Injectable$ } from '@nano_kit/store'
7171
import type { ApiService$ } from './api'
7272

@@ -91,7 +91,7 @@ export class ServerApiService$ extends Injectable$ implements ApiService$ {
9191

9292
The interface and the token pick the implementation at build time:
9393

94-
```ts title="services/api/api.ts"
94+
```ts title="src/services/api/api.ts"
9595
import { ClientApiService$ } from './api.client'
9696
import { ServerApiService$ } from './api.server'
9797

@@ -104,7 +104,7 @@ export const ApiService$ = import.meta.env.SSR
104104
: ClientApiService$
105105
```
106106

107-
```ts title="services/api/index.ts"
107+
```ts title="src/services/api/index.ts"
108108
export * from './api'
109109
```
110110

@@ -116,7 +116,7 @@ This split is also where request context will live. The server implementation is
116116

117117
The standalone functions become methods of `EventsService$`:
118118

119-
```ts title="services/events.ts"
119+
```ts title="src/services/events.ts"
120120
import { Injectable$, inject } from '@nano_kit/store'
121121
import { ApiService$ } from './api'
122122

@@ -143,7 +143,7 @@ export class EventsService$ extends Injectable$ {
143143

144144
Stores inject the service instead of importing functions:
145145

146-
```ts title="stores/events.ts"
146+
```ts title="src/stores/events.ts"
147147
export function EventsList$() {
148148
const eventsService = inject(EventsService$)
149149
const { infinite } = inject(Client$)

website/src/content/docs/tutorial/authentication.mdx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The cookie is HttpOnly, so the frontend never reads or writes it. The browser st
2323

2424
Auth failures are part of the domain, so the service maps HTTP statuses to typed error codes:
2525

26-
```ts title="services/user.types.ts"
26+
```ts title="src/services/user.types.ts"
2727
export const UserError = {
2828
Unauthenticated: 'UNAUTHENTICATED',
2929
LoginFailed: 'LOGIN_FAILED',
@@ -44,7 +44,7 @@ export interface LoginParams {
4444
}
4545
```
4646

47-
```ts title="services/user.ts"
47+
```ts title="src/services/user.ts"
4848
import { Injectable$, inject } from '@nano_kit/store'
4949
import { ApiService$ } from './api'
5050
import { type LoginParams, type User, UserError } from './user.types'
@@ -99,7 +99,7 @@ export class UserService$ extends Injectable$ {
9999

100100
The session state is just a query: `GET /api/users/me` keyed as `UserKey`. For an anonymous visitor the query fails with `UserError.Unauthenticated`, and that error code *is* the "logged out" state.
101101

102-
```ts title="stores/user.ts"
102+
```ts title="src/stores/user.ts"
103103
import { inject, onMountEffect } from '@nano_kit/store'
104104
import { keys, onSuccess, queryKey } from '@nano_kit/query'
105105
import { LocationNavigation$, Paths$ } from '@nano_kit/router'
@@ -175,7 +175,7 @@ The [`onMountEffect`](/store/advanced#onmounteffect-and-onmounteffectscope) bloc
175175

176176
The `publicRoutes` set lives next to the routes:
177177

178-
```ts title="stores/router.ts"
178+
```ts title="src/stores/router.ts"
179179
export const routes = {
180180
home: '/',
181181
login: '/login',
@@ -196,7 +196,7 @@ During SSR the same guard produces a real redirect: `navigation.replace` becomes
196196

197197
The login page is a form wired to the `login` mutation:
198198

199-
```tsx title="ui/pages/Login.tsx"
199+
```tsx title="src/ui/pages/Login.tsx"
200200
import type { FormEvent } from 'react'
201201
import { useInject, useSignal } from '@nano_kit/react'
202202
import { title } from '@nano_kit/react-router'
@@ -266,7 +266,7 @@ The error signal holds the typed code thrown by the service, and the page maps c
266266

267267
The route table gets the new page:
268268

269-
```tsx title="index.tsx"
269+
```tsx title="src/index.tsx"
270270
export const pages = [
271271
layout(Layout, [
272272
page('home', loadable(() => import('./ui/pages/Home'))),
@@ -279,7 +279,7 @@ export const pages = [
279279

280280
The layout shows who is logged in. Including `$user` in the layout `Stores$` means SSR waits for the session before rendering, so the name appears in the first HTML response:
281281

282-
```tsx title="ui/pages/Layout.tsx"
282+
```tsx title="src/ui/pages/Layout.tsx"
283283
export function Stores$() {
284284
const { $user } = inject(User$)
285285

@@ -317,7 +317,7 @@ The renderer can provide the incoming request cookies to stores and services. Ad
317317
pnpm add @nano_kit/platform-web
318318
```
319319

320-
```ts
320+
```ts title="vite.config.ts"
321321
ssr({
322322
index: 'src/index.tsx',
323323
server: 'src/server.ts',
@@ -329,7 +329,7 @@ ssr({
329329

330330
Now `CookieStore$` is injectable during SSR, and the server transport from the API services chapter gets its promised upgrade — it forwards the session cookie to the API:
331331

332-
```ts title="services/api/api.server.ts"
332+
```ts title="src/services/api/api.server.ts"
333333
import { CookieStore$, serializeCookies } from '@nano_kit/platform-web'
334334
import { Injectable$, inject } from '@nano_kit/store'
335335
import type { ApiService$ } from './api'
@@ -390,7 +390,7 @@ See [SSR Cookies](/ssr/cookies) for the full picture of request-bound cookie sto
390390

391391
With a session, RSVP stops being an anonymous counter. The API toggles attendance per user and returns a `going` flag, so `BoardEvent` grows one field:
392392

393-
```ts
393+
```ts title="src/services/events.ts"
394394
export interface BoardEvent {
395395
/* ... */
396396
attendees: number
@@ -400,7 +400,7 @@ export interface BoardEvent {
400400

401401
The optimistic update from the optimistic updates chapter becomes a toggle. Setting cache data returns a revert callback, so rolling back on error takes one line:
402402

403-
```ts title="stores/events.ts"
403+
```ts title="src/stores/events.ts"
404404
export function RsvpEvent$() {
405405
const eventsService = inject(EventsService$)
406406
const { $user } = inject(User$)
@@ -435,7 +435,7 @@ export function RsvpEvent$() {
435435

436436
A logged in user toggles `going` in both directions; an anonymous visitor still just adds a guest, so `going` stays `false` for them. The event page picks the button label from the flag:
437437

438-
```tsx
438+
```tsx title="src/ui/pages/Event.tsx"
439439
<button
440440
type='button'
441441
disabled={rsvpLoading}

website/src/content/docs/tutorial/first-store.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The first store will hold the filters, the loaded events, and the loading flag.
1515
pnpm add @nano_kit/store @nano_kit/react
1616
```
1717

18-
```ts
18+
```ts title="src/stores/events.ts"
1919
import { action, effect, mountable, onMount, signal } from '@nano_kit/store'
2020
import { type BoardEvent, type EventCategory, fetchEvents } from '#src/services/events'
2121

@@ -58,7 +58,7 @@ Here the callback creates an [`effect`](/store/core-concepts#signals-and-effects
5858

5959
Let's render that state with one React component:
6060

61-
```tsx
61+
```tsx title="src/ui/pages/Home.tsx"
6262
import { useSignal } from '@nano_kit/react'
6363
import { $events, $loading, $q } from '#src/stores/events'
6464

website/src/content/docs/tutorial/forms-and-mutations.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ Reading data is only half of a real app. At some point the user also needs to se
99

1010
In our example, that means a page for creating a new event. That page gets its own route:
1111

12-
```ts
12+
```ts title="src/stores/router.ts"
1313
export const routes = {
1414
home: '/',
1515
newEvent: '/events/new',
1616
event: '/events/:slug'
1717
} as const
1818
```
1919

20-
```tsx
20+
```tsx title="src/index.tsx"
2121
import { page, router, useNavigationListenLinks, usePageSignal } from '@nano_kit/react-router'
2222
import { $location, navigation } from './stores/router'
2323
import Event from './ui/pages/Event'
@@ -47,7 +47,7 @@ Nano Kit solves that by combining store signals for local form values with query
4747

4848
Form input values are local UI state, so plain store [`signal`](/store/core-concepts#signals-and-effects) values are enough. Derived values like validation errors and request payload can be computed from those signals.
4949

50-
```ts
50+
```ts title="src/stores/newEvent.ts"
5151
import { action, computed, signal } from '@nano_kit/store'
5252
import { type EventCategory, type NewEventForm } from '#src/services/events'
5353

@@ -103,7 +103,7 @@ export const resetNewEventForm = action(() => {
103103

104104
The submit action is another mutation:
105105

106-
```ts
106+
```ts title="src/stores/newEvent.ts"
107107
import { disabled, onSuccess } from '@nano_kit/query'
108108
import { not } from '@nano_kit/store'
109109
import { type BoardEvent, createEvent as createEventRequest } from '#src/services/events'

0 commit comments

Comments
 (0)