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