Skip to content

Commit

Permalink
Merge pull request #170 from sandydoo/wip/add-dom-listener-deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
sandydoo authored Jul 5, 2022
2 parents 37949c6 + 0c87c77 commit b6759b5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
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

0 comments on commit b6759b5

Please sign in to comment.