Skip to content

Commit

Permalink
chore(lint): Use EMPTY for rxjs
Browse files Browse the repository at this point in the history
  • Loading branch information
NothingEverHappens committed Apr 28, 2020
1 parent 7cf0804 commit 6246b16
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/analytics/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Inject, Injectable, InjectionToken, NgZone, Optional, PLATFORM_ID } from '@angular/core';
import { empty, Observable, of } from 'rxjs';
import { EMPTY, Observable, of } from 'rxjs';
import { isPlatformBrowser } from '@angular/common';
import { map, observeOn, shareReplay, switchMap, tap } from 'rxjs/operators';
import { FIREBASE_APP_NAME, FIREBASE_OPTIONS, FirebaseAppConfig, FirebaseOptions, ɵAngularFireSchedulers, ɵfirebaseAppFactory, ɵlazySDKProxy, ɵPromiseProxy } from '@angular/fire';
Expand Down Expand Up @@ -80,7 +80,7 @@ export class AngularFireAnalytics {
if (!analytics) {
analytics = of(undefined).pipe(
observeOn(new ɵAngularFireSchedulers(zone).outsideAngular),
switchMap(() => isPlatformBrowser(platformId) ? import('firebase/analytics') : empty()),
switchMap(() => isPlatformBrowser(platformId) ? import('firebase/analytics') : EMPTY),
map(() => ɵfirebaseAppFactory(options, zone, nameOrConfig)),
map(app => app.analytics()),
tap(analytics => {
Expand Down
18 changes: 10 additions & 8 deletions src/messaging/messaging.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
import { Inject, Injectable, NgZone, Optional, PLATFORM_ID } from '@angular/core';
import { messaging } from 'firebase/app';
import { empty, Observable, of, throwError } from 'rxjs';
import { EMPTY, Observable, of, throwError } from 'rxjs';
import { catchError, concat, defaultIfEmpty, map, mergeMap, observeOn, switchMap } from 'rxjs/operators';
import { FIREBASE_APP_NAME, FIREBASE_OPTIONS, FirebaseAppConfig, FirebaseOptions, ɵAngularFireSchedulers, ɵfirebaseAppFactory, ɵlazySDKProxy, ɵPromiseProxy } from '@angular/fire';
import { isPlatformServer } from '@angular/common';

export interface AngularFireMessaging extends Omit<ɵPromiseProxy<messaging.Messaging>, 'deleteToken'|'getToken'|'requestPermission'> {}
export interface AngularFireMessaging extends Omit<ɵPromiseProxy<messaging.Messaging>, 'deleteToken' | 'getToken' | 'requestPermission'> {
}

@Injectable({
providedIn: 'any'
})
export class AngularFireMessaging {

public readonly requestPermission: Observable<void>;
public readonly getToken: Observable<string|null>;
public readonly tokenChanges: Observable<string|null>;
public readonly getToken: Observable<string | null>;
public readonly tokenChanges: Observable<string | null>;
public readonly messages: Observable<{}>;
public readonly requestToken: Observable<string|null>;
public readonly requestToken: Observable<string | null>;
public readonly deleteToken: (token: string) => Observable<boolean>;

constructor(
@Inject(FIREBASE_OPTIONS) options: FirebaseOptions,
@Optional() @Inject(FIREBASE_APP_NAME) nameOrConfig: string|FirebaseAppConfig|null|undefined,
@Optional() @Inject(FIREBASE_APP_NAME) nameOrConfig: string | FirebaseAppConfig | null | undefined,
// tslint:disable-next-line:ban-types
@Inject(PLATFORM_ID) platformId: Object,
zone: NgZone
) {
const schedulers = new ɵAngularFireSchedulers(zone);

const messaging = of(undefined).pipe(
observeOn(schedulers.outsideAngular),
switchMap(() => isPlatformServer(platformId) ? empty() : import('firebase/messaging')),
switchMap(() => isPlatformServer(platformId) ? EMPTY : import('firebase/messaging')),
map(() => ɵfirebaseAppFactory(options, zone, nameOrConfig)),
map(app => app.messaging())
);
Expand All @@ -38,7 +40,7 @@ export class AngularFireMessaging {

this.requestPermission = messaging.pipe(
observeOn(schedulers.outsideAngular),
switchMap(messaging => messaging.requestPermission()),
switchMap(messaging => messaging.requestPermission())
);

} else {
Expand Down
4 changes: 2 additions & 2 deletions src/performance/performance.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Inject, Injectable, InjectionToken, NgZone, Optional, PLATFORM_ID } from '@angular/core';
import { EMPTY, empty, Observable, of, Subscription } from 'rxjs';
import { EMPTY, Observable, of, Subscription } from 'rxjs';
import { map, shareReplay, switchMap, tap } from 'rxjs/operators';
import { performance } from 'firebase/app';
import { FirebaseApp, ɵlazySDKProxy, ɵPromiseProxy } from '@angular/fire';
Expand Down Expand Up @@ -65,7 +65,7 @@ const trace$ = (traceId: string) => {
};
});
} else {
return empty();
return EMPTY;
}
};

Expand Down
10 changes: 6 additions & 4 deletions src/remote-config/remote-config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Inject, Injectable, InjectionToken, NgZone, Optional, PLATFORM_ID } from '@angular/core';
import { concat, empty, MonoTypeOperatorFunction, Observable, of, OperatorFunction, pipe } from 'rxjs';
import { concat, EMPTY, MonoTypeOperatorFunction, Observable, of, OperatorFunction, pipe } from 'rxjs';
import { debounceTime, distinctUntilChanged, filter, groupBy, map, mergeMap, observeOn, scan, shareReplay, startWith, switchMap, tap, withLatestFrom } from 'rxjs/operators';
import { FIREBASE_APP_NAME, FIREBASE_OPTIONS, FirebaseAppConfig, FirebaseOptions, ɵAngularFireSchedulers, ɵfirebaseAppFactory, ɵlazySDKProxy, ɵPromiseProxy } from '@angular/fire';
import { remoteConfig } from 'firebase/app';
Expand All @@ -14,6 +14,7 @@ export const DEFAULTS = new InjectionToken<ConfigTemplate>('angularfire2.remoteC

export interface AngularFireRemoteConfig extends ɵPromiseProxy<remoteConfig.RemoteConfig> {
}

// TODO look into the types here, I don't like the anys
const proxyAll = (observable: Observable<Parameter[]>, as: 'numbers' | 'booleans' | 'strings') => new Proxy(
observable.pipe(mapToObject(as as any)), {
Expand Down Expand Up @@ -90,7 +91,7 @@ export class AngularFireRemoteConfig {

const remoteConfig$ = of(undefined).pipe(
observeOn(schedulers.outsideAngular),
switchMap(() => isPlatformBrowser(platformId) ? import('firebase/remote-config') : empty()),
switchMap(() => isPlatformBrowser(platformId) ? import('firebase/remote-config') : EMPTY),
map(() => ɵfirebaseAppFactory(options, zone, nameOrConfig)),
map(app => app.remoteConfig()),
tap(rc => {
Expand Down Expand Up @@ -183,8 +184,6 @@ const scanToParametersArray = (
}, [] as Array<Parameter>)
);

const AS_TO_FN = { strings: 'asString', numbers: 'asNumber', booleans: 'asBoolean' };
const STATIC_VALUES = { numbers: 0, booleans: false, strings: undefined };

export const budget = <T>(interval: number): MonoTypeOperatorFunction<T> => (source: Observable<T>) => new Observable<T>(observer => {
let timedOut = false;
Expand Down Expand Up @@ -227,6 +226,9 @@ const typedMethod = (it: any) => {
}
};

const AS_TO_FN = { strings: 'asString', numbers: 'asNumber', booleans: 'asBoolean' };
const STATIC_VALUES = { numbers: 0, booleans: false, strings: undefined };

export function scanToObject(): OperatorFunction<Parameter, { [key: string]: string | undefined }>;
export function scanToObject(to: 'numbers'): OperatorFunction<Parameter, { [key: string]: number | undefined }>;
export function scanToObject(to: 'booleans'): OperatorFunction<Parameter, { [key: string]: boolean | undefined }>;
Expand Down
5 changes: 2 additions & 3 deletions src/schematics/ng-add.jasmine.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Tree } from '@angular-devkit/schematics';
import { setupProject } from './ng-add';


const PROJECT_NAME = 'pie-ka-chu';
const PROJECT_ROOT = 'pirojok';
const FIREBASE_PROJECT = 'pirojok-111e3';
Expand Down Expand Up @@ -555,7 +554,7 @@ describe('ng-add', () => {
project: PROJECT_NAME
});

const workspace = JSON.parse((await result.read('angular.json'))!.toString());
const workspace = JSON.parse((await result.read('angular.json')).toString());
expect(workspace.projects['pie-ka-chu'].architect.deploy.options.ssr).toBeTrue();
});

Expand All @@ -569,7 +568,7 @@ describe('ng-add', () => {
project: PROJECT_NAME
});

const firebaseJson = JSON.parse((await result.read('firebase.json'))!.toString());
const firebaseJson = JSON.parse((await result.read('firebase.json')).toString());
expect(firebaseJson).toEqual(universalFirebaseJson);
});
});
Expand Down
23 changes: 14 additions & 9 deletions tools/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async function replacePackageCoreVersion() {
async function replacePackageJsonVersions() {
const path = dest('package.json');
const root = await rootPackage;
let pkg = await import(path);
const pkg = await import(path);
Object.keys(pkg.peerDependencies).forEach(peer => {
pkg.peerDependencies[peer] = root.dependencies[peer];
});
Expand All @@ -53,7 +53,7 @@ async function replaceSchematicVersions() {
}

function spawnPromise(command: string, args: string[]) {
return new Promise(resolve => spawn(command, args, {stdio: 'inherit'}).on('close', resolve));
return new Promise(resolve => spawn(command, args, { stdio: 'inherit' }).on('close', resolve));
}

async function compileSchematics() {
Expand Down Expand Up @@ -93,19 +93,19 @@ function measureLibrary() {
async function buildDocs() {
// INVESTIGATE json to stdout rather than FS?
await Promise.all(MODULES.map(module => spawnPromise('npx', ['typedoc', `./src/${module}`, '--json', `./dist/typedocs/${module}.json`])));
const entries = await Promise.all(MODULES.map(async (module, index) => {
const entries = await Promise.all(MODULES.map(async (module) => {
const buffer = await readFile(`./dist/typedocs/${module}.json`);
const typedoc = JSON.parse(buffer.toString());
// TODO infer the entryPoint from the package.json
const entryPoint = typedoc.children.find((c: any) => c.name === '"public_api"');
const allChildren = [].concat(...typedoc.children.map(child =>
// TODO chop out the working directory and filename
child.children ? child.children.map(c => ({...c, path: dirname(child.originalName.split(process.cwd())[1])})) : []
child.children ? child.children.map(c => ({ ...c, path: dirname(child.originalName.split(process.cwd())[1]) })) : []
));
return entryPoint.children
.filter(c => c.name[0] !== 'ɵ' && c.name[0] !== '_' /* private */)
.map(child => ({...allChildren.find(c => child.target === c.id)}))
.reduce((acc, child) => ({...acc, [encodeURIComponent(child.name)]: child}), {});
.map(child => ({ ...allChildren.find(c => child.target === c.id) }))
.reduce((acc, child) => ({ ...acc, [encodeURIComponent(child.name)]: child }), {});
}));
const root = await rootPackage;
const pipes = ['MonoTypeOperatorFunction', 'OperatorFunction', 'AuthPipe', 'UnaryFunction'];
Expand All @@ -125,11 +125,16 @@ async function buildDocs() {
return child.kindString;
}
};
const table_of_contents = entries.reduce((acc, entry, index) =>
({...acc, [MODULES[index]]: {name: ENTRY_NAMES[index], exports: Object.keys(entry).reduce((acc, key) => ({...acc, [key]: tocType(entry[key])}), {})}}),
const tableOfContents = entries.reduce((acc, entry, index) =>
({
...acc, [MODULES[index]]: {
name: ENTRY_NAMES[index],
exports: Object.keys(entry).reduce((acc, key) => ({ ...acc, [key]: tocType(entry[key]) }), {})
}
}),
{}
);
const afdoc = entries.reduce((acc, entry, index) => ({...acc, [MODULES[index]]: entry }), { table_of_contents });
const afdoc = entries.reduce((acc, entry, index) => ({ ...acc, [MODULES[index]]: entry }), { table_of_contents: tableOfContents });
return writeFile(`./api-${root.version}.json`, JSON.stringify(afdoc, null, 2));
}

Expand Down

0 comments on commit 6246b16

Please sign in to comment.