Skip to content

Commit

Permalink
Move functions not depending on state out of the class
Browse files Browse the repository at this point in the history
  • Loading branch information
bbecquet committed Jan 28, 2018
1 parent 51ff372 commit 4ea1350
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
18 changes: 9 additions & 9 deletions dist/leaflet.polylineDecorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,14 @@ L$1.Symbol.marker = function (options) {
return new L$1.Symbol.Marker(options);
};

var isCoord = function isCoord(c) {
return c instanceof L$1.LatLng || Array.isArray(c) && c.length === 2 && typeof c[0] === 'number';
};

var isCoordArray = function isCoordArray(ll) {
return Array.isArray(ll) && isCoord(ll[0]);
};

L$1.PolylineDecorator = L$1.FeatureGroup.extend({
options: {
patterns: []
Expand All @@ -306,7 +314,7 @@ L$1.PolylineDecorator = L$1.FeatureGroup.extend({
_initPaths: function _initPaths(input, isPolygon) {
var _this = this;

if (this._isCoordArray(input)) {
if (isCoordArray(input)) {
// Leaflet Polygons don't need the first point to be repeated, but we do
var coords = isPolygon ? input.concat([input[0]]) : input;
return [coords];
Expand All @@ -324,14 +332,6 @@ L$1.PolylineDecorator = L$1.FeatureGroup.extend({
return [];
},

_isCoordArray: function _isCoordArray(ll) {
return Array.isArray(ll) && this._isCoord(ll[0]);
},

_isCoord: function _isCoord(c) {
return c instanceof L$1.LatLng || Array.isArray(c) && c.length === 2 && typeof c[0] === 'number';
},

// parse pattern definitions and precompute some values
_initPatterns: function _initPatterns(patternDefs) {
return patternDefs.map(this._parsePatternDef);
Expand Down
17 changes: 7 additions & 10 deletions src/L.PolylineDecorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import {
} from './patternUtils.js';
import './L.Symbol.js';

const isCoord = c =>
(c instanceof L.LatLng) ||
(Array.isArray(c) && c.length === 2 && typeof c[0] === 'number');

const isCoordArray = ll => Array.isArray(ll) && isCoord(ll[0]);

L.PolylineDecorator = L.FeatureGroup.extend({
options: {
patterns: []
Expand All @@ -25,7 +31,7 @@ L.PolylineDecorator = L.FeatureGroup.extend({
* array of one of the previous.
*/
_initPaths: function(input, isPolygon) {
if (this._isCoordArray(input)) {
if (isCoordArray(input)) {
// Leaflet Polygons don't need the first point to be repeated, but we do
const coords = isPolygon ? input.concat([input[0]]) : input;
return [coords];
Expand All @@ -43,15 +49,6 @@ L.PolylineDecorator = L.FeatureGroup.extend({
return [];
},

_isCoordArray: function(ll) {
return Array.isArray(ll) && this._isCoord(ll[0]);
},

_isCoord: function(c) {
return c instanceof L.LatLng
|| (Array.isArray(c) && c.length === 2 && typeof c[0] === 'number');
},

// parse pattern definitions and precompute some values
_initPatterns: function(patternDefs) {
return patternDefs.map(this._parsePatternDef);
Expand Down

0 comments on commit 4ea1350

Please sign in to comment.