mirror of
https://github.com/zhigang1992/mtcute.git
synced 2026-04-30 05:05:10 +08:00
docs: fixed dispatcher creation docs
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -128,7 +128,7 @@ dp.onNewMessage(
|
||||
}
|
||||
)
|
||||
|
||||
const dp1 = new Dispatcher()
|
||||
const dp1 = Dispatcher.child()
|
||||
dp.addChild(dp1)
|
||||
|
||||
dp1.onNewMessage(
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 })
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user