Skip to content

Commit

Permalink
Cleaned up and perf mixin nits
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesdaniels committed Oct 12, 2019
1 parent ccd15e4 commit d5d9f0d
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ package.json.ember-try
addon/**/*.js
app/**/*.js
adapters/*.d.ts
mixins/*.d.ts
authenticators/*.d.ts
authorizers/*.d.ts
serializers/*.d.ts
Expand Down
30 changes: 14 additions & 16 deletions addon/mixins/performance-route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { inject as service } from '@ember/service';
import Mixin from '@ember/object/mixin';
import { performance } from 'firebase';
import { Promise, reject } from 'rsvp';
import { reject } from 'rsvp';

export default Mixin.create({
firebaseApp: service('firebase-app'),
Expand All @@ -15,28 +15,26 @@ export default Mixin.create({
if (this.toString().indexOf("@route:application::") > 0) { throw "PerformanceRouteMixin does not work correctly in the application route" }
},
beforeModel() {
// TODO promise proxy
this.set('trace', this.get('firebaseApp').performance().then(perf => {
const trace = perf.trace(`${this.toString()}:didTransition`);
trace.start();
return trace;
}));
},
routeDidChange() {
const router = this.get('router');
router.removeObserver('currentRoute', this, this.routeDidChange);
const screen_name = router.currentRoute.name;
this.get('trace').then(trace => {
trace.putAttribute('url', router.currentURL);
// TODO allow name to be set
(trace as any).name = `${screen_name}:didTransition`;
trace.stop();
this.set('trace', reject());
});
},
afterModel() {
const tracePromise = this.get('trace')!;
const router = this.get('router');
tracePromise.then((trace:performance.Trace|undefined) => {
// TODO figure out how to disconnect the routeDidChange listener
router.on('routeDidChange', () => {
if (trace) {
const screen_name = router.currentRouteName;
trace.putAttribute('url', router.currentURL);
(trace as any).name = `${screen_name}:didTransition`;
trace.stop();
this.set('trace', reject());
trace = undefined;
}
});
})
router.addObserver('currentRoute', this, this.routeDidChange);
}
});
5 changes: 0 additions & 5 deletions initializers/emberfire.d.ts

This file was deleted.

Empty file added mixins/.gitkeep
Empty file.
7 changes: 0 additions & 7 deletions mixins/analytics-route.d.ts

This file was deleted.

7 changes: 0 additions & 7 deletions mixins/performance-route.d.ts

This file was deleted.

7 changes: 0 additions & 7 deletions mixins/realtime-route.d.ts

This file was deleted.

0 comments on commit d5d9f0d

Please sign in to comment.