Skip to content

Commit

Permalink
Added PollingControllerOnly (#1873)
Browse files Browse the repository at this point in the history
## Explanation

Added PollingControllerOnly to extend from an empty class. This will
allow classes that previously are just classes that don't extend from
BaseV2 or V2 to extend from this new PollingControllerOnly.

## Changelog

<!--
If you're making any consumer-facing changes, list those changes here as
if you were updating a changelog, using the template below as a guide.

(CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or
FIXED. For security-related issues, follow the Security Advisory
process.)

Please take care to name the exact pieces of the API you've added or
changed (e.g. types, interfaces, functions, or methods).

If there are any breaking changes, make sure to offer a solution for
consumers to follow once they upgrade to the changes.

Finally, if you're only making changes to development scripts or tests,
you may replace the template below with "None".
-->

### `@metamask/polling-controller`

- **ADDED**: PollingControllerOnly to extend from an empty class

---------

Co-authored-by: jiexi <[email protected]>
Co-authored-by: Alex Donesky <[email protected]>
  • Loading branch information
3 people authored Oct 20, 2023
1 parent 9f987f4 commit 4b3098c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/polling-controller/src/PollingController.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ControllerMessenger } from '@metamask/base-controller';

import { PollingController } from './PollingController';
import { PollingController, PollingControllerOnly } from './PollingController';

const TICK_TIME = 1000;

Expand Down Expand Up @@ -327,4 +327,18 @@ describe('PollingController', () => {
]);
});
});
describe('PollingControllerOnly', () => {
it('can be extended from and constructed', async () => {
class MyClass extends PollingControllerOnly {
_executePoll = createExecutePollMock();
}
const c = new MyClass();
expect(c._executePoll).toBeDefined();
expect(c.getIntervalLength).toBeDefined();
expect(c.setIntervalLength).toBeDefined();
expect(c.stopAllPolling).toBeDefined();
expect(c.startPollingByNetworkClientId).toBeDefined();
expect(c.stopPollingByPollingToken).toBeDefined();
});
});
});
3 changes: 3 additions & 0 deletions packages/polling-controller/src/PollingController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,8 @@ function PollingControllerMixin<TBase extends Constructor>(Base: TBase) {
return PollingControllerBase;
}

class Empty {}

export const PollingControllerOnly = PollingControllerMixin(Empty);
export const PollingController = PollingControllerMixin(BaseControllerV2);
export const PollingControllerV1 = PollingControllerMixin(BaseController);

0 comments on commit 4b3098c

Please sign in to comment.