Skip to content

Commit

Permalink
build: update rxjs build version to v7
Browse files Browse the repository at this point in the history
The version of rxjs used to build the repository has been updated to v7.
This required only minimal changes to the code. Most of which were type
related only due to more strict types in v7. The behavior in those cases
was left intact. The most common type related change was to handle the
possibility of `undefined` with `toPromise` which was always possible with
v6 but the types did not reflect the runtime behavior. The one change that
was not type related was to provide a parameter value to the `defaultIfEmpty`
operator. It no longer defaults to a value of `null` if no default is provided.
To provide the same behavior the value of `null` is now passed to the operator.
  • Loading branch information
clydin committed Dec 11, 2023
1 parent e3a6bf9 commit d9c1a98
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export class ComponentDataSource extends DataSource<FlatNode> {
this._treeControl.expansionModel.changed,
this._flattenedData,
];
return merge(...changes)
return merge<unknown[]>(...changes)
.pipe(
map(() => {
this._expandedData.next(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class ExpandingRowDetailsCaption implements OnDestroy {
@Input() color: string = 'blue';

/** This is triggered when this component is destroyed. */
private readonly onDestroy = new Subject();
private readonly onDestroy = new Subject<void>();

/**
* We need a reference to parent cfc-expanding-row component here to hide
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
"rollup": "~2.79.0",
"rollup-plugin-preserve-shebang": "^1.0.1",
"rollup-plugin-sourcemaps": "^0.6.3",
"rxjs": "^6.6.7",
"rxjs": "^7.0.0",
"selenium-webdriver": "3.5.0",
"selenium-webdriver4": "npm:selenium-webdriver@4.14.0",
"semver-dsl": "^1.0.1",
Expand Down
8 changes: 4 additions & 4 deletions packages/common/http/test/client_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ describe('HttpClient', () => {
});
it('that returns a stream of events', done => {
client.get('/test', {observe: 'events'}).pipe(toArray()).toPromise().then(events => {
expect(events.length).toBe(2);
expect(events!.length).toBe(2);
let x = HttpResponse;
expect(events[0].type).toBe(HttpEventType.Sent);
expect(events[1].type).toBe(HttpEventType.Response);
expect(events[1] instanceof HttpResponse).toBeTruthy();
expect(events![0].type).toBe(HttpEventType.Sent);
expect(events![1].type).toBe(HttpEventType.Response);
expect(events![1] instanceof HttpResponse).toBeTruthy();
done();
});
backend.expectOne('/test').flush({'data': 'hello world'});
Expand Down
23 changes: 11 additions & 12 deletions packages/common/http/test/fetch_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@ import {HttpDownloadProgressEvent, HttpErrorResponse, HttpHeaderResponse, HttpPa
import {FetchBackend, FetchFactory} from '../src/fetch';

function trackEvents(obs: Observable<any>): Promise<any[]> {
return obs
.pipe(
// We don't want the promise to fail on HttpErrorResponse
catchError((e) => of(e)),
scan(
(acc, event) => {
acc.push(event);
return acc;
},
[] as any[]),
)
.toPromise();
return obs.pipe(
// We don't want the promise to fail on HttpErrorResponse
catchError((e) => of(e)),
scan(
(acc, event) => {
acc.push(event);
return acc;
},
[] as any[]),
)
.toPromise() as Promise<any[]>;
}

const TEST_POST = new HttpRequest('POST', '/test', 'some body', {
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/event_emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/

/// <reference types="rxjs" />

import {PartialObserver, Subject, Subscription} from 'rxjs';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ describe('InitialRenderPendingTasks', () => {

function hasPendingTasks(pendingTasks: InitialRenderPendingTasks): Promise<boolean> {
return of(EMPTY)
.pipe(
withLatestFrom(pendingTasks.hasPendingTasks),
map(([_, hasPendingTasks]) => hasPendingTasks),
)
.toPromise();
.pipe(
withLatestFrom(pendingTasks.hasPendingTasks),
map(([_, hasPendingTasks]) => hasPendingTasks),
)
.toPromise() as Promise<boolean>;
}
8 changes: 4 additions & 4 deletions packages/core/test/acceptance/outputs_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import {TestBed} from '@angular/core/testing';
describe('outputs', () => {
@Component({selector: 'button-toggle', template: ''})
class ButtonToggle {
@Output('change') change = new EventEmitter();
@Output('change') change = new EventEmitter<void>();

@Output('reset') resetStream = new EventEmitter();
@Output('reset') resetStream = new EventEmitter<void>();
}

@Directive({selector: '[otherDir]'})
class OtherDir {
@Output('change') changeStream = new EventEmitter();
@Output('change') changeStream = new EventEmitter<void>();
}

@Component({selector: 'destroy-comp', template: ''})
Expand All @@ -33,7 +33,7 @@ describe('outputs', () => {

@Directive({selector: '[myButton]'})
class MyButton {
@Output() click = new EventEmitter();
@Output() click = new EventEmitter<void>();
}

it('should call component output function when event is emitted', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/acceptance/property_binding_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ describe('property bindings', () => {
class MyDir {
@Input() role: string|undefined;
@Input('dir') direction: string|undefined;
@Output('change') changeStream = new EventEmitter();
@Output('change') changeStream = new EventEmitter<void>();
}

@Directive({selector: '[myDirB]'})
Expand Down
2 changes: 1 addition & 1 deletion packages/router/src/navigation_transition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ export class NavigationTransitions {
return loaders;
};
return combineLatest(loadComponents(t.targetSnapshot!.root))
.pipe(defaultIfEmpty(), take(1));
.pipe(defaultIfEmpty(null), take(1));
}),

switchTap(() => this.afterPreactivation()),
Expand Down
4 changes: 2 additions & 2 deletions packages/router/test/create_router_state.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ async function createState(config: Routes, url: string): Promise<RouterStateSnap
return recognize(
TestBed.inject(EnvironmentInjector), TestBed.inject(RouterConfigLoader), RootComponent,
config, tree(url), new DefaultUrlSerializer())
.pipe(map(result => result.state))
.toPromise();
.pipe(map(result => result.state))
.toPromise() as Promise<RouterStateSnapshot>;
}

function checkActivatedRoute(
Expand Down
2 changes: 1 addition & 1 deletion packages/router/test/recognize.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ async function recognize(
RootComponent, config, tree(url), paramsInheritanceStrategy, serializer)
.recognize()
.toPromise();
return result.state;
return result!.state;
}

function checkActivatedRoute(
Expand Down
3 changes: 2 additions & 1 deletion packages/router/test/router_scroller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ describe('RouterScroller', () => {
});

function nextScrollEvent(events: Subject<Event>): Promise<Scroll> {
return events.pipe(filter((e): e is Scroll => e instanceof Scroll), take(1)).toPromise();
return events.pipe(filter((e): e is Scroll => e instanceof Scroll), take(1)).toPromise() as
Promise<Scroll>;
}

describe('scroll to top', () => {
Expand Down
14 changes: 7 additions & 7 deletions packages/service-worker/src/low_level.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,13 @@ export class NgswCommChannel {

waitForOperationCompleted(nonce: number): Promise<boolean> {
return this.eventsOfType<OperationCompletedEvent>('OPERATION_COMPLETED')
.pipe(filter(event => event.nonce === nonce), take(1), map(event => {
if (event.result !== undefined) {
return event.result;
}
throw new Error(event.error!);
}))
.toPromise();
.pipe(filter(event => event.nonce === nonce), take(1), map(event => {
if (event.result !== undefined) {
return event.result;
}
throw new Error(event.error!);
}))
.toPromise() as Promise<boolean>;
}

get isEnabled(): boolean {
Expand Down
4 changes: 2 additions & 2 deletions packages/service-worker/src/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ export class SwPush {
return this.pushManager.pipe(switchMap(pm => pm.subscribe(pushOptions)), take(1))
.toPromise()
.then(sub => {
this.subscriptionChanges.next(sub);
return sub;
this.subscriptionChanges.next(sub!);
return sub!;
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/service-worker/test/integration_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const dist = new MockFileSystemBuilder().addFile('/only.txt', 'this is only').bu
const distUpdate = new MockFileSystemBuilder().addFile('/only.txt', 'this is only v2').build();

function obsToSinglePromise<T>(obs: Observable<T>): Promise<T> {
return obs.pipe(take(1)).toPromise();
return obs.pipe(take(1)).toPromise() as Promise<T>;
}

const manifest: Manifest = {
Expand Down
2 changes: 1 addition & 1 deletion tools/rxjs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ filegroup(
name = "rxjs_umd_modules",
srcs = [
":rxjs_shims.js",
"@npm//:node_modules/rxjs/bundles/rxjs.umd.js",
"@npm//:node_modules/rxjs/dist/bundles/rxjs.umd.js",
],
)
11 changes: 2 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13884,20 +13884,13 @@ rx@4.1.0:
resolved "https://registry.yarnpkg.com/rx/-/rx-4.1.0.tgz#a5f13ff79ef3b740fe30aa803fb09f98805d4782"
integrity sha512-CiaiuN6gapkdl+cZUr67W6I8jquN4lkak3vtIsIWCl4XIPP8ffsoyN6/+PuGXnQy8Cu8W2y9Xxh31Rq4M6wUug==

rxjs@7.8.1, rxjs@^7.2.0, rxjs@^7.5.5, rxjs@^7.8.1:
rxjs@7.8.1, rxjs@^7.0.0, rxjs@^7.2.0, rxjs@^7.5.5, rxjs@^7.8.1:
version "7.8.1"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.8.1.tgz#6f6f3d99ea8044291efd92e7c7fcf562c4057543"
integrity sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==
dependencies:
tslib "^2.1.0"

rxjs@^6.6.7:
version "6.6.7"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.6.7.tgz#90ac018acabf491bf65044235d5863c4dab804c9"
integrity sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ==
dependencies:
tslib "^1.9.0"

safe-buffer@5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1:
version "5.1.2"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
Expand Down Expand Up @@ -15348,7 +15341,7 @@ tslib@2.6.2, tslib@^2.0.0, tslib@^2.0.1, tslib@^2.0.3, tslib@^2.1.0, tslib@^2.3.
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.2.tgz#703ac29425e7b37cd6fd456e92404d46d1f3e4ae"
integrity sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==

tslib@^1.13.0, tslib@^1.8.1, tslib@^1.9.0:
tslib@^1.13.0, tslib@^1.8.1:
version "1.14.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
Expand Down

0 comments on commit d9c1a98

Please sign in to comment.