Skip to content

Commit

Permalink
fix(compat): deprecate Observable.if/throw (#3527)
Browse files Browse the repository at this point in the history
* fix(compat): deprecate Observable.if/throw

* build: point circular deps check against output files
  • Loading branch information
jasonaden authored and benlesh committed Apr 5, 2018
1 parent 5f2f797 commit 3116275
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .dependency-cruiser.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"severity": "error",
"comment": "Error in case we have circular dependencies",
"from": {
"path": "^src"
"path": "^dist/esm5"
},
"to": {
"circular": true
Expand Down
3 changes: 1 addition & 2 deletions compat/add/observable/if.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Observable, iif } from 'rxjs';

//tslint:disable-next-line:no-any TypeScript doesn't like `if`
(Observable as any).if = iif;
Observable.if = iif;
2 changes: 1 addition & 1 deletion compat/add/observable/throw.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Observable, throwError as staticThrowError } from 'rxjs';

(Observable as any).throw = staticThrowError;
Observable.throw = staticThrowError;
Observable.throwError = staticThrowError;

declare module 'rxjs/internal/Observable' {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"test_browser": "npm-run-all build_spec_browser && opn spec/support/mocha-browser-runner.html",
"test": "mocha --require ts-node/register --opts spec-build/support/coverage.opts \"spec-build/**/*-spec.ts\"",
"test:cover": "cross-env TS_NODE_FAST=true nyc npm test",
"test:circular": "dependency-cruise --validate .dependency-cruiser.json -x \"^node_modules\" src",
"test:circular": "dependency-cruise --validate .dependency-cruiser.json -x \"^node_modules\" dist/esm5",
"test:systemjs": "node integration/systemjs/systemjs-compatibility-spec.js",
"tests2png": "mkdirp tmp/docs/img && cross-env TS_NODE_FAST=true mocha --compilers ts:ts-node/register --opts spec/support/tests2png.opts \"spec/**/*-spec.ts\"",
"watch": "watch \"echo triggering build && npm run build_spec && npm run test && echo build completed\" src -d -u -w=15",
Expand Down
15 changes: 12 additions & 3 deletions src/internal/Observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Subscription } from './Subscription';
import { TeardownLogic } from './types';
import { toSubscriber } from './util/toSubscriber';
import { iif } from './observable/iif';
import { throwError } from './observable/throwError';
import { observable as Symbol_observable } from '../internal/symbol/observable';
import { OperatorFunction, PartialObserver, Subscribable } from '../internal/types';
import { pipeFromArray } from './util/pipe';
Expand Down Expand Up @@ -252,10 +253,18 @@ export class Observable<T> implements Subscribable<T> {
return source && source.subscribe(subscriber);
}

// TODO(benlesh): determine if this is still necessary
// `if` and `throw` are special snow flakes, the compiler sees them as reserved words
/** @nocollapse */
// `if` and `throw` are special snow flakes, the compiler sees them as reserved words. Deprecated in
// favor of iif and throwError functions.
/**
* @nocollapse
* @deprecated In favor of iif creation function: import { iif } from 'rxjs';
*/
static if: typeof iif;
/**
* @nocollapse
* @deprecated In favor of throwError creation function: import { throwError } from 'rxjs';
*/
static throw: typeof throwError;

/**
* An interop point defined by the es7-observable spec https://github.com/zenparsing/es-observable
Expand Down

0 comments on commit 3116275

Please sign in to comment.