Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(location): return ISubscription from Location.subscribe() #20429

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/common/src/location/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import {EventEmitter, Injectable} from '@angular/core';
import {ISubscription} from 'rxjs/Subscription';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OOC, what are the benefits of using ISubscription instead of Subscription (if it's only for types)? Does it affect the bundle size?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really should be using ISubscription because it's the closest thing to the spec. Subscription requires additional properties/methods such as add, remove, etc. ISubscription should be compatible with most Observable implementations since it just has unsubscribe() and closed: boolean.


import {LocationStrategy} from './location_strategy';

Expand Down Expand Up @@ -129,7 +130,7 @@ export class Location {
*/
subscribe(
onNext: (value: PopStateEvent) => void, onThrow?: ((exception: any) => void)|null,
onReturn?: (() => void)|null): Object {
onReturn?: (() => void)|null): ISubscription {
return this._subject.subscribe({next: onNext, error: onThrow, complete: onReturn});
}

Expand Down
3 changes: 2 additions & 1 deletion packages/common/testing/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const globals = {
'@angular/core': 'ng.core',
'@angular/common': 'ng.common',
'rxjs/Observable': 'Rx',
'rxjs/Subject': 'Rx'
'rxjs/Subject': 'Rx',
'rxjs/Subscription': 'Rx'
};

module.exports = {
Expand Down
3 changes: 2 additions & 1 deletion packages/common/testing/src/location_mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import {Location, LocationStrategy} from '@angular/common';
import {EventEmitter, Injectable} from '@angular/core';
import {ISubscription} from 'rxjs/Subscription';


/**
Expand Down Expand Up @@ -109,7 +110,7 @@ export class SpyLocation implements Location {

subscribe(
onNext: (value: any) => void, onThrow?: ((error: any) => void)|null,
onReturn?: (() => void)|null): Object {
onReturn?: (() => void)|null): ISubscription {
return this._subject.subscribe({next: onNext, error: onThrow, complete: onReturn});
}

Expand Down
2 changes: 1 addition & 1 deletion tools/public_api_guard/common/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export declare class Location {
path(includeHash?: boolean): string;
prepareExternalUrl(url: string): string;
replaceState(path: string, query?: string): void;
subscribe(onNext: (value: PopStateEvent) => void, onThrow?: ((exception: any) => void) | null, onReturn?: (() => void) | null): Object;
subscribe(onNext: (value: PopStateEvent) => void, onThrow?: ((exception: any) => void) | null, onReturn?: (() => void) | null): ISubscription;
static joinWithSlash(start: string, end: string): string;
static normalizeQueryParams(params: string): string;
static stripTrailingSlash(url: string): string;
Expand Down
2 changes: 1 addition & 1 deletion tools/public_api_guard/common/testing.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ export declare class SpyLocation implements Location {
setInitialPath(url: string): void;
simulateHashChange(pathname: string): void;
simulateUrlPop(pathname: string): void;
subscribe(onNext: (value: any) => void, onThrow?: ((error: any) => void) | null, onReturn?: (() => void) | null): Object;
subscribe(onNext: (value: any) => void, onThrow?: ((error: any) => void) | null, onReturn?: (() => void) | null): ISubscription;
}