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

feat: remove uses of rxjs patch operators #5314

Merged
merged 1 commit into from Jun 23, 2017

Conversation

crisbeto
Copy link
Member

Refactors the entire codebase not to use the patch operators from RxJS, because they pollute the user's setup. Instead, opts into importing the operators directly and chaining them via the RxChain class.

Fixes #2622.

Note: I'll add some linting to enforce these changes after they get in.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jun 22, 2017
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

Looks good, just a few comments

* @docs-private
*/
export class RxChain<T> {
constructor(private _context: Observable<T>) { }
Copy link
Member

Choose a reason for hiding this comment

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

We can also make the constructor private so people have to use the static from and get a strict chain.
(just looked this up a moment ago)


/**
* Utility class used to chain RxJS operators.
* @docs-private
Copy link
Member

Choose a reason for hiding this comment

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

Maybe expand the comment with something like

/**
 * Utility class used to chain RxJS operators.
 *
 * This class is the concrete implementation, but the type used by the user when chaining
 * is StrictRxChain. The strict chain enforces types on the operators to the same level as
 * the prototype-added equivalents.
 * 
 * @docs-private
 */


/**
* Represents a strongly-typed chain of RxJS operators.
* @docs-private
Copy link
Member

Choose a reason for hiding this comment

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

I'd expand to something like

/**
 * Represents a strongly-typed chain of RxJS operators.
 *
 * We achieve strict type enforcement on the chained operators by creating types that
 * *unambiguously* match specific rxjs operators. These unambiguous types are created by
 * intersecting a "brand" to the `typeof` the existing operator. The brand (a class with a private
 * member) effectively forces nominal typing for the operators. This allows typescript to understand
 * that, for example, `filter` is *`filter`* and not, say, a map of T => boolean.
 *
 * The downside to this approach is that operators must be imported in their type-coerced form
 * rather than from the normal rxjs location.
 *
 * @docs-private
 */

@crisbeto
Copy link
Member Author

Addressed the feedback and sorted out the CI failures @jelbourn.

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn jelbourn added merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Jun 23, 2017
@jelbourn
Copy link
Member

Caretaker note: removing the prototype operators can potentially break some apps on sync

Refactors the entire codebase not to use the patch operators from RxJS, because they pollute the user's setup. Instead, opts into importing the operators directly and chaining them via the `RxChain` class.

Fixes angular#2622.
@jelbourn jelbourn merged commit e488e3f into angular:master Jun 23, 2017
devversion added a commit to devversion/material2 that referenced this pull request Jun 25, 2017
With angular#5314 a lot of `@docs-private` tags that are ignored have been added. Dgeni only includes exports of files if they are explicitly exported in a `src/XXX/index.ts` file.

Since this is not the case the `@docs-private` tags can be removed because the Rx chain files are not re-exported anywhere.
tinayuangao pushed a commit that referenced this pull request Jun 27, 2017
With #5314 a lot of `@docs-private` tags that are ignored have been added. Dgeni only includes exports of files if they are explicitly exported in a `src/XXX/index.ts` file.

Since this is not the case the `@docs-private` tags can be removed because the Rx chain files are not re-exported anywhere.
@willshowell
Copy link
Contributor

For folks who come searching later, these are the operators and observables that are no longer being patched onto your Observable.prototype

Operators
-------------
auditTime
catch
debounceTime
do
filter
finally
first
let
map
share
startWith
switchMap
takeUntil

Observables
-------------
combineLatest
forkJoin
fromEvent
merge
of
throw

amcdnl pushed a commit to amcdnl/material2 that referenced this pull request Jul 8, 2017
With angular#5314 a lot of `@docs-private` tags that are ignored have been added. Dgeni only includes exports of files if they are explicitly exported in a `src/XXX/index.ts` file.

Since this is not the case the `@docs-private` tags can be removed because the Rx chain files are not re-exported anywhere.
emoralesb05 added a commit to Teradata/covalent that referenced this pull request Jul 9, 2017
emoralesb05 added a commit to Teradata/covalent that referenced this pull request Jul 13, 2017
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Internal usages of RxJS operators should not patch the prototype of Observable
4 participants