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 deprecation warning for addDomListener #170

Merged
merged 2 commits into from
Jul 5, 2022
Merged
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
13 changes: 7 additions & 6 deletions addon/utils/options-and-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,12 @@ export function addEventListener(
let isDom = target instanceof Element;
let isOnce = isOnceEvent(originalEventName);

let maybeDom = isDom ? 'Dom' : '';
let maybeOnce = isOnce ? 'Once' : '';

let listenerType = `add${maybeDom}Listener${maybeOnce}`;
let addGoogleListener = google.maps.event[listenerType];
let nativeListener = (target, eventName, callback) => {
target.addEventListener(eventName, callback, { once: isOnce });
};
let addListener = isDom
? nativeListener
: google.maps.event[`addListener${isOnce ? 'Once' : ''}`];

let eventName = isOnce
? originalEventName.slice(6) // onceOn
Expand All @@ -227,7 +228,7 @@ export function addEventListener(
next(target, action, params);
}

let listener = addGoogleListener(target, eventName, callback);
let listener = addListener(target, eventName, callback);

return {
name: eventName,
Expand Down
10 changes: 8 additions & 2 deletions tests/integration/components/g-map/overlay-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { setupMapTest } from 'ember-google-maps/test-support';
import { setupLocations } from 'dummy/tests/helpers/locations';
import { find, render, waitFor } from '@ember/test-helpers';
import { find, render, waitFor, click } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { later } from '@ember/runloop';

Expand Down Expand Up @@ -39,11 +39,15 @@ module('Integration | Component | g map/overlay', function (hooks) {
setupLocations(hooks);

test('it renders a custom overlay', async function (assert) {
assert.expect(4);

this.onClick = () => assert.ok('can attach events to overlays');

await render(hbs`
<GMap @lat={{this.lat}} @lng={{this.lng}} @zoom={{12}} as |g|>
<g.canvas id="map-canvas" />

<g.overlay @lat={{this.lat}} @lng={{this.lng}}>
<g.overlay id="overlay-container" @lat={{this.lat}} @lng={{this.lng}} @onClick={{this.onClick}}>
<div id="custom-overlay"></div>
</g.overlay>
</GMap>
Expand All @@ -61,6 +65,8 @@ module('Integration | Component | g map/overlay', function (hooks) {
assert.ok(overlay, 'overlay rendered');

assert.ok(mapDiv.contains(overlay), 'overlay is child of map node');

await click('#overlay-container');
});

test('it survives a performance test without errors', async function (assert) {
Expand Down