Memoize and avoid extra calls to utilDetect()

This commit is contained in:
Bryan Housel
2016-10-18 21:48:39 -04:00
parent bf857c419a
commit efd9e6df4b
6 changed files with 11 additions and 6 deletions
+1 -1
View File
@@ -18,6 +18,7 @@ var apibase = 'https://a.mapillary.com/v2/',
maxPages = 10,
tileZoom = 14,
dispatch = d3.dispatch('loadedImages', 'loadedSigns'),
detected = utilDetect(),
mapillaryCache,
mapillaryClicks,
mapillaryImage,
@@ -298,7 +299,6 @@ export default {
signsSupported: function() {
var detected = utilDetect();
return (!(detected.ie || detected.browser.toLowerCase() === 'safari'));
},
+2 -1
View File
@@ -7,6 +7,7 @@ import toGeoJSON from 'togeojson';
export function svgGpx(projection, context, dispatch) {
var showLabels = true,
detected = utilDetect(),
layer;
@@ -27,7 +28,7 @@ export function svgGpx(projection, context, dispatch) {
.on('drop.localgpx', function() {
d3.event.stopPropagation();
d3.event.preventDefault();
if (!utilDetect().filedrop) return;
if (!detected.filedrop) return;
drawGpx.files(d3.event.dataTransfer.files);
})
.on('dragenter.localgpx', over)
+1 -1
View File
@@ -340,7 +340,7 @@ export function svgLabels(projection, context) {
var coord = projection(entity.loc),
margin = 2,
textDirection = utilDetect().textDirection,
textDirection = detected.textDirection,
offset = pointOffsets[textDirection],
p = {
height: height,
+2 -1
View File
@@ -12,6 +12,7 @@ import { utilDetect } from '../util/detect';
export function svgLines(projection) {
var detected = utilDetect();
var highway_stack = {
motorway: 0,
@@ -135,7 +136,7 @@ export function svgLines(projection) {
.merge(oneways)
.attr('d', function(d) { return d.d; });
if (utilDetect().ie) {
if (detected.ie) {
oneways.each(function() { this.parentNode.insertBefore(this, this); });
}
};
+2 -1
View File
@@ -15,6 +15,7 @@ import { tooltip } from '../util/tooltip';
export function uiBackground(context) {
var key = 'B',
detected = utilDetect(),
opacities = [1, 0.75, 0.5, 0.25],
directions = [
['right', [0.5, 0]],
@@ -45,7 +46,7 @@ export function uiBackground(context) {
.style('opacity', d)
.attr('data-opacity', d);
if (!utilDetect().opera) {
if (!detected.opera) {
utilSetTransform(bg, 0, 0);
}
+3 -1
View File
@@ -1,9 +1,11 @@
import { currentLocale, setTextDirection } from './locale';
import { utilStringQs } from './index';
var detected;
export function utilDetect() {
var detected = {};
if (detected) return detected;
detected = {};
var ua = navigator.userAgent,
m = null;