chore: upgrade mitt (#9340)
This commit is contained in:
parent
e8c1d56845
commit
f3c87dcdb7
@ -14,16 +14,16 @@ Add an event listener.
|
||||
|
||||
```typescript
|
||||
class EventEmitter {
|
||||
addListener(event: EventType, handler: Handler): EventEmitter;
|
||||
addListener(event: EventType, handler: Handler<any>): EventEmitter;
|
||||
}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --------- | ------------------------------------- | ----------- |
|
||||
| event | [EventType](./puppeteer.eventtype.md) | |
|
||||
| handler | [Handler](./puppeteer.handler.md) | |
|
||||
| Parameter | Type | Description |
|
||||
| --------- | -------------------------------------------- | ----------- |
|
||||
| event | [EventType](./puppeteer.eventtype.md) | |
|
||||
| handler | [Handler](./puppeteer.handler.md)<any> | |
|
||||
|
||||
**Returns:**
|
||||
|
||||
|
@ -10,16 +10,16 @@ Remove an event listener from firing.
|
||||
|
||||
```typescript
|
||||
class EventEmitter {
|
||||
off(event: EventType, handler: Handler): EventEmitter;
|
||||
off(event: EventType, handler: Handler<any>): EventEmitter;
|
||||
}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --------- | ------------------------------------- | ----------------------------------------------- |
|
||||
| event | [EventType](./puppeteer.eventtype.md) | the event type you'd like to stop listening to. |
|
||||
| handler | [Handler](./puppeteer.handler.md) | the function that should be removed. |
|
||||
| Parameter | Type | Description |
|
||||
| --------- | -------------------------------------------- | ----------------------------------------------- |
|
||||
| event | [EventType](./puppeteer.eventtype.md) | the event type you'd like to stop listening to. |
|
||||
| handler | [Handler](./puppeteer.handler.md)<any> | the function that should be removed. |
|
||||
|
||||
**Returns:**
|
||||
|
||||
|
@ -10,16 +10,16 @@ Bind an event listener to fire when an event occurs.
|
||||
|
||||
```typescript
|
||||
class EventEmitter {
|
||||
on(event: EventType, handler: Handler): EventEmitter;
|
||||
on(event: EventType, handler: Handler<any>): EventEmitter;
|
||||
}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --------- | ------------------------------------- | ------------------------------------------------------------------ |
|
||||
| event | [EventType](./puppeteer.eventtype.md) | the event type you'd like to listen to. Can be a string or symbol. |
|
||||
| handler | [Handler](./puppeteer.handler.md) | the function to be called when the event occurs. |
|
||||
| Parameter | Type | Description |
|
||||
| --------- | -------------------------------------------- | ------------------------------------------------------------------ |
|
||||
| event | [EventType](./puppeteer.eventtype.md) | the event type you'd like to listen to. Can be a string or symbol. |
|
||||
| handler | [Handler](./puppeteer.handler.md)<any> | the function to be called when the event occurs. |
|
||||
|
||||
**Returns:**
|
||||
|
||||
|
@ -10,16 +10,16 @@ Like `on` but the listener will only be fired once and then it will be removed.
|
||||
|
||||
```typescript
|
||||
class EventEmitter {
|
||||
once(event: EventType, handler: Handler): EventEmitter;
|
||||
once(event: EventType, handler: Handler<any>): EventEmitter;
|
||||
}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --------- | ------------------------------------- | ------------------------------------------------- |
|
||||
| event | [EventType](./puppeteer.eventtype.md) | the event you'd like to listen to |
|
||||
| handler | [Handler](./puppeteer.handler.md) | the handler function to run when the event occurs |
|
||||
| Parameter | Type | Description |
|
||||
| --------- | -------------------------------------------- | ------------------------------------------------- |
|
||||
| event | [EventType](./puppeteer.eventtype.md) | the event you'd like to listen to |
|
||||
| handler | [Handler](./puppeteer.handler.md)<any> | the handler function to run when the event occurs |
|
||||
|
||||
**Returns:**
|
||||
|
||||
|
@ -14,16 +14,16 @@ Remove an event listener.
|
||||
|
||||
```typescript
|
||||
class EventEmitter {
|
||||
removeListener(event: EventType, handler: Handler): EventEmitter;
|
||||
removeListener(event: EventType, handler: Handler<any>): EventEmitter;
|
||||
}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --------- | ------------------------------------- | ----------- |
|
||||
| event | [EventType](./puppeteer.eventtype.md) | |
|
||||
| handler | [Handler](./puppeteer.handler.md) | |
|
||||
| Parameter | Type | Description |
|
||||
| --------- | -------------------------------------------- | ----------- |
|
||||
| event | [EventType](./puppeteer.eventtype.md) | |
|
||||
| handler | [Handler](./puppeteer.handler.md)<any> | |
|
||||
|
||||
**Returns:**
|
||||
|
||||
|
@ -7,5 +7,5 @@ sidebar_label: Handler
|
||||
#### Signature:
|
||||
|
||||
```typescript
|
||||
declare type Handler<T = any> = (event?: T) => void;
|
||||
declare type Handler<T = unknown> = (event: T) => void;
|
||||
```
|
||||
|
14
package-lock.json
generated
14
package-lock.json
generated
@ -58,7 +58,7 @@
|
||||
"jpeg-js": "0.4.4",
|
||||
"mime": "3.0.0",
|
||||
"minimist": "1.2.6",
|
||||
"mitt": "2.1.0",
|
||||
"mitt": "3.0.0",
|
||||
"mocha": "10.0.0",
|
||||
"ncp": "2.0.0",
|
||||
"npm-run-all": "4.1.5",
|
||||
@ -6217,9 +6217,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/mitt": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/mitt/-/mitt-2.1.0.tgz",
|
||||
"integrity": "sha512-ILj2TpLiysu2wkBbWjAmww7TkZb65aiQO+DkVdUTBpBXq+MHYiETENkKFMtsJZX1Lf4pe4QOrTSjIfUwN5lRdg==",
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/mitt/-/mitt-3.0.0.tgz",
|
||||
"integrity": "sha512-7dX2/10ITVyqh4aOSVI9gdape+t9l2/8QxHrFmUXu4EEUpdlxl6RudZUPZoc+zuY2hk1j7XxVroIVIan/pD/SQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/mkdirp-classic": {
|
||||
@ -13200,9 +13200,9 @@
|
||||
}
|
||||
},
|
||||
"mitt": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/mitt/-/mitt-2.1.0.tgz",
|
||||
"integrity": "sha512-ILj2TpLiysu2wkBbWjAmww7TkZb65aiQO+DkVdUTBpBXq+MHYiETENkKFMtsJZX1Lf4pe4QOrTSjIfUwN5lRdg==",
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/mitt/-/mitt-3.0.0.tgz",
|
||||
"integrity": "sha512-7dX2/10ITVyqh4aOSVI9gdape+t9l2/8QxHrFmUXu4EEUpdlxl6RudZUPZoc+zuY2hk1j7XxVroIVIan/pD/SQ==",
|
||||
"dev": true
|
||||
},
|
||||
"mkdirp-classic": {
|
||||
|
@ -81,7 +81,7 @@
|
||||
"jpeg-js": "0.4.4",
|
||||
"mime": "3.0.0",
|
||||
"minimist": "1.2.6",
|
||||
"mitt": "2.1.0",
|
||||
"mitt": "3.0.0",
|
||||
"mocha": "10.0.0",
|
||||
"ncp": "2.0.0",
|
||||
"npm-run-all": "4.1.5",
|
||||
|
@ -425,7 +425,7 @@ export interface PageEventObject {
|
||||
* @public
|
||||
*/
|
||||
export class Page extends EventEmitter {
|
||||
#handlerMap = new WeakMap<Handler, Handler>();
|
||||
#handlerMap = new WeakMap<Handler<any>, Handler<any>>();
|
||||
|
||||
/**
|
||||
* @internal
|
||||
|
@ -17,6 +17,7 @@
|
||||
import mitt, {
|
||||
Emitter,
|
||||
EventType,
|
||||
EventHandlerMap,
|
||||
Handler,
|
||||
} from '../../third_party/mitt/index.js';
|
||||
|
||||
@ -57,8 +58,8 @@ export interface CommonEventEmitter {
|
||||
* @public
|
||||
*/
|
||||
export class EventEmitter implements CommonEventEmitter {
|
||||
private emitter: Emitter;
|
||||
private eventsMap = new Map<EventType, Handler[]>();
|
||||
private emitter: Emitter<Record<string | symbol, any>>;
|
||||
private eventsMap: EventHandlerMap<Record<string | symbol, any>> = new Map();
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@ -73,7 +74,7 @@ export class EventEmitter implements CommonEventEmitter {
|
||||
* @param handler - the function to be called when the event occurs.
|
||||
* @returns `this` to enable you to chain method calls.
|
||||
*/
|
||||
on(event: EventType, handler: Handler): EventEmitter {
|
||||
on(event: EventType, handler: Handler<any>): EventEmitter {
|
||||
this.emitter.on(event, handler);
|
||||
return this;
|
||||
}
|
||||
@ -84,7 +85,7 @@ export class EventEmitter implements CommonEventEmitter {
|
||||
* @param handler - the function that should be removed.
|
||||
* @returns `this` to enable you to chain method calls.
|
||||
*/
|
||||
off(event: EventType, handler: Handler): EventEmitter {
|
||||
off(event: EventType, handler: Handler<any>): EventEmitter {
|
||||
this.emitter.off(event, handler);
|
||||
return this;
|
||||
}
|
||||
@ -93,7 +94,7 @@ export class EventEmitter implements CommonEventEmitter {
|
||||
* Remove an event listener.
|
||||
* @deprecated please use {@link EventEmitter.off} instead.
|
||||
*/
|
||||
removeListener(event: EventType, handler: Handler): EventEmitter {
|
||||
removeListener(event: EventType, handler: Handler<any>): EventEmitter {
|
||||
this.off(event, handler);
|
||||
return this;
|
||||
}
|
||||
@ -102,7 +103,7 @@ export class EventEmitter implements CommonEventEmitter {
|
||||
* Add an event listener.
|
||||
* @deprecated please use {@link EventEmitter.on} instead.
|
||||
*/
|
||||
addListener(event: EventType, handler: Handler): EventEmitter {
|
||||
addListener(event: EventType, handler: Handler<any>): EventEmitter {
|
||||
this.on(event, handler);
|
||||
return this;
|
||||
}
|
||||
@ -125,8 +126,8 @@ export class EventEmitter implements CommonEventEmitter {
|
||||
* @param handler - the handler function to run when the event occurs
|
||||
* @returns `this` to enable you to chain method calls.
|
||||
*/
|
||||
once(event: EventType, handler: Handler): EventEmitter {
|
||||
const onceHandler: Handler = eventData => {
|
||||
once(event: EventType, handler: Handler<any>): EventEmitter {
|
||||
const onceHandler: Handler<any> = eventData => {
|
||||
handler(eventData);
|
||||
this.off(event, onceHandler);
|
||||
};
|
||||
|
@ -64,7 +64,10 @@ describe('Target.createCDPSession', function () {
|
||||
client.on('Network.requestWillBeSent', event => {
|
||||
return events.push(event);
|
||||
});
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
await Promise.all([
|
||||
waitEvent(client, 'Network.requestWillBeSent'),
|
||||
page.goto(server.EMPTY_PAGE),
|
||||
]);
|
||||
expect(events.length).toBe(1);
|
||||
});
|
||||
it('should enable and disable domains independently', async () => {
|
||||
|
Loading…
Reference in New Issue
Block a user