Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typings issues in 3.2.0 #2898

Merged
merged 17 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@types/mapbox__point-geometry": "^0.1.2",
"@types/mapbox__vector-tile": "^1.3.0",
"@types/pbf": "^3.0.2",
"@types/supercluster": "^7.1.0",
HarelM marked this conversation as resolved.
Show resolved Hide resolved
"earcut": "^2.2.4",
"geojson-vt": "^3.2.1",
"gl-matrix": "^3.4.3",
Expand Down Expand Up @@ -69,7 +70,6 @@
"@types/react-dom": "^18.2.6",
"@types/request": "^2.48.8",
"@types/shuffle-seed": "^1.1.0",
"@types/supercluster": "^7.1.0",
"@types/window-or-global": "^1.0.4",
"@typescript-eslint/eslint-plugin": "^5.61.0",
"@typescript-eslint/parser": "^5.62.0",
Expand Down
3 changes: 1 addition & 2 deletions src/ui/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,5 @@ export class Hash {
/**
* Mobile Safari doesn't allow updating the hash more than 100 times per 30 seconds.
*/
_updateHash = throttle(this._updateHashUnthrottled, 30 * 1000 / 100);

_updateHash: () => ReturnType<typeof setTimeout> = throttle(this._updateHashUnthrottled, 30 * 1000 / 100);
HarelM marked this conversation as resolved.
Show resolved Hide resolved
}
2 changes: 1 addition & 1 deletion src/ui/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1411,13 +1411,13 @@ export class Map extends Camera {
* @see [Create a hover effect](https://maplibre.org/maplibre-gl-js/docs/examples/hover-styles/)
* @see [Create a draggable marker](https://maplibre.org/maplibre-gl-js/docs/examples/drag-a-point/)
*/
on(type: keyof MapEventType | string, listener: Listener): this;
on<T extends keyof MapLayerEventType>(
type: T,
layer: string,
listener: (ev: MapLayerEventType[T] & Object) => void,
): Map;
on<T extends keyof MapEventType>(type: T, listener: (ev: MapEventType[T] & Object) => void): this;
on(type: keyof MapEventType | string, listener: Listener): this;
HarelM marked this conversation as resolved.
Show resolved Hide resolved
/**
* This is an overload of the `on` method that allows to listen to events based on the `layerId`
* @event
Expand Down
69 changes: 69 additions & 0 deletions src/ui/map_events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,19 @@ describe('map events', () => {
expect(handler.onMove).toHaveBeenCalledTimes(1);
});

test('Map#on allows a listener to infer the event type ', () => {
const map = createMap();

const spy = jest.fn();
map.on('mousemove', (event) => {
const {lng, lat} = event.lngLat;
spy({lng, lat});
});

simulate.mousemove(map.getCanvas());
expect(spy).toHaveBeenCalledTimes(1);
});

test('Map#off removes a delegated event listener', () => {
const map = createMap();

Expand Down Expand Up @@ -244,6 +257,62 @@ describe('map events', () => {
expect(spyB).not.toHaveBeenCalled();
});

test('Map#off calls an event listener with no type arguments, defaulting to \'unknown\' originalEvent type', () => {
const map = createMap();

const handler = {
onMove: function onMove(_event: MapLibreEvent) {}
};

jest.spyOn(handler, 'onMove');

map.off('move', (event) => handler.onMove(event));
map.jumpTo({center: {lng: 10, lat: 10}});

expect(handler.onMove).toHaveBeenCalledTimes(0);
});

test('Map#off allows a listener to infer the event type ', () => {
const map = createMap();

const spy = jest.fn();
map.off('mousemove', (event) => {
const {lng, lat} = event.lngLat;
spy({lng, lat});
});

simulate.mousemove(map.getCanvas());
expect(spy).toHaveBeenCalledTimes(0);
});

test('Map#once calls an event listener with no type arguments, defaulting to \'unknown\' originalEvent type', () => {
const map = createMap();

const handler = {
onMoveOnce: function onMoveOnce(_event: MapLibreEvent) {}
};

jest.spyOn(handler, 'onMoveOnce');

map.once('move', (event) => handler.onMoveOnce(event));
map.jumpTo({center: {lng: 10, lat: 10}});

expect(handler.onMoveOnce).toHaveBeenCalledTimes(1);
});

test('Map#once allows a listener to infer the event type ', () => {
const map = createMap();

const spy = jest.fn();
map.once('mousemove', (event) => {
const {lng, lat} = event.lngLat;
spy({lng, lat});
});

simulate.mousemove(map.getCanvas());
expect(spy).toHaveBeenCalledTimes(1);
});

(['mouseenter', 'mouseover'] as (keyof MapLayerEventType)[]).forEach((event) => {
test(`Map#on ${event} does not fire if the specified layer does not exist`, () => {
const map = createMap();
Expand Down