Cleaned dead code and updated documents
This commit is contained in:
@@ -12,39 +12,44 @@ npm install @rythazhur/mizan@git+https://git.impactsoundworks.com/isw/mizan.git#
|
||||
|
||||
You don't use this package directly. You use the **generated hooks**.
|
||||
|
||||
This is the pre-kernel React adapter: it ships its own `MizanProvider`
|
||||
(`src/context.tsx`) that owns HTTP/WebSocket/CSRF/session/context state
|
||||
directly, rather than subscribing to the `@mizan/base` kernel. It is still
|
||||
the provider the Django + desktop example wires against. (`DjangoContext`,
|
||||
`useDjango`, etc. are deprecated aliases for the `Mizan*` names.)
|
||||
|
||||
### 1. Configure
|
||||
|
||||
```js
|
||||
// django.config.mjs
|
||||
export default {
|
||||
source: {
|
||||
django: {
|
||||
managePath: '../backend/manage.py',
|
||||
command: ['uv', 'run', 'python'],
|
||||
},
|
||||
},
|
||||
output: 'src/api/generated.ts',
|
||||
}
|
||||
```toml
|
||||
# mizan.toml
|
||||
output = "src/api"
|
||||
targets = ["react"]
|
||||
|
||||
[source.django]
|
||||
manage_path = "../backend/manage.py"
|
||||
command = ["uv", "run", "python"]
|
||||
```
|
||||
|
||||
### 2. Generate
|
||||
|
||||
The codegen is the `mizan-generate` Rust binary (source at
|
||||
`protocol/mizan-codegen/`; `protocol/mizan-generate/` is the npm launcher):
|
||||
|
||||
```bash
|
||||
npx mizan-generate # once
|
||||
npx mizan-generate --watch # dev mode
|
||||
mizan-generate --config mizan.toml
|
||||
```
|
||||
|
||||
### 3. Wrap your app
|
||||
|
||||
```tsx
|
||||
import { DjangoContext } from '@/api'
|
||||
import { MizanProvider } from '@rythazhur/mizan'
|
||||
|
||||
<DjangoContext>
|
||||
<MizanProvider>
|
||||
<App />
|
||||
</DjangoContext>
|
||||
</MizanProvider>
|
||||
```
|
||||
|
||||
`DjangoContext` is the only provider you need. It handles HTTP, WebSocket, CSRF, session init, context auto-fetching, and channel connections.
|
||||
`MizanProvider` is the only provider you need. It handles HTTP, WebSocket, CSRF, session init, context auto-fetching, and channel connections.
|
||||
|
||||
### 4. Use generated hooks
|
||||
|
||||
@@ -71,19 +76,22 @@ chat.messages // typed, reactive
|
||||
|
||||
## Generated Files
|
||||
|
||||
The Rust codegen emits per-target files into the configured `output`
|
||||
directory (Stage 1 is auto-included whenever `react` is a target):
|
||||
|
||||
| File | Contents |
|
||||
|------|----------|
|
||||
| `generated.django.tsx` | `DjangoContext` + typed hooks |
|
||||
| `generated.mizan.ts` | Pydantic types |
|
||||
| `generated.forms.ts` | Form hooks with Zod |
|
||||
| `generated.channels.hooks.tsx` | Channel hooks |
|
||||
| `index.ts` | Re-exports everything |
|
||||
| `types.ts` | Pydantic types |
|
||||
| `contexts/<name>.ts` | Per-context `fetchXxx` bundles |
|
||||
| `react.tsx` | `<MizanContext>` provider + typed `use{Hook}()` hooks |
|
||||
| `channels.ts` / `channels.hooks.tsx` | Channel types + hooks (when the schema carries channels) |
|
||||
| `index.ts` | Stage 1 re-export root |
|
||||
|
||||
## Sub-exports
|
||||
|
||||
| Import | When to use |
|
||||
|--------|------------|
|
||||
| `@rythazhur/mizan` | Core: mizanProvider, hooks, forms, errors |
|
||||
| `@rythazhur/mizan` | Core: `MizanProvider`, hooks, forms, errors |
|
||||
| `@rythazhur/mizan/channels` | WebSocket channels |
|
||||
| `@rythazhur/mizan/jwt` | JWT token management |
|
||||
| `@rythazhur/mizan/client` | HTTP clients (CSR/SSR) |
|
||||
|
||||
Reference in New Issue
Block a user