Skip to content

Commit

Permalink
[internal] Replace var with let in ui/public F-N
Browse files Browse the repository at this point in the history
This change was applied to any .js files under directories beginning
with `f` through `n` in src/ui/public. There are no `e` directories.

This was an automatic replacement from var to let for any variable
declaration that doubles as the initial assignment. Ultimately we want
most of these to be converted to const, but this commit is so large that
it warrants breaking each step of automation up into its own commit.

For example:

`var foo = 'bar';` becomes `let foo = 'var';`

This was accomplished by replacing:
find: `var ([a-zA-Z_$][0-9a-zA-Z_$]*)(\s+)=`
replace: `let $1$2=`
  • Loading branch information
epixa committed Apr 13, 2016
1 parent 68d46d4 commit cd76078
Show file tree
Hide file tree
Showing 64 changed files with 351 additions and 351 deletions.
8 changes: 4 additions & 4 deletions src/ui/public/fancy_forms/fancy_forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ uiModules
// directive providers are arrays
$delegate.forEach(function (directive) {
// get metadata about all init fns
var chain = [directive.controller, DecorativeController].map(function (fn) {
var deps = $injector.annotate(fn);
let chain = [directive.controller, DecorativeController].map(function (fn) {
let deps = $injector.annotate(fn);
return { deps: deps, fn: _.isArray(fn) ? _.last(fn) : fn };
});

// replace the controller with one that will setup the actual controller
directive.controller = function stub() {
var allDeps = _.toArray(arguments);
let allDeps = _.toArray(arguments);
return chain.reduce(function (controller, link, i) {
var deps = allDeps.splice(0, link.deps.length);
let deps = allDeps.splice(0, link.deps.length);
return link.fn.apply(controller, deps) || controller;
}, this);
};
Expand Down
8 changes: 4 additions & 4 deletions src/ui/public/fancy_forms/kbn_form_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import _ from 'lodash';
* @param {$scope} $scope
*/
function KbnFormController($scope, $element) {
var self = this;
let self = this;

self.errorCount = function (predicate) {
return self.$$invalidModels().length;
Expand All @@ -21,14 +21,14 @@ function KbnFormController($scope, $element) {
};

self.describeErrors = function () {
var count = self.softErrorCount();
let count = self.softErrorCount();
return count + ' Error' + (count === 1 ? '' : 's');
};

self.$$invalidModels = function (predicate) {
predicate = _.callback(predicate);

var invalid = [];
let invalid = [];

_.forOwn(self.$error, function collect(models) {
if (!models) return;
Expand All @@ -40,7 +40,7 @@ function KbnFormController($scope, $element) {
} else {
if (predicate(model)) {
// prevent dups
var len = invalid.length;
let len = invalid.length;
while (len--) if (invalid[len] === model) return;

invalid.push(model);
Expand Down
38 changes: 19 additions & 19 deletions src/ui/public/field_editor/field_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import fieldEditorTemplate from 'ui/field_editor/field_editor.html';
uiModules
.get('kibana', ['colorpicker.module'])
.directive('fieldEditor', function (Private, $sce) {
var fieldFormats = Private(RegistryFieldFormatsProvider);
var Field = Private(IndexPatternsFieldProvider);
var scriptingInfo = $sce.trustAsHtml(require('ui/field_editor/scripting_info.html'));
var scriptingWarning = $sce.trustAsHtml(require('ui/field_editor/scripting_warning.html'));
let fieldFormats = Private(RegistryFieldFormatsProvider);
let Field = Private(IndexPatternsFieldProvider);
let scriptingInfo = $sce.trustAsHtml(require('ui/field_editor/scripting_info.html'));
let scriptingWarning = $sce.trustAsHtml(require('ui/field_editor/scripting_warning.html'));

return {
restrict: 'E',
Expand All @@ -25,8 +25,8 @@ uiModules
},
controllerAs: 'editor',
controller: function ($scope, Notifier, kbnUrl) {
var self = this;
var notify = new Notifier({ location: 'Field Editor' });
let self = this;
let notify = new Notifier({ location: 'Field Editor' });

self.scriptingInfo = scriptingInfo;
self.scriptingWarning = scriptingWarning;
Expand All @@ -43,9 +43,9 @@ uiModules

self.cancel = redirectAway;
self.save = function () {
var indexPattern = self.indexPattern;
var fields = indexPattern.fields;
var field = self.field.toActualField();
let indexPattern = self.indexPattern;
let fields = indexPattern.fields;
let field = self.field.toActualField();

fields.remove({ name: field.name });
fields.push(field);
Expand All @@ -64,8 +64,8 @@ uiModules
};

self.delete = function () {
var indexPattern = self.indexPattern;
var field = self.field;
let indexPattern = self.indexPattern;
let field = self.field;

indexPattern.fields.remove({ name: field.name });
return indexPattern.save()
Expand All @@ -76,9 +76,9 @@ uiModules
};

$scope.$watch('editor.selectedFormatId', function (cur, prev) {
var format = self.field.format;
var changedFormat = cur !== prev;
var missingFormat = cur && (!format || format.type.id !== cur);
let format = self.field.format;
let changedFormat = cur !== prev;
let missingFormat = cur && (!format || format.type.id !== cur);

if (!changedFormat || !missingFormat) return;

Expand All @@ -87,15 +87,15 @@ uiModules
});

$scope.$watch('editor.formatParams', function () {
var FieldFormat = getFieldFormatType();
let FieldFormat = getFieldFormatType();
self.field.format = new FieldFormat(self.formatParams);
}, true);

// copy the defined properties of the field to a plain object
// which is mutable, and capture the changed seperately.
function shadowCopy(field) {
var changes = {};
var shadowProps = {
let changes = {};
let shadowProps = {
toActualField: {
// bring the shadow copy out of the shadows
value: function toActualField() {
Expand All @@ -105,7 +105,7 @@ uiModules
};

Object.getOwnPropertyNames(field).forEach(function (prop) {
var desc = Object.getOwnPropertyDescriptor(field, prop);
let desc = Object.getOwnPropertyDescriptor(field, prop);
shadowProps[prop] = {
enumerable: desc.enumerable,
get: function () {
Expand All @@ -130,7 +130,7 @@ uiModules
}

function initDefaultFormat() {
var def = Object.create(fieldFormats.getDefaultType(self.field.type));
let def = Object.create(fieldFormats.getDefaultType(self.field.type));

// explicitly set to undefined to prevent inheritting the prototypes id
def.id = undefined;
Expand Down
22 changes: 11 additions & 11 deletions src/ui/public/field_format_editor/field_format_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ uiModules
},
controllerAs: 'editor',
controller: function ($scope) {
var self = this;
let self = this;

// bind the scope values to the controller, down with $scope.values
$scope.editor = this;
Expand All @@ -40,7 +40,7 @@ uiModules
* @return {undefined}
*/
$scope.$watch('editor.field.format.type', function (FieldFormat) {
var opts = FieldFormat && FieldFormat.editor;
let opts = FieldFormat && FieldFormat.editor;

if (!opts) {
delete self.$$pseudoDirective;
Expand All @@ -67,14 +67,14 @@ uiModules

},
link: function ($scope, $el) {
var scopesToTeardown = [];
let scopesToTeardown = [];

function setupScope(opts) {
if (typeof opts !== 'object') {
return scopesToTeardown[scopesToTeardown.push($scope.$new()) - 1];
}

var isolate = scopesToTeardown[scopesToTeardown.push($scope.$new(true)) - 1];
let isolate = scopesToTeardown[scopesToTeardown.push($scope.$new(true)) - 1];
_.forOwn(opts, function (from, to) {
isolate.$bind(to, from, $scope);
});
Expand All @@ -88,21 +88,21 @@ uiModules
if (!directive) return $el.hide();
else $el.show();

var askedForChild = !!directive.scope;
var reuseScope = !askedForChild && !directive.controller;
let askedForChild = !!directive.scope;
let reuseScope = !askedForChild && !directive.controller;

var $formatEditor = $('<div>').html(directive.template);
var $formatEditorScope = reuseScope ? $scope : setupScope(directive.scope);
let $formatEditor = $('<div>').html(directive.template);
let $formatEditorScope = reuseScope ? $scope : setupScope(directive.scope);

if (directive.controller) {
// bind the controller to the injected element
var cntrlAs = (directive.controllerAs ? ' as ' + directive.controllerAs : '');
let cntrlAs = (directive.controllerAs ? ' as ' + directive.controllerAs : '');
$formatEditorScope.Controller = directive.controller;
$formatEditor.attr('ng-controller', 'Controller' + cntrlAs);
}

var attrs = {};
var linkFns = directive.compile && directive.compile($el, attrs);
let attrs = {};
let linkFns = directive.compile && directive.compile($el, attrs);
if (!linkFns || _.isFunction(linkFns)) {
linkFns = {
pre: _.noop,
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/field_format_editor/pattern/pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ uiModules
require: ['ngModel', '^fieldEditor'],
scope: true,
link: function ($scope, $el, attrs, cntrls) {
var ngModelCntrl = cntrls[0];
let ngModelCntrl = cntrls[0];

$scope.$bind('inputs', attrs.inputs);
$scope.$bind('placeholder', attrs.placeholder);
Expand Down
6 changes: 3 additions & 3 deletions src/ui/public/field_format_editor/samples/samples.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ uiModules
require: ['?^ngModel', '^fieldEditor'],
scope: true,
link: function ($scope, $el, attrs, cntrls) {
var ngModelCntrl = cntrls[0];
let ngModelCntrl = cntrls[0];

$scope.samples = null;
$scope.$bind('inputs', attrs.inputs);
Expand All @@ -21,14 +21,14 @@ uiModules
'[]inputs'
], function () {
$scope.samples = null;
var field = $scope.editor.field;
let field = $scope.editor.field;

if (!field || !field.format) {
return;
}

Promise.try(function () {
var converter = field.format.getConverterFor('html');
let converter = field.format.getConverterFor('html');
$scope.samples = _.map($scope.inputs, function (input) {
return [input, $sce.trustAsHtml(converter(input))];
});
Expand Down
20 changes: 10 additions & 10 deletions src/ui/public/filter_bar/filter_bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import FilterBarLibFilterOutTimeBasedFilterProvider from 'ui/filter_bar/lib/filt
import FilterBarLibChangeTimeFilterProvider from 'ui/filter_bar/lib/change_time_filter';
import FilterBarQueryFilterProvider from 'ui/filter_bar/query_filter';
import uiModules from 'ui/modules';
var module = uiModules.get('kibana');
let module = uiModules.get('kibana');


module.directive('filterBar', function (Private, Promise, getAppState) {
var mapAndFlattenFilters = Private(FilterBarLibMapAndFlattenFiltersProvider);
var mapFlattenAndWrapFilters = Private(FilterBarLibMapFlattenAndWrapFiltersProvider);
var extractTimeFilter = Private(FilterBarLibExtractTimeFilterProvider);
var filterOutTimeBasedFilter = Private(FilterBarLibFilterOutTimeBasedFilterProvider);
var changeTimeFilter = Private(FilterBarLibChangeTimeFilterProvider);
var queryFilter = Private(FilterBarQueryFilterProvider);
var privateFilterFieldRegex = /(^\$|meta)/;
let mapAndFlattenFilters = Private(FilterBarLibMapAndFlattenFiltersProvider);
let mapFlattenAndWrapFilters = Private(FilterBarLibMapFlattenAndWrapFiltersProvider);
let extractTimeFilter = Private(FilterBarLibExtractTimeFilterProvider);
let filterOutTimeBasedFilter = Private(FilterBarLibFilterOutTimeBasedFilterProvider);
let changeTimeFilter = Private(FilterBarLibChangeTimeFilterProvider);
let queryFilter = Private(FilterBarQueryFilterProvider);
let privateFilterFieldRegex = /(^\$|meta)/;

return {
restrict: 'E',
Expand All @@ -48,7 +48,7 @@ module.directive('filterBar', function (Private, Promise, getAppState) {

$scope.aceLoaded = function (editor) {
editor.$blockScrolling = Infinity;
var session = editor.getSession();
let session = editor.getSession();
session.setTabSize(2);
session.setUseSoftTabs(true);
};
Expand Down Expand Up @@ -141,7 +141,7 @@ module.directive('filterBar', function (Private, Promise, getAppState) {
}

function updateFilters() {
var filters = queryFilter.getFilters();
let filters = queryFilter.getFilters();
mapAndFlattenFilters(filters).then(function (results) {
// used to display the current filters in the state
$scope.filters = _.sortBy(results, function (filter) {
Expand Down
10 changes: 5 additions & 5 deletions src/ui/public/filter_bar/filter_bar_click_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import findByParam from 'ui/utils/find_by_param';
export default function (Notifier) {
return function ($state) {
return function (event, simulate) {
var notify = new Notifier({
let notify = new Notifier({
location: 'Filter bar'
});
let aggConfigResult;
Expand All @@ -23,18 +23,18 @@ export default function (Notifier) {
}

if (aggConfigResult) {
var isLegendLabel = !!event.point.values;
var aggBuckets = _.filter(aggConfigResult.getPath(), { type: 'bucket' });
let isLegendLabel = !!event.point.values;
let aggBuckets = _.filter(aggConfigResult.getPath(), { type: 'bucket' });

// For legend clicks, use the last bucket in the path
if (isLegendLabel) {
// series data has multiple values, use aggConfig on the first
// hierarchical data values is an object with the addConfig
var aggConfig = findByParam(event.point.values, 'aggConfig');
let aggConfig = findByParam(event.point.values, 'aggConfig');
aggBuckets = aggBuckets.filter((result) => result.aggConfig && result.aggConfig === aggConfig);
}

var filters = _(aggBuckets)
let filters = _(aggBuckets)
.map(function (result) {
try {
return result.createFilter();
Expand Down
4 changes: 2 additions & 2 deletions src/ui/public/filter_bar/lib/change_time_filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import moment from 'moment';
import _ from 'lodash';
export default function changeTimeFilterProvider(timefilter) {
return function (filter) {
var key = _.keys(filter.range)[0];
var values = filter.range[key];
let key = _.keys(filter.range)[0];
let values = filter.range[key];
timefilter.time.from = moment(values.gt || values.gte);
timefilter.time.to = moment(values.lt || values.lte);
timefilter.time.mode = 'absolute';
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/filter_bar/lib/compare_filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function (first, second, comparatorOptions) {
};

function mapFilter(filter) {
var cleaned = _.omit(filter, excludedAttributes);
let cleaned = _.omit(filter, excludedAttributes);
if (comparators.negate) cleaned.negate = filter.meta && !!filter.meta.negate;
if (comparators.disabled) cleaned.disabled = filter.meta && !!filter.meta.disabled;
return cleaned;
Expand Down
6 changes: 3 additions & 3 deletions src/ui/public/filter_bar/lib/extract_time_filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ export default function extractTimeFilterProvider(courier, Promise) {
return Promise.method(function (filters) {
// Assume all the index patterns are the same since they will be added
// from the same visualization.
var id = _.get(filters, '[0].meta.index');
let id = _.get(filters, '[0].meta.index');
if (id == null) return;

return courier.indexPatterns.get(id).then(function (indexPattern) {
var filter = _.find(filters, function (obj) {
var key = _.keys(obj.range)[0];
let filter = _.find(filters, function (obj) {
let key = _.keys(obj.range)[0];
return key === indexPattern.timeFieldName;
});
if (filter && filter.range) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from 'lodash';
export default function filterOutTimeBaseFilter(courier, Promise) {
return Promise.method(function (filters) {
var id = _.get(filters, '[0].meta.index');
let id = _.get(filters, '[0].meta.index');
if (id == null) return;

return courier.indexPatterns.get(id).then(function (indexPattern) {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/filter_bar/lib/generate_mapping_chain.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from 'lodash';
export default function generateMappingChainProvider(Promise) {

var noop = function () {
let noop = function () {
return Promise.reject(new Error('No mappings have been found for filter.'));
};

Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/filter_bar/lib/map_and_flatten_filters.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from 'lodash';
import FilterBarLibMapFilterProvider from 'ui/filter_bar/lib/map_filter';
export default function mapAndFlattenFiltersProvider(Private, Promise) {
var mapFilter = Private(FilterBarLibMapFilterProvider);
let mapFilter = Private(FilterBarLibMapFilterProvider);
return function (filters) {
return _(filters)
.flatten()
Expand Down
Loading

0 comments on commit cd76078

Please sign in to comment.