Independent-of-prod quality debt from PENDIENTE.md §2: - test: migrate broken Jest -> meteortesting:mocha. Tests rewritten to chai + Meteor 3 async APIs, moved to test/server/ (server-only). test/server/ 00-setup.test.js re-runs the collection2/accounts init that `meteor test` skips (no server/main.js). New comments method + mediaAnalyzers coverage. Dropped rest.test.js (removed meteor/http; covered by smoke/). 36 passing. - fix: scope FireContainer read by the URL _id on the archive route instead of a selector-less FiresCollection.findOne() (imports/ui/pages/Fires/Fires.js). - feat: rate-limit abusable publications via rateLimitSubscriptions (fireFrom* and comments.forReference 5/1000ms; geo subs 10/1000ms). - perf: append loading=async to the Google Maps loader URL (Gkeys.js). - deps: meteor-accounts-t9n 2.0 -> 2.6 (no gl build -> keep gl->es fallback, documented); add 3 missing gl/common.json keys (0 missing now). - deps: drop jest/babel/enzyme, add chai.
55 lines
1.6 KiB
JavaScript
55 lines
1.6 KiB
JavaScript
import { Meteor } from 'meteor/meteor';
|
|
import { ReactiveVar } from 'meteor/reactive-var';
|
|
import { Tracker } from 'meteor/tracker';
|
|
import GoogleMapsLoader from 'google-maps';
|
|
|
|
class GkeysC {
|
|
constructor() {
|
|
this.gmapkey = new ReactiveVar(null);
|
|
const self = this;
|
|
this.callbacks = [];
|
|
Meteor.startup(() => {
|
|
Meteor.call('getMapKey', (error, key) => {
|
|
// console.log(google.maps);
|
|
GoogleMapsLoader.KEY = key;
|
|
GoogleMapsLoader.LIBRARIES = ['places'];
|
|
// The google-maps npm package (v3.2.1) builds the script URL without
|
|
// `loading=async`, which Google now warns about. It exposes no hook for
|
|
// extra params, so wrap createUrl to append it (no node_modules edit).
|
|
const origCreateUrl = GoogleMapsLoader.createUrl;
|
|
GoogleMapsLoader.createUrl = () => `${origCreateUrl()}&loading=async`;
|
|
GoogleMapsLoader.load(() => {
|
|
self.gmapkey.set(key);
|
|
console.log('GMaps script just loaded');
|
|
self.doCallbacks(key);
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
doCallbacks(key) {
|
|
for (let i = 0; i < this.callbacks.length; i += 1) {
|
|
this.callbacks[i](null, key);
|
|
}
|
|
this.callbacks = [];
|
|
}
|
|
|
|
load(callback) {
|
|
this.callbacks.push(callback);
|
|
Tracker.autorun((computation) => {
|
|
const key = this.gmapkey.get();
|
|
if (key) {
|
|
// already loaded
|
|
// console.log('GMaps already loaded');
|
|
this.doCallbacks(key);
|
|
computation.stop();
|
|
} else {
|
|
console.log('Waiting for the gkey');
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
const Gkeys = new GkeysC();
|
|
|
|
export default Gkeys;
|