docs: fixed dispatcher creation docs

This commit is contained in:
alina sireneva
2025-03-23 03:27:46 +03:00
parent 76789da23d
commit e2d6b3006f
6 changed files with 13 additions and 13 deletions

View File

@@ -96,9 +96,9 @@ Errors are **not** propagated to parent dispatcher or to any of the children
dispatchers:
```ts
const dp = new Dispatcher(tg)
const dp1 = new Dispatcher()
const dp2 = new Dispatcher()
const dp = Dispatcher.for(tg)
const dp1 = Dispatcher.child()
const dp2 = Dispatcher.child()
dp.addChild(dp1)
dp1.addChild(dp2)
@@ -117,9 +117,9 @@ dp1.onNewMessage(() => { throw new Error() })
However, if you need that behaviour, you can use `propagateErrorToParent`:
```ts
const dp = new Dispatcher(tg)
const dp1 = new Dispatcher()
const dp2 = new Dispatcher()
const dp = Dispatcher.for(tg)
const dp1 = Dispatcher.child()
const dp2 = Dispatcher.child()
dp.addChild(dp1)
dp1.addChild(dp2)

View File

@@ -128,7 +128,7 @@ dp.onNewMessage(
}
)
const dp1 = new Dispatcher()
const dp1 = Dispatcher.child()
dp.addChild(dp1)
dp1.onNewMessage(

View File

@@ -30,7 +30,7 @@ dp.addScene(SomeScene)
If you don't use state within your scene, just don't pass anything:
```ts
const scene = new Dispatcher()
const scene = Dispatcher.scene()
```
::: tip
@@ -115,7 +115,7 @@ Alternatively, you can disable isolated storage for FSM altogether and use
global state directly:
```ts
const dp = new Dispatcher<BotState>()
const dp = Dispatcher.scene<BotState>()
// add handlers to `dp`
export const SomeScene = dp

View File

@@ -180,9 +180,9 @@ keying mechanism too, if you want:
```ts
const customKey = (upd) => ...
const dp = new Dispatcher<BotState>(tg, storage, customKey)
const dp = Dispatcher.for<BotState>(tg, { storage, key: customKey })
// or, locally for a child dispatcher:
const dp = new Dispatcher<BotState>(customKey)
const dp = Dispatcher.child<BotState>({ key: customKey })
```

View File

@@ -124,7 +124,7 @@ Unhandled errors that had happened inside dispatcher's handlers
can be handled as well:
```ts
const dp = new Dispatcher()
const dp = Dispatcher.child()
dp.onError((error, update, state) => {
console.log(error)

View File

@@ -138,7 +138,7 @@ a separate section. For now, let's just register a dispatcher and add a simple h
```ts
const tg = new TelegramClient(...)
const dp = new Dispatcher(tg)
const dp = Dispatcher.for(tg)
dp.onNewMessage(async (msg) => {
await msg.forwardTo('me')