Change gr-reporting to class object
Gr-reporting is singleton and each element that needs to report can
get its instance. A class implementation is cleaner and it's not
creating unnecessary dom elements.
Added mock of gr reporting enables easier way to test functions with
gr reporting and it is also checking basic types of parameters.
Change-Id: I039fce6dbcfd4956ff2c29805b3be7955b5f40ac
diff --git a/polygerrit-ui/app/elements/core/gr-router/gr-router.js b/polygerrit-ui/app/elements/core/gr-router/gr-router.js
index 11465ba..0635fb9 100644
--- a/polygerrit-ui/app/elements/core/gr-router/gr-router.js
+++ b/polygerrit-ui/app/elements/core/gr-router/gr-router.js
@@ -17,7 +17,6 @@
import '../../../scripts/bundled-polymer.js';
import '../../shared/gr-rest-api-interface/gr-rest-api-interface.js';
-import '../gr-reporting/gr-reporting.js';
import {mixinBehaviors} from '@polymer/polymer/lib/legacy/class.js';
import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-listeners.js';
import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin.js';
@@ -28,6 +27,7 @@
import {PatchSetBehavior} from '../../../behaviors/gr-patch-set-behavior/gr-patch-set-behavior.js';
import {URLEncodingBehavior} from '../../../behaviors/gr-url-encoding-behavior/gr-url-encoding-behavior.js';
import {GerritNav} from '../gr-navigation/gr-navigation.js';
+import {appContext} from '../../../services/app-context.js';
const RoutePattern = {
ROOT: '/',
@@ -210,10 +210,8 @@
// Setup listeners outside of the router component initialization.
(function() {
- const reporting = document.createElement('gr-reporting');
-
window.addEventListener('WebComponentsReady', () => {
- reporting.timeEnd('WebComponentsReady');
+ appContext.reportingService.timeEnd('WebComponentsReady');
});
})();
@@ -247,6 +245,11 @@
};
}
+ constructor() {
+ super();
+ this.reporting = appContext.reportingService;
+ }
+
start() {
if (!this._app) { return; }
this._startRouter();
@@ -716,7 +719,7 @@
(ctx, next) => this._loadUserMiddleware(ctx, next),
(ctx, next) => this._queryStringMiddleware(ctx, next),
data => {
- this.$.reporting.locationChanged(handlerName);
+ this.reporting.locationChanged(handlerName);
const promise = opt_authRedirect ?
this._redirectIfNotLoggedIn(data) : Promise.resolve();
promise.then(() => { this[handlerName](data); });
@@ -738,7 +741,7 @@
page.exit('*', (ctx, next) => {
if (!this._isRedirecting) {
- this.$.reporting.beforeLocationChanged();
+ this.reporting.beforeLocationChanged();
}
this._isRedirecting = false;
this._isInitialLoad = false;
@@ -1089,7 +1092,7 @@
project,
dashboard: decodeURIComponent(data.params[1]),
});
- this.$.reporting.setRepoName(project);
+ this.reporting.setRepoName(project);
}
_handleGroupInfoRoute(data) {
@@ -1170,7 +1173,7 @@
detail: GerritNav.RepoDetailView.COMMANDS,
repo,
});
- this.$.reporting.setRepoName(repo);
+ this.reporting.setRepoName(repo);
}
_handleRepoAccessRoute(data) {
@@ -1180,7 +1183,7 @@
detail: GerritNav.RepoDetailView.ACCESS,
repo,
});
- this.$.reporting.setRepoName(repo);
+ this.reporting.setRepoName(repo);
}
_handleRepoDashboardsRoute(data) {
@@ -1190,7 +1193,7 @@
detail: GerritNav.RepoDetailView.DASHBOARDS,
repo,
});
- this.$.reporting.setRepoName(repo);
+ this.reporting.setRepoName(repo);
}
_handleBranchListOffsetRoute(data) {
@@ -1296,7 +1299,7 @@
view: GerritNav.View.REPO,
repo,
});
- this.$.reporting.setRepoName(repo);
+ this.reporting.setRepoName(repo);
}
_handlePluginListOffsetRoute(data) {
@@ -1359,7 +1362,7 @@
queryMap: ctx.queryMap,
};
- this.$.reporting.setRepoName(params.project);
+ this.reporting.setRepoName(params.project);
this._redirectOrNavigate(params);
}
@@ -1379,7 +1382,7 @@
params.leftSide = address.leftSide;
params.lineNum = address.lineNum;
}
- this.$.reporting.setRepoName(params.project);
+ this.reporting.setRepoName(params.project);
this._redirectOrNavigate(params);
}
@@ -1430,7 +1433,7 @@
lineNum: ctx.hash,
view: GerritNav.View.EDIT,
});
- this.$.reporting.setRepoName(project);
+ this.reporting.setRepoName(project);
}
_handleChangeEditRoute(ctx) {
@@ -1443,7 +1446,7 @@
view: GerritNav.View.CHANGE,
edit: true,
});
- this.$.reporting.setRepoName(project);
+ this.reporting.setRepoName(project);
}
/**