mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
changed var to const (#13061)
This commit is contained in:
committed by
Torkel Ödegaard
parent
9423e3e124
commit
5e0d0c5816
@@ -52,9 +52,9 @@ function applied(fn, scope) {
|
||||
if (fn.wrappedInApply) {
|
||||
return fn;
|
||||
}
|
||||
var wrapped: any = function() {
|
||||
var args = arguments;
|
||||
var phase = scope.$root.$$phase;
|
||||
const wrapped: any = function() {
|
||||
const args = arguments;
|
||||
const phase = scope.$root.$$phase;
|
||||
if (phase === '$apply' || phase === '$digest') {
|
||||
return fn.apply(null, args);
|
||||
} else {
|
||||
@@ -81,8 +81,8 @@ function applied(fn, scope) {
|
||||
*/
|
||||
function applyFunctions(obj, scope, propsConfig?) {
|
||||
return Object.keys(obj || {}).reduce(function(prev, key) {
|
||||
var value = obj[key];
|
||||
var config = (propsConfig || {})[key] || {};
|
||||
const value = obj[key];
|
||||
const config = (propsConfig || {})[key] || {};
|
||||
/**
|
||||
* wrap functions in a function that ensures they are scope.$applied
|
||||
* ensures that when function is called from a React component
|
||||
@@ -103,14 +103,14 @@ function applyFunctions(obj, scope, propsConfig?) {
|
||||
* If watchDepth attribute is NOT reference or collection, watchDepth defaults to deep watching by value
|
||||
*/
|
||||
function watchProps(watchDepth, scope, watchExpressions, listener) {
|
||||
var supportsWatchCollection = angular.isFunction(scope.$watchCollection);
|
||||
var supportsWatchGroup = angular.isFunction(scope.$watchGroup);
|
||||
const supportsWatchCollection = angular.isFunction(scope.$watchCollection);
|
||||
const supportsWatchGroup = angular.isFunction(scope.$watchGroup);
|
||||
|
||||
var watchGroupExpressions = [];
|
||||
const watchGroupExpressions = [];
|
||||
|
||||
watchExpressions.forEach(function(expr) {
|
||||
var actualExpr = getPropExpression(expr);
|
||||
var exprWatchDepth = getPropWatchDepth(watchDepth, expr);
|
||||
const actualExpr = getPropExpression(expr);
|
||||
const exprWatchDepth = getPropWatchDepth(watchDepth, expr);
|
||||
|
||||
if (exprWatchDepth === 'collection' && supportsWatchCollection) {
|
||||
scope.$watchCollection(actualExpr, listener);
|
||||
@@ -156,7 +156,7 @@ function getPropExpression(prop) {
|
||||
|
||||
// find the normalized attribute knowing that React props accept any type of capitalization
|
||||
function findAttribute(attrs, propName) {
|
||||
var index = Object.keys(attrs).filter(function(attr) {
|
||||
const index = Object.keys(attrs).filter(function(attr) {
|
||||
return attr.toLowerCase() === propName.toLowerCase();
|
||||
})[0];
|
||||
return attrs[index];
|
||||
@@ -164,7 +164,7 @@ function findAttribute(attrs, propName) {
|
||||
|
||||
// get watch depth of prop (string or array)
|
||||
function getPropWatchDepth(defaultWatch, prop) {
|
||||
var customWatchDepth = Array.isArray(prop) && angular.isObject(prop[1]) && prop[1].watchDepth;
|
||||
const customWatchDepth = Array.isArray(prop) && angular.isObject(prop[1]) && prop[1].watchDepth;
|
||||
return customWatchDepth || defaultWatch;
|
||||
}
|
||||
|
||||
@@ -186,16 +186,16 @@ function getPropWatchDepth(defaultWatch, prop) {
|
||||
// }
|
||||
// }));
|
||||
//
|
||||
var reactComponent = function($injector) {
|
||||
const reactComponent = function($injector) {
|
||||
return {
|
||||
restrict: 'E',
|
||||
replace: true,
|
||||
link: function(scope, elem, attrs) {
|
||||
var reactComponent = getReactComponent(attrs.name, $injector);
|
||||
const reactComponent = getReactComponent(attrs.name, $injector);
|
||||
|
||||
var renderMyComponent = function() {
|
||||
var scopeProps = scope.$eval(attrs.props);
|
||||
var props = applyFunctions(scopeProps, scope);
|
||||
const renderMyComponent = function() {
|
||||
const scopeProps = scope.$eval(attrs.props);
|
||||
const props = applyFunctions(scopeProps, scope);
|
||||
|
||||
renderComponent(reactComponent, props, scope, elem);
|
||||
};
|
||||
@@ -243,24 +243,24 @@ var reactComponent = function($injector) {
|
||||
//
|
||||
// <hello name="name"/>
|
||||
//
|
||||
var reactDirective = function($injector) {
|
||||
const reactDirective = function($injector) {
|
||||
return function(reactComponentName, props, conf, injectableProps) {
|
||||
var directive = {
|
||||
const directive = {
|
||||
restrict: 'E',
|
||||
replace: true,
|
||||
link: function(scope, elem, attrs) {
|
||||
var reactComponent = getReactComponent(reactComponentName, $injector);
|
||||
const reactComponent = getReactComponent(reactComponentName, $injector);
|
||||
|
||||
// if props is not defined, fall back to use the React component's propTypes if present
|
||||
props = props || Object.keys(reactComponent.propTypes || {});
|
||||
|
||||
// for each of the properties, get their scope value and set it to scope.props
|
||||
var renderMyComponent = function() {
|
||||
var scopeProps = {},
|
||||
config = {};
|
||||
const renderMyComponent = function() {
|
||||
var scopeProps = {};
|
||||
const config = {};
|
||||
|
||||
props.forEach(function(prop) {
|
||||
var propName = getPropName(prop);
|
||||
const propName = getPropName(prop);
|
||||
scopeProps[propName] = scope.$eval(findAttribute(attrs, propName));
|
||||
config[propName] = getPropConfig(prop);
|
||||
});
|
||||
@@ -272,7 +272,7 @@ var reactDirective = function($injector) {
|
||||
|
||||
// watch each property name and trigger an update whenever something changes,
|
||||
// to update scope.props with new values
|
||||
var propExpressions = props.map(function(prop) {
|
||||
const propExpressions = props.map(function(prop) {
|
||||
return Array.isArray(prop) ? [attrs[getPropName(prop)], getPropConfig(prop)] : attrs[prop];
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user