Skip to content

Commit 0f4215d

Browse files
committed
Expand on data service delegation example
1 parent b197ca9 commit 0f4215d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

docs/data-services.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ const gasPricesService = new GasPricesService({
432432
433433
Great! Now that we've set up the data service and its messenger action, we can use it somewhere else.
434434
435-
Let's say we wanted to use it in a controller. We'd just need to allow that controller's messenger access to `GasPricesService:fetchGasPrices` by delegating it from the root messenger.
435+
Let's say we wanted to use `GasPricesService:fetchGasPrices` in a controller. First, that controller's messenger would need to include `GasPricesService:fetchGasPrices` in its type defintion.
436436
437437
This code would probably be in the controller package itself. For instance, if we had a file `packages/send-controller/send-controller.ts`, we might have:
438438
@@ -454,6 +454,15 @@ type SendControllerMessenger = Messenger<
454454
>;
455455
```
456456
457+
Then we'll need to allow that controller's messenger access to `GasPricesService:fetchGasPrices` by delegating it from the root messenger:
458+
459+
```typescript
460+
rootMessenger.delegate({
461+
actions: ['GasPricesService:fetchGasPrices'],
462+
messenger: sendControllerMessenger,
463+
});
464+
```
465+
457466
Then, later on in our controller, we could say:
458467
459468
```typescript

0 commit comments

Comments
 (0)