Skip to content

Commit

Permalink
Use old function code rather than converting to expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Sep 29, 2017
1 parent d79918f commit 00c3c9d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 21 deletions.
8 changes: 3 additions & 5 deletions src/style-spec/expression/index.js
Expand Up @@ -62,9 +62,7 @@ type StylePropertySpecification = {
type StylePropertyValue = null | string | number | Array<string> | Array<number>;
type FunctionParameters = DataDrivenPropertyValueSpecification<StylePropertyValue>

function createExpression(expression: mixed,
propertySpec: StylePropertySpecification,
options: { isConvertedFunction?: boolean, defaultValue?: any } = {}): StyleExpression {
function createExpression(expression: mixed, propertySpec: StylePropertySpecification): StyleExpression {
const expectedType = getExpectedType(propertySpec);
const compiled = compileExpression(expression, expectedType);

Expand All @@ -73,7 +71,7 @@ function createExpression(expression: mixed,
throw new Error(compiled.errors.map(err => `${err.key}: ${err.message}`).join(', '));
}

let defaultValue = options.defaultValue || propertySpec.default;
let defaultValue = propertySpec.default;
if (propertySpec.type === 'color') {
defaultValue = parseColor((defaultValue: any));
}
Expand All @@ -87,7 +85,7 @@ function createExpression(expression: mixed,
}
return val;
} catch (e) {
if (!options.isConvertedFunction && !warningHistory[e.message]) {
if (!warningHistory[e.message]) {
warningHistory[e.message] = true;
if (typeof console !== 'undefined') {
console.warn(e.message);
Expand Down
4 changes: 3 additions & 1 deletion src/style-spec/function/index.js
Expand Up @@ -121,7 +121,9 @@ function createFunction(parameters, propertySpec) {
return {
isFeatureConstant: true,
isZoomConstant: false,
interpolation: {name: type === 'exponential' ? 'exponential' : 'step'},
interpolation: type === 'exponential' ?
{name: 'exponential', base: parameters.base !== undefined ? parameters.base : 1} :
{name: 'step'},
zoomStops: parameters.stops.map(s => s[0]),
evaluate({zoom}) {
return outputFunction(innerFun(parameters, propertySpec, zoom, hashedStops, categoricalKeyType));
Expand Down
7 changes: 2 additions & 5 deletions src/style/style_declaration.js
Expand Up @@ -2,7 +2,7 @@

const parseColor = require('../style-spec/util/parse_color');
const createExpression = require('../style-spec/expression');
const convertFunction = require('../style-spec/function/convert');
const createFunction = require('../style-spec/function');
const util = require('../util/util');
const Curve = require('../style-spec/expression/definitions/curve');

Expand All @@ -29,10 +29,7 @@ function normalizeToExpression(parameters, propertySpec): StyleExpression {
if (parameters.expression) {
return createExpression(parameters.expression, propertySpec);
} else {
return createExpression(convertFunction(parameters, propertySpec), propertySpec, {
defaultValue: parameters.default,
isConvertedFunction: true
});
return createFunction(parameters, propertySpec);
}
}

Expand Down
12 changes: 2 additions & 10 deletions test/unit/style-spec/function.test.js
@@ -1,15 +1,7 @@
'use strict';

const test = require('mapbox-gl-js-test').test;
const createExpression = require('../../../src/style-spec/expression');
const convertFunction = require('../../../src/style-spec/function/convert');

function createFunction(parameters, propertySpec) {
return createExpression(convertFunction(parameters, propertySpec), propertySpec, {
defaultValue: parameters.default,
isConvertedFunction: true
});
}
const createFunction = require('../../../src/style-spec/function');

test('binary search', (t) => {
t.test('will eventually terminate.', (t) => {
Expand Down Expand Up @@ -996,7 +988,7 @@ test('unknown function', (t) => {
type: 'nonesuch', stops: [[]]
}, {
type: 'string'
}), /Unknown zoom function type "nonesuch"/);
}), /Unknown function type "nonesuch"/);
t.end();
});

Expand Down

0 comments on commit 00c3c9d

Please sign in to comment.