forked from mapbox/mapbox-gl-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow programmatic construction of style even when one is not passed…
… in initially ( h/t @stepankuzmin ) (mapbox#8924)
- Loading branch information
1 parent
40fa9f7
commit b7ca760
Showing
6 changed files
with
91 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import latest from './reference/latest'; | ||
|
||
export default function emptyStyle() { | ||
const style = {}; | ||
|
||
const version = latest['$version']; | ||
for (const styleKey in latest['$root']) { | ||
const spec = latest['$root'][styleKey]; | ||
|
||
if (spec.required) { | ||
let value = null; | ||
if (styleKey === 'version') { | ||
value = version; | ||
} else { | ||
if (spec.type === 'array') { | ||
value = []; | ||
} else { | ||
value = {}; | ||
} | ||
} | ||
|
||
if (value != null) { | ||
style[styleKey] = value; | ||
} | ||
} | ||
} | ||
|
||
return style; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {test} from '../../util/test'; | ||
import emptyStyle from '../../../src/style-spec/empty'; | ||
import validateStyleMin from '../../../src/style-spec/validate_style.min'; | ||
|
||
test('it generates something', (t) => { | ||
const style = emptyStyle(); | ||
t.ok(style); | ||
t.end(); | ||
}); | ||
|
||
test('generated empty style is a valid style', (t) => { | ||
const errors = validateStyleMin(emptyStyle()); | ||
t.equal(errors.length, 0); | ||
t.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters