-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d34bf2f
commit 755ab85
Showing
15 changed files
with
232 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './performance.spec'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './public_api'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "@angular/fire/performance", | ||
"version": "ANGULARFIRE2_VERSION", | ||
"description": "The performance monitoring module", | ||
"main": "../bundles/performance.umd.js", | ||
"module": "index.js", | ||
"es2015": "./es2015/index.js", | ||
"keywords": [ | ||
"angular", | ||
"firebase", | ||
"rxjs" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/angular/angularfire2.git" | ||
}, | ||
"author": "angular,firebase", | ||
"license": "MIT", | ||
"peerDependencies": { | ||
"@angular/fire": "ANGULARFIRE2_VERSION", | ||
"@angular/common": "ANGULAR_VERSION", | ||
"@angular/core": "ANGULAR_VERSION", | ||
"@angular/platform-browser": "ANGULAR_VERSION", | ||
"@angular/platform-browser-dynamic": "ANGULAR_VERSION", | ||
"@firebase/app": "FIREBASE_APP_VERSION", | ||
"@firebase/messaging": "FIREBASE_MESSAGING_VERSION", | ||
"rxjs": "RXJS_VERSION", | ||
"zone.js": "ZONEJS_VERSION" | ||
}, | ||
"typings": "index.d.ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { AngularFirePerformance } from './performance'; | ||
|
||
import 'firebase/perf'; | ||
|
||
@NgModule({ | ||
providers: [ AngularFirePerformance ] | ||
}) | ||
export class AngularFirePerformanceModule { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { Injectable, Inject, Optional, NgZone, ApplicationRef } from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
import { filter, tap, take } from 'rxjs/operators'; | ||
import { FirebaseOptions, FirebaseAppConfig } from '@angular/fire'; | ||
import { FirebaseOptionsToken, FirebaseNameOrConfigToken, _firebaseAppFactory } from '@angular/fire'; | ||
import { PerformanceController } from '@firebase/performance/dist/src/controllers/perf'; | ||
|
||
export type TraceOptions = { | ||
metrics: {[key:string]: number}, | ||
attributes?:{[key:string]:string}, | ||
attribute$?:{[key:string]:Observable<string>}, | ||
incrementMetric$:{[key:string]: Observable<number|void|null|undefined>}, | ||
metric$?:{[key:string]: Observable<number>} | ||
}; | ||
|
||
@Injectable() | ||
export class AngularFirePerformance { | ||
|
||
performance: PerformanceController; | ||
|
||
constructor( | ||
@Inject(FirebaseOptionsToken) options:FirebaseOptions, | ||
@Optional() @Inject(FirebaseNameOrConfigToken) nameOrConfig:string|FirebaseAppConfig|null|undefined, | ||
appRef: ApplicationRef, | ||
private zone: NgZone | ||
) { | ||
|
||
this.performance = zone.runOutsideAngular(() => { | ||
const app = _firebaseAppFactory(options, nameOrConfig); | ||
return app.performance(); | ||
}); | ||
|
||
// TODO detirmine more built in metrics | ||
appRef.isStable.pipe( | ||
this.traceComplete('isStable'), | ||
filter(it => it), | ||
take(1) | ||
).subscribe(); | ||
|
||
} | ||
|
||
trace$ = (name:string, options?: TraceOptions) => new Observable<void>(emitter => | ||
this.zone.runOutsideAngular(() => { | ||
const trace = this.performance.trace(name); | ||
options && options.metrics && Object.keys(options.metrics).forEach(metric => { | ||
trace.putMetric(metric, options!.metrics![metric]) | ||
}); | ||
options && options.attributes && Object.keys(options.attributes).forEach(attribute => { | ||
trace.putAttribute(attribute, options!.attributes![attribute]) | ||
}); | ||
const attributeSubscriptions = options && options.attribute$ ? Object.keys(options.attribute$).map(attribute => | ||
options!.attribute$![attribute].subscribe(next => trace.putAttribute(attribute, next)) | ||
) : []; | ||
const metricSubscriptions = options && options.metric$ ? Object.keys(options.metric$).map(metric => | ||
options!.metric$![metric].subscribe(next => trace.putMetric(metric, next)) | ||
) : []; | ||
const incrementOnSubscriptions = options && options.incrementMetric$ ? Object.keys(options.incrementMetric$).map(metric => | ||
options!.incrementMetric$![metric].subscribe(next => trace.incrementMetric(metric, next || undefined)) | ||
) : []; | ||
emitter.next(trace.start()); | ||
return { unsubscribe: () => { | ||
trace.stop(); | ||
metricSubscriptions.forEach(m => m.unsubscribe()); | ||
incrementOnSubscriptions.forEach(m => m.unsubscribe()); | ||
attributeSubscriptions.forEach(m => m.unsubscribe()); | ||
}}; | ||
}) | ||
); | ||
|
||
traceUntil = <T=any>(name:string, test: (a:T) => boolean, options?: TraceOptions) => (source$: Observable<T>) => { | ||
const traceSubscription = this.trace$(name, options).subscribe(); | ||
return source$.pipe( | ||
tap(a => { if (test(a)) { traceSubscription.unsubscribe() }}) | ||
) | ||
}; | ||
|
||
traceComplete = <T=any>(name:string, options?: TraceOptions) => (source$: Observable<T>) => { | ||
const traceSubscription = this.trace$(name, options).subscribe(); | ||
return source$.pipe( | ||
tap( | ||
() => {}, | ||
() => {}, | ||
() => traceSubscription.unsubscribe() | ||
) | ||
) | ||
}; | ||
|
||
trace = <T=any>(name:string, options?: TraceOptions) => (source$: Observable<T>) => { | ||
const traceSubscription = this.trace$(name, options).subscribe(); | ||
return source$.pipe( | ||
tap( | ||
() => traceSubscription.unsubscribe(), | ||
() => {}, | ||
() => traceSubscription.unsubscribe() | ||
) | ||
) | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './performance'; | ||
export * from './performance.module'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
export const COMMON_CONFIG = { | ||
apiKey: "AIzaSyBVSy3YpkVGiKXbbxeK0qBnu3-MNZ9UIjA", | ||
authDomain: "angularfire2-test.firebaseapp.com", | ||
databaseURL: "https://angularfire2-test.firebaseio.com", | ||
storageBucket: "angularfire2-test.appspot.com", | ||
messagingSenderId: "920323787688" | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"experimentalDecorators": true, | ||
"emitDecoratorMetadata": true, | ||
"module": "es2015", | ||
"target": "es2015", | ||
"noImplicitAny": false, | ||
"outDir": "../../dist/packages-dist/performance/es2015", | ||
"rootDir": ".", | ||
"sourceMap": true, | ||
"inlineSources": true, | ||
"declaration": false, | ||
"removeComments": true, | ||
"strictNullChecks": true, | ||
"lib": ["es2015", "dom", "es2015.promise", "es2015.collection", "es2015.iterable"], | ||
"skipLibCheck": true, | ||
"moduleResolution": "node", | ||
"paths": { | ||
"@angular/fire": ["../../dist/packages-dist"] | ||
} | ||
}, | ||
"files": [ | ||
"index.ts", | ||
"../../node_modules/zone.js/dist/zone.js.d.ts" | ||
], | ||
"angularCompilerOptions": { | ||
"skipTemplateCodegen": true, | ||
"strictMetadataEmit": true, | ||
"enableSummariesForJit": false | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"extends": "./tsconfig-build.json", | ||
"compilerOptions": { | ||
"target": "es5", | ||
"outDir": "../../dist/packages-dist/performance", | ||
"declaration": true | ||
}, | ||
"files": [ | ||
"public_api.ts", | ||
"../../node_modules/zone.js/dist/zone.js.d.ts" | ||
], | ||
"angularCompilerOptions": { | ||
"skipTemplateCodegen": true, | ||
"strictMetadataEmit": true, | ||
"enableSummariesForJit": false, | ||
"flatModuleOutFile": "index.js", | ||
"flatModuleId": "@angular/fire/performance" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"extends": "./tsconfig-esm.json", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"paths": { | ||
"@angular/fire": ["../../dist/packages-dist"] | ||
} | ||
}, | ||
"files": [ | ||
"index.spec.ts", | ||
"../../node_modules/zone.js/dist/zone.js.d.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
755ab85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍