Skip to content

Commit

Permalink
Merge pull request #451 from openlayers/modernize
Browse files Browse the repository at this point in the history
Modernize
  • Loading branch information
gberaudo authored Mar 7, 2017
2 parents 2fc49f5 + 8191c16 commit 2accc3f
Show file tree
Hide file tree
Showing 16 changed files with 631 additions and 475 deletions.
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"extends": "openlayers",
"extends": [
"openlayers",
".eslintrc-es6.yaml"
],
"rules": {
"no-console": 0,
"no-extra-boolean-cast": 0,
Expand Down
153 changes: 153 additions & 0 deletions .eslintrc-es6.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
{
env: {
es6: true
},
parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
ecmaFeatures: {
generators: false,
objectLiteralDuplicateProperties: false
}
},

rules: {
# enforces no braces where they can be omitted
# http://eslint.org/docs/rules/arrow-body-style
'arrow-body-style': ['error', 'as-needed', {
requireReturnForObjectLiteral: true,
}],

# require parens in arrow function arguments
# http://eslint.org/docs/rules/arrow-parens
'arrow-parens': ['error', 'as-needed', {
requireForBlockBody: true,
}],

# require space before/after arrow function's arrow
# http://eslint.org/docs/rules/arrow-spacing
'arrow-spacing': ['error', { before: true, after: true }],

# verify super() callings in constructors
'constructor-super': 'error',

# enforce the spacing around the * in generator functions
# http://eslint.org/docs/rules/generator-star-spacing
'generator-star-spacing': ['error', { before: false, after: true }],

# disallow modifying variables of class declarations
# http://eslint.org/docs/rules/no-class-assign
'no-class-assign': 'error',

# disallow arrow functions where they could be confused with comparisons
# http://eslint.org/docs/rules/no-confusing-arrow
'no-confusing-arrow': ['error', {
allowParens: true,
}],

# disallow modifying variables that are declared using const
'no-const-assign': 'error',

# disallow duplicate class members
# http://eslint.org/docs/rules/no-dupe-class-members
'no-dupe-class-members': 'error',

# disallow importing from the same path more than once
# http://eslint.org/docs/rules/no-duplicate-imports
'no-duplicate-imports': 'error',

# disallow symbol constructor
# http://eslint.org/docs/rules/no-new-symbol
'no-new-symbol': 'error',

# disallow specific imports
# http://eslint.org/docs/rules/no-restricted-imports
'no-restricted-imports': 'off',

# disallow to use this/super before super() calling in constructors.
# http://eslint.org/docs/rules/no-this-before-super
'no-this-before-super': 'error',

# disallow useless computed property keys
# http://eslint.org/docs/rules/no-useless-computed-key
'no-useless-computed-key': 'error',

# disallow unnecessary constructor
# http://eslint.org/docs/rules/no-useless-constructor
'no-useless-constructor': 'error',

# disallow renaming import, export, and destructured assignments to the same name
# http://eslint.org/docs/rules/no-useless-rename
'no-useless-rename': ['error', {
ignoreDestructuring: false,
ignoreImport: false,
ignoreExport: false,
}],

# require let or const instead of var
'no-var': 'error',

# require method and property shorthand syntax for object literals
# http://eslint.org/docs/rules/object-shorthand
'object-shorthand': ['error', 'always', {
ignoreConstructors: false,
avoidQuotes: true,
}],

# suggest using arrow functions as callbacks
'prefer-arrow-callback': ['error', {
allowNamedFunctions: false,
allowUnboundThis: true,
}],

# suggest using of const declaration for variables that are never modified after declared
'prefer-const': ['error', {
destructuring: 'any',
ignoreReadBeforeAssign: true,
}],

# disallow parseInt() in favor of binary, octal, and hexadecimal literals
# http://eslint.org/docs/rules/prefer-numeric-literals
'prefer-numeric-literals': 'error',

# use rest parameters instead of arguments
# http://eslint.org/docs/rules/prefer-rest-params
'prefer-rest-params': 'error',

# suggest using the spread operator instead of .apply()
# http://eslint.org/docs/rules/prefer-spread
'prefer-spread': 'error',

# suggest using template literals instead of string concatenation
# http://eslint.org/docs/rules/prefer-template
'prefer-template': 'error',

# disallow generator functions that do not have yield
# http://eslint.org/docs/rules/require-yield
'require-yield': 'error',

# enforce spacing between object rest-spread
# http://eslint.org/docs/rules/rest-spread-spacing
'rest-spread-spacing': ['error', 'never'],

# import sorting
# http://eslint.org/docs/rules/sort-imports
'sort-imports': ['off', {
ignoreCase: false,
ignoreMemberSort: false,
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
}],

# require a Symbol description
# http://eslint.org/docs/rules/symbol-description
'symbol-description': 'error',

# enforce usage of spacing in template strings
# http://eslint.org/docs/rules/template-curly-spacing
'template-curly-spacing': 'error',

# enforce spacing around the * in yield* expressions
# http://eslint.org/docs/rules/yield-star-spacing
'yield-star-spacing': ['error', 'after']
}
}
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Changes
* Port to Cesium 1.31.
* Add example rotate.html about animating rotation of the Cesium globe.
* Convert source to Ecmascript 6. Continue to output Ecmascript 5.1.

# v 1.24.3 - 2017-02-17

Expand Down
2 changes: 1 addition & 1 deletion build/olcesium.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"api", "observable"
],
"compilation_level": "ADVANCED_OPTIMIZATIONS",
"language_in": "ECMASCRIPT5_STRICT",
"language_in": "ECMASCRIPT6_STRICT",
"language_out": "ECMASCRIPT5_STRICT",
"warning_level": "VERBOSE",
"generate_exports": true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@mapbox/geojsonhint": "2.0.1",
"fs-extra": "2.0.0",
"jsdoc": "~3.4.0",
"eslint": "3.16.1",
"eslint": "3.17.0",
"eslint-config-openlayers": "7.0.0",
"nomnom": "1.8.1",
"temp": "0.8.3",
Expand Down
52 changes: 26 additions & 26 deletions src/abstractsynchronizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,18 @@ olcs.AbstractSynchronizer.prototype.orderLayers = function() {
*/
olcs.AbstractSynchronizer.prototype.addLayers_ = function(root) {
/** @type {Array.<!ol.layer.Base>} */
var fifo = [root];
const fifo = [root];
while (fifo.length > 0) {
var olLayer = fifo.splice(0, 1)[0];
var olLayerId = ol.getUid(olLayer).toString();
const olLayer = fifo.splice(0, 1)[0];
const olLayerId = ol.getUid(olLayer).toString();
goog.asserts.assert(!this.layerMap[olLayerId]);

var cesiumObjects = null;
let cesiumObjects = null;
if (olLayer instanceof ol.layer.Group) {
this.listenForGroupChanges_(olLayer);
cesiumObjects = this.createSingleLayerCounterparts(olLayer);
if (!cesiumObjects) {
olLayer.getLayers().forEach(function(l) {
olLayer.getLayers().forEach((l) => {
if (l) {
fifo.push(l);
}
Expand Down Expand Up @@ -142,8 +142,8 @@ olcs.AbstractSynchronizer.prototype.addLayers_ = function(root) {
* @private
*/
olcs.AbstractSynchronizer.prototype.removeAndDestroySingleLayer_ = function(layer) {
var uid = ol.getUid(layer).toString();
var counterparts = this.layerMap[uid];
const uid = ol.getUid(layer).toString();
const counterparts = this.layerMap[uid];
if (!!counterparts) {
counterparts.forEach(function(counterpart) {
this.removeSingleCesiumObject(counterpart, false);
Expand All @@ -166,9 +166,9 @@ olcs.AbstractSynchronizer.prototype.unlistenSingleGroup_ = function(group) {
if (group === this.mapLayerGroup) {
return;
}
var uid = ol.getUid(group).toString();
var keys = this.olGroupListenKeys_[uid];
keys.forEach(function(key) {
const uid = ol.getUid(group).toString();
const keys = this.olGroupListenKeys_[uid];
keys.forEach((key) => {
ol.Observable.unByKey(key);
});
delete this.olGroupListenKeys_[uid];
Expand All @@ -183,16 +183,16 @@ olcs.AbstractSynchronizer.prototype.unlistenSingleGroup_ = function(group) {
*/
olcs.AbstractSynchronizer.prototype.removeLayer_ = function(root) {
if (!!root) {
var fifo = [root];
const fifo = [root];
while (fifo.length > 0) {
var olLayer = fifo.splice(0, 1)[0];
var done = this.removeAndDestroySingleLayer_(olLayer);
const olLayer = fifo.splice(0, 1)[0];
const done = this.removeAndDestroySingleLayer_(olLayer);
if (olLayer instanceof ol.layer.Group) {
this.unlistenSingleGroup_(olLayer);
if (!done) {
// No counterpart for the group itself so removing
// each of the child layers.
olLayer.getLayers().forEach(function(l) {
olLayer.getLayers().forEach((l) => {
fifo.push(l);
});
}
Expand All @@ -208,17 +208,17 @@ olcs.AbstractSynchronizer.prototype.removeLayer_ = function(root) {
* @private
*/
olcs.AbstractSynchronizer.prototype.listenForGroupChanges_ = function(group) {
var uuid = ol.getUid(group).toString();
const uuid = ol.getUid(group).toString();

goog.asserts.assert(this.olGroupListenKeys_[uuid] === undefined);

var listenKeyArray = [];
const listenKeyArray = [];
this.olGroupListenKeys_[uuid] = listenKeyArray;

// only the keys that need to be relistened when collection changes
var contentKeys = [];
var listenAddRemove = (function() {
var collection = group.getLayers();
let contentKeys = [];
const listenAddRemove = (function() {
const collection = group.getLayers();
if (collection) {
contentKeys = [
collection.on('add', function(event) {
Expand All @@ -228,15 +228,15 @@ olcs.AbstractSynchronizer.prototype.listenForGroupChanges_ = function(group) {
this.removeLayer_(event.element);
}, this)
];
listenKeyArray.push.apply(listenKeyArray, contentKeys);
listenKeyArray.push(...contentKeys);
}
}).bind(this);

listenAddRemove();

listenKeyArray.push(group.on('change:layers', function(e) {
contentKeys.forEach(function(el) {
var i = listenKeyArray.indexOf(el);
listenKeyArray.push(group.on('change:layers', (e) => {
contentKeys.forEach((el) => {
const i = listenKeyArray.indexOf(el);
if (i >= 0) {
listenKeyArray.splice(i, 1);
}
Expand All @@ -253,13 +253,13 @@ olcs.AbstractSynchronizer.prototype.listenForGroupChanges_ = function(group) {
*/
olcs.AbstractSynchronizer.prototype.destroyAll = function() {
this.removeAllCesiumObjects(true); // destroy
var objKey;
let objKey;
for (objKey in this.olGroupListenKeys_) {
var keys = this.olGroupListenKeys_[objKey];
const keys = this.olGroupListenKeys_[objKey];
keys.forEach(ol.Observable.unByKey);
}
for (objKey in this.olLayerListenKeys_) {
var key = this.olLayerListenKeys_[objKey];
const key = this.olLayerListenKeys_[objKey];
ol.Observable.unByKey(key);
}
this.olGroupListenKeys_ = {};
Expand Down
Loading

0 comments on commit 2accc3f

Please sign in to comment.