Skip to content

Commit

Permalink
Promote StylePropertySpecification
Browse files Browse the repository at this point in the history
It's useful outside of expressions.
  • Loading branch information
jfirebaugh committed Nov 3, 2017
1 parent 05f5d8c commit c26bc89
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 40 deletions.
6 changes: 2 additions & 4 deletions bench/benchmarks/expressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ const convertFunction = require('../../src/style-spec/function/convert');
const {isFunction, createFunction} = require('../../src/style-spec/function');
const {createExpression} = require('../../src/style-spec/expression');

import type {
StyleExpression,
StylePropertySpecification
} from '../../src/style-spec/expression';
import type {StylePropertySpecification} from '../../src/style-spec/style-spec';
import type {StyleExpression} from '../../src/style-spec/expression';

class ExpressionBenchmark extends Benchmark {
data: Array<{
Expand Down
36 changes: 1 addition & 35 deletions src/style-spec/expression/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const isConstant = require('./is_constant');
import type {Type} from './types';
import type {Value} from './values';
import type {Expression} from './expression';
import type {StylePropertySpecification} from '../style-spec';

export type Feature = {
+type: 1 | 2 | 3 | 'Unknown' | 'Point' | 'MultiPoint' | 'LineString' | 'MultiLineString' | 'Polygon' | 'MultiPolygon',
Expand Down Expand Up @@ -65,41 +66,6 @@ export type StyleFilterExpression = ZoomConstantExpression | {

export type StyleExpression = StyleDeclarationExpression | StyleFilterExpression;

export type StylePropertySpecification = {
type: 'number',
'function': boolean,
'property-function': boolean,
default?: number
} | {
type: 'string',
'function': boolean,
'property-function': boolean,
default?: string
} | {
type: 'boolean',
'function': boolean,
'property-function': boolean,
default?: boolean
} | {
type: 'enum',
'function': boolean,
'property-function': boolean,
values: {[string]: {}},
default?: string
} | {
type: 'array',
'function': boolean,
'property-function': boolean,
value: 'number' | 'string' | 'boolean',
length?: number,
default?: Array<Value>
} | {
type: 'color',
'function': boolean,
'property-function': boolean,
default?: string
};

function isExpression(expression: mixed) {
return Array.isArray(expression) && expression.length > 0 &&
typeof expression[0] === 'string' && expression[0] in definitions;
Expand Down
2 changes: 1 addition & 1 deletion src/style-spec/expression/values.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function validateRGBA(r: mixed, g: mixed, b: mixed, a?: mixed): ?string {
return null;
}

export type Value = null | string | boolean | number | Color | Array<Value> | { [string]: Value }
export type Value = null | string | boolean | number | Color | $ReadOnlyArray<Value> | { +[string]: Value }

function isValue(mixed: mixed): boolean {
if (mixed === null) {
Expand Down
43 changes: 43 additions & 0 deletions src/style-spec/style-spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
// @flow

export type StylePropertySpecification = {
type: 'number',
'function': boolean,
'property-function': boolean,
default?: number
} | {
type: 'string',
'function': boolean,
'property-function': boolean,
default?: string
} | {
type: 'boolean',
'function': boolean,
'property-function': boolean,
default?: boolean
} | {
type: 'enum',
'function': boolean,
'property-function': boolean,
values: {[string]: {}},
default?: string
} | {
type: 'color',
'function': boolean,
'property-function': boolean,
default?: string
} | {
type: 'array',
value: 'number',
'function': boolean,
'property-function': boolean,
length?: number,
default?: Array<number>
} | {
type: 'array',
value: 'string',
'function': boolean,
'property-function': boolean,
length?: number,
default?: Array<string>
};

exports.v6 = require('./reference/v6.json');
exports.v7 = require('./reference/v7.json');
Expand Down

0 comments on commit c26bc89

Please sign in to comment.