Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/polling-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add `BlockTrackerPollingDataService` and `StaticIntervalPollingDataService` mixins for integrating the polling pattern in data services ([#9352](https://github.com/MetaMask/core/pull/9352))

## [16.0.8]

### Changed
Expand Down
1 change: 1 addition & 0 deletions packages/polling-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
},
"dependencies": {
"@metamask/base-controller": "^9.1.0",
"@metamask/base-data-service": "^0.1.3",
"@metamask/network-controller": "^34.0.0",
"@metamask/utils": "^11.11.0",
"@types/uuid": "^8.3.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BaseController } from '@metamask/base-controller';
import { BaseDataService } from '@metamask/base-data-service';
import type {
NetworkClientId,
NetworkClient,
Expand Down Expand Up @@ -103,3 +104,13 @@ export const BlockTrackerPollingController = <
BlockTrackerPollingControllerMixin<typeof BaseController, PollingInput>(
BaseController,
);

export const BlockTrackerPollingDataService = <

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about placing these in base-data-service instead of this package, since we want to encourage engineers to use polling in data services and discourage them from using it in controllers. But then base-data-service would depend on polling-controller, and that seemed a little strange.

PollingInput extends BlockTrackerPollingInput,
// The return type is inferred from the class defined inside the function
// scope, so this can't be easily typed.
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
>() =>
BlockTrackerPollingControllerMixin<typeof BaseDataService, PollingInput>(
BaseDataService,
);
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BaseController } from '@metamask/base-controller';
import { BaseDataService } from '@metamask/base-data-service';
import type { Json } from '@metamask/utils';

import {
Expand Down Expand Up @@ -96,3 +97,11 @@ export const StaticIntervalPollingController = <PollingInput extends Json>() =>
StaticIntervalPollingControllerMixin<typeof BaseController, PollingInput>(
BaseController,
);

// The return type is inferred from the class defined inside the function
// scope, so this can't be easily typed.
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export const StaticIntervalPollingDataService = <PollingInput extends Json>() =>
StaticIntervalPollingControllerMixin<typeof BaseDataService, PollingInput>(
BaseDataService,
);
2 changes: 2 additions & 0 deletions packages/polling-controller/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
export {
BlockTrackerPollingControllerOnly,
BlockTrackerPollingController,
BlockTrackerPollingDataService,
} from './BlockTrackerPollingController';

export {
StaticIntervalPollingControllerOnly,
StaticIntervalPollingController,
StaticIntervalPollingDataService,
} from './StaticIntervalPollingController';

export type { IPollingController } from './types';
1 change: 1 addition & 0 deletions packages/polling-controller/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
},
"references": [
{ "path": "../base-controller/tsconfig.build.json" },
{ "path": "../base-data-service/tsconfig.build.json" },
{ "path": "../controller-utils/tsconfig.build.json" },
{ "path": "../network-controller/tsconfig.build.json" },
{ "path": "../messenger/tsconfig.build.json" }
Expand Down
1 change: 1 addition & 0 deletions packages/polling-controller/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
},
"references": [
{ "path": "../base-controller" },
{ "path": "../base-data-service" },
{ "path": "../controller-utils" },
{ "path": "../network-controller" },
{ "path": "../messenger" }
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8029,6 +8029,7 @@ __metadata:
dependencies:
"@metamask/auto-changelog": "npm:^6.1.0"
"@metamask/base-controller": "npm:^9.1.0"
"@metamask/base-data-service": "npm:^0.1.3"
"@metamask/messenger": "npm:^1.2.0"
"@metamask/network-controller": "npm:^34.0.0"
"@metamask/utils": "npm:^11.11.0"
Expand Down
Loading