Skip to content

Commit

Permalink
Merge pull request #6909 from epixa/uiletconst5
Browse files Browse the repository at this point in the history
[internal] Replace var with let in ui/public P-T
  • Loading branch information
panda01 committed Apr 14, 2016
2 parents fbb0c55 + 1cddaab commit cd412ee
Show file tree
Hide file tree
Showing 50 changed files with 291 additions and 291 deletions.
12 changes: 6 additions & 6 deletions src/ui/public/paginated_table/paginated_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import paginatedTableTemplate from 'ui/paginated_table/paginated_table.html';
uiModules
.get('kibana')
.directive('paginatedTable', function ($filter) {
var orderBy = $filter('orderBy');
let orderBy = $filter('orderBy');

return {
restrict: 'E',
Expand All @@ -19,14 +19,14 @@ uiModules
},
controllerAs: 'paginatedTable',
controller: function ($scope) {
var self = this;
let self = this;
self.sort = {
columnIndex: null,
direction: null
};

self.sortColumn = function (colIndex) {
var col = $scope.columns[colIndex];
let col = $scope.columns[colIndex];

if (!col) return;
if (col.sortable === false) return;
Expand All @@ -36,7 +36,7 @@ uiModules
if (self.sort.columnIndex !== colIndex) {
sortDirection = 'asc';
} else {
var directions = {
let directions = {
null: 'asc',
'asc': 'desc',
'desc': null
Expand All @@ -56,7 +56,7 @@ uiModules
} else {
// use generic sort handler
self.sort.getter = function (row) {
var value = row[index];
let value = row[index];
if (value && value.value != null) value = value.value;
if (typeof value === 'boolean') value = value ? 0 : 1;
return value;
Expand All @@ -75,7 +75,7 @@ uiModules
return;
}

var sort = self.sort;
let sort = self.sort;
if (sort.direction == null) {
$scope.sortedRows = $scope.rows.slice(0);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/ui/public/parse_query/lib/from_user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from 'lodash';
import DecorateQueryProvider from 'ui/courier/data_source/_decorate_query';
export default function GetQueryFromUser(es, Private) {
var decorateQuery = Private(DecorateQueryProvider);
let decorateQuery = Private(DecorateQueryProvider);

/**
* Take text from the user and make it into a query object
Expand All @@ -13,7 +13,7 @@ export default function GetQueryFromUser(es, Private) {
return decorateQuery({query_string: {query: text}});
}

var matchAll = getQueryStringQuery('*');
let matchAll = getQueryStringQuery('*');

// If we get an empty object, treat it as a *
if (_.isObject(text)) {
Expand Down
4 changes: 2 additions & 2 deletions src/ui/public/parse_query/parse_query.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import uiModules from 'ui/modules';
uiModules
.get('kibana')
.directive('parseQuery', function (Private) {
var fromUser = Private(ParseQueryLibFromUserProvider);
let fromUser = Private(ParseQueryLibFromUserProvider);

return {
restrict: 'A',
Expand All @@ -13,7 +13,7 @@ uiModules
'ngModel': '='
},
link: function ($scope, elem, attr, ngModel) {
var init = function () {
let init = function () {
$scope.ngModel = fromUser($scope.ngModel);
};

Expand Down
54 changes: 27 additions & 27 deletions src/ui/public/persisted_state/persisted_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import SimpleEmitter from 'ui/utils/simple_emitter';
import EventsProvider from 'ui/events';

export default function (Private) {
var Events = Private(EventsProvider);
let Events = Private(EventsProvider);

function validateParent(parent, path) {
if (path.length <= 0) {
Expand All @@ -17,7 +17,7 @@ export default function (Private) {
}

function validateValue(value) {
var msg = 'State value must be a plain object';
let msg = 'State value must be a plain object';
if (!value) return;
if (!_.isPlainObject(value)) throw new errors.PersistedStateError(msg);
}
Expand Down Expand Up @@ -73,21 +73,21 @@ export default function (Private) {
};

PersistedState.prototype.set = function (key, value) {
var params = prepSetParams(key, value, this._path);
var val = this._set(params.key, params.value);
let params = prepSetParams(key, value, this._path);
let val = this._set(params.key, params.value);
this.emit('set');
return val;
};

PersistedState.prototype.setSilent = function (key, value) {
var params = prepSetParams(key, value, this._path);
let params = prepSetParams(key, value, this._path);
return this._set(params.key, params.value, true);
};

PersistedState.prototype.reset = function (path) {
var keyPath = this._getIndex(path);
var origValue = _.get(this._defaultState, keyPath);
var currentValue = _.get(this._mergedState, keyPath);
let keyPath = this._getIndex(path);
let origValue = _.get(this._defaultState, keyPath);
let currentValue = _.get(this._mergedState, keyPath);

if (_.isUndefined(origValue)) {
this._cleanPath(path, this._mergedState);
Expand All @@ -108,7 +108,7 @@ export default function (Private) {
};

PersistedState.prototype.removeChild = function (path) {
var origValue = _.get(this._defaultState, this._getIndex(path));
let origValue = _.get(this._defaultState, this._getIndex(path));

if (_.isUndefined(origValue)) {
this.reset(path);
Expand Down Expand Up @@ -139,19 +139,19 @@ export default function (Private) {
};

PersistedState.prototype._getPartialIndex = function (key) {
var keyPath = this._getIndex(key);
let keyPath = this._getIndex(key);
return keyPath.slice(this._path.length);
};

PersistedState.prototype._cleanPath = function (path, stateTree) {
var partialPath = this._getPartialIndex(path);
var remove = true;
let partialPath = this._getPartialIndex(path);
let remove = true;

// recursively delete value tree, when no other keys exist
while (partialPath.length > 0) {
var lastKey = partialPath.splice(partialPath.length - 1, 1)[0];
var statePath = this._path.concat(partialPath);
var stateVal = statePath.length > 0 ? _.get(stateTree, statePath) : stateTree;
let lastKey = partialPath.splice(partialPath.length - 1, 1)[0];
let statePath = this._path.concat(partialPath);
let stateVal = statePath.length > 0 ? _.get(stateTree, statePath) : stateTree;

// if stateVal isn't an object, do nothing
if (!_.isPlainObject(stateVal)) return;
Expand All @@ -162,13 +162,13 @@ export default function (Private) {
};

PersistedState.prototype._getDefault = function () {
var def = (this._hasPath()) ? undefined : {};
let def = (this._hasPath()) ? undefined : {};
return (this._parent ? this.get() : def);
};

PersistedState.prototype._setPath = function (path) {
var isString = _.isString(path);
var isArray = _.isArray(path);
let isString = _.isString(path);
let isArray = _.isArray(path);

if (!isString && !isArray) return [];
return (isString) ? [this._getIndex(path)] : path;
Expand Down Expand Up @@ -196,11 +196,11 @@ export default function (Private) {
};

PersistedState.prototype._set = function (key, value, silent, initialChildState) {
var self = this;
var stateChanged = false;
var initialState = !this._initialized;
var keyPath = this._getIndex(key);
var hasKeyPath = keyPath.length > 0;
let self = this;
let stateChanged = false;
let initialState = !this._initialized;
let keyPath = this._getIndex(key);
let hasKeyPath = keyPath.length > 0;

// if this is the initial state value, save value as the default
if (initialState) {
Expand All @@ -226,7 +226,7 @@ export default function (Private) {
}
} else {
// check for changes at path, emit an event when different
var curVal = hasKeyPath ? this.get(keyPath) : this._mergedState;
let curVal = hasKeyPath ? this.get(keyPath) : this._mergedState;
stateChanged = !_.isEqual(curVal, value);

if (!initialChildState) {
Expand All @@ -243,11 +243,11 @@ export default function (Private) {
}

// update the merged state value
var targetObj = this._mergedState || _.cloneDeep(this._defaultState);
var sourceObj = _.merge({}, this._defaultChildState, this._changedState);
let targetObj = this._mergedState || _.cloneDeep(this._defaultState);
let sourceObj = _.merge({}, this._defaultChildState, this._changedState);

// handler arguments are (targetValue, sourceValue, key, target, source)
var mergeMethod = function (targetValue, sourceValue, mergeKey) {
let mergeMethod = function (targetValue, sourceValue, mergeKey) {
// if not initial state, skip default merge method (ie. return value, see note below)
if (!initialState && !initialChildState && _.isEqual(keyPath, self._getIndex(mergeKey))) {
// use the sourceValue or fall back to targetValue
Expand Down
24 changes: 12 additions & 12 deletions src/ui/public/private/private.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import uiModules from 'ui/modules';
* ```js
* define(function (require) {
* return function ServerHealthProvider(Private, Promise) {
* var ping = Private(require('ui/ping'));
* let ping = Private(require('ui/ping'));
* return {
* check: Promise.method(function () {
* var attempts = 0;
* let attempts = 0;
* return (function attempt() {
* attempts += 1;
* return ping.ping()
Expand Down Expand Up @@ -87,19 +87,19 @@ import uiModules from 'ui/modules';
*/


var nextId = _.partial(_.uniqueId, 'privateProvider#');
let nextId = _.partial(_.uniqueId, 'privateProvider#');

function name(fn) {
return fn.name || fn.toString().split('\n').shift();
}

uiModules.get('kibana')
.provider('Private', function () {
var provider = this;
let provider = this;

// one cache/swaps per Provider
var cache = {};
var swaps = {};
let cache = {};
let swaps = {};

// return the uniq id for this function
function identify(fn) {
Expand All @@ -117,15 +117,15 @@ uiModules.get('kibana')
};

provider.swap = function (fn, prov) {
var id = identify(fn);
let id = identify(fn);
swaps[id] = prov;
};

provider.$get = ['$injector', function PrivateFactory($injector) {

// prevent circular deps by tracking where we came from
var privPath = [];
var pathToString = function () {
let privPath = [];
let pathToString = function () {
return privPath.map(name).join(' -> ');
};

Expand All @@ -140,8 +140,8 @@ uiModules.get('kibana')

privPath.push(prov);

var context = {};
var instance = $injector.invoke(prov, context, locals);
let context = {};
let instance = $injector.invoke(prov, context, locals);
if (!_.isObject(instance)) instance = context;

privPath.pop();
Expand All @@ -167,7 +167,7 @@ uiModules.get('kibana')

// main api, get the appropriate instance for a provider
function Private(prov) {
var id = identify(prov);
let id = identify(prov);
let $delegateId;
let $delegateProv;

Expand Down
14 changes: 7 additions & 7 deletions src/ui/public/promises/promises.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import _ from 'lodash';
import uiModules from 'ui/modules';

var module = uiModules.get('kibana');
let module = uiModules.get('kibana');

// Provides a tiny subset of the excelent API from
// bluebird, reimplemented using the $q service
module.service('Promise', function ($q, $timeout) {
function Promise(fn) {
if (typeof this === 'undefined') throw new Error('Promise constructor must be called with "new"');

var defer = $q.defer();
let defer = $q.defer();
try {
fn(defer.resolve, defer.reject);
} catch (e) {
Expand All @@ -20,12 +20,12 @@ module.service('Promise', function ($q, $timeout) {

Promise.all = Promise.props = $q.all;
Promise.resolve = function (val) {
var defer = $q.defer();
let defer = $q.defer();
defer.resolve(val);
return defer.promise;
};
Promise.reject = function (reason) {
var defer = $q.defer();
let defer = $q.defer();
defer.reject(reason);
return defer.promise;
};
Expand All @@ -36,7 +36,7 @@ module.service('Promise', function ($q, $timeout) {
};
Promise.method = function (fn) {
return function () {
var args = Array.prototype.slice.call(arguments);
let args = Array.prototype.slice.call(arguments);
return Promise.try(fn, args, this);
};
};
Expand Down Expand Up @@ -64,7 +64,7 @@ module.service('Promise', function ($q, $timeout) {
return obj && typeof obj.then === 'function';
};
Promise.halt = _.once(function () {
var promise = new Promise();
let promise = new Promise();
promise.then = _.constant(promise);
promise.catch = _.constant(promise);
return promise;
Expand Down Expand Up @@ -155,7 +155,7 @@ module.factory('PromiseEmitter', function (Promise) {
* @return {Promise}
*/
function PromiseEmitter(fn, handler) {
var prom = new Promise(fn);
let prom = new Promise(fn);

if (!handler) return prom;

Expand Down
10 changes: 5 additions & 5 deletions src/ui/public/reflow_watcher/reflow_watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import _ from 'lodash';
import EventsProvider from 'ui/events';
export default function ReflowWatcherService(Private, $rootScope, $http) {

var EventEmitter = Private(EventsProvider);
var $body = $(document.body);
var $window = $(window);
let EventEmitter = Private(EventsProvider);
let $body = $(document.body);
let $window = $(window);

var MOUSE_EVENTS = 'mouseup';
var WINDOW_EVENTS = 'resize';
let MOUSE_EVENTS = 'mouseup';
let WINDOW_EVENTS = 'resize';

_.class(ReflowWatcher).inherits(EventEmitter);
/**
Expand Down
Loading

0 comments on commit cd412ee

Please sign in to comment.