Skip to content

Commit

Permalink
chore(rxjs): use pipeable operators instead of prototype-patched base…
Browse files Browse the repository at this point in the history
…d operators [#258]
  • Loading branch information
christophercr committed Apr 4, 2018
1 parent 2f3dee6 commit 2f1af56
Show file tree
Hide file tree
Showing 13 changed files with 388 additions and 377 deletions.
20 changes: 4 additions & 16 deletions packages/rollup.config.common-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,21 @@ const commonjs = require("rollup-plugin-commonjs");
const sourcemaps = require("rollup-plugin-sourcemaps");

const globals = {
"class-validator": "class-validator",
cerialize: "cerialize",
"@angular/core": "ng.core",
"@angular/common/http": "angular.common.http",
rxjs: "rxjs",

"@ngrx/store": "@ngrx/store",
"class-validator": "class-validator",
cerialize: "cerialize",
moment: "moment",
uuid: "uuid",

rxjs: "rxjs",

// this should be the preferred way to import RxJS operators: https://github.com/ReactiveX/rxjs/blob/master/doc/pipeable-operators.md
// we should only use that in our code base
"rxjs/operators": "rxjs.operators",

// so that we can get rid of those: https://github.com/NationalBankBelgium/stark/issues/232
"rxjs/add/operator/catch": "Rx.Observable.prototype",
"rxjs/add/operator/map": "Rx.Observable.prototype",
"rxjs/add/operator/mergeMap": "Rx.Observable.prototype",
"rxjs/add/operator/retryWhen": "Rx.Observable.prototype",
"rxjs/add/operator/toPromise": "Rx.Observable.prototype",

// TODO could we also get rid of those?
"rxjs/Observable": "Rx",
"rxjs/add/observable/of": "Rx.Observable.prototype",
"rxjs/add/observable/throw": "Rx.Observable.prototype",
"rxjs/add/observable/timer": "Rx.Observable.prototype",

"rxjs/Subject": "Rx",
//"rxjs/Subscription": "Rx",

Expand Down
5 changes: 3 additions & 2 deletions packages/stark-build/config/build-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@ function getEnvFile(suffix) {
/**
* Read the tsconfig to determine if we should prefer ES2015 modules.
* Load rxjs path aliases.
* https://github.com/ReactiveX/rxjs/blob/master/doc/lettable-operators.md#build-and-treeshaking
* https://github.com/ReactiveX/rxjs/blob/master/doc/pipeable-operators.md#build-and-treeshaking
* @param supportES2015 Set to true when the output of typescript is >= ES6
*/
function rxjsAlias(supportES2015) {
try {
const rxjsPathMappingImport = supportES2015 ? "rxjs/_esm2015/path-mapping" : "rxjs/_esm5/path-mapping";
const rxPaths = require(rxjsPathMappingImport);
return rxPaths(helpers.root("node_modules"));
return rxPaths();
} catch (e) {
console.warn(e);
return {};
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/stark-build/config/tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
"no-import-side-effect": [
true,
{
"ignore-module": "(rxjs|reflect-metadata|core-js|ngrx-store|angular|polyfills|vendor|typings|\\.css|\\.pcss)"
"ignore-module": "(reflect-metadata|core-js|ngrx-store|angular|polyfills|vendor|typings|\\.css|\\.pcss)"
}
],
"no-non-null-assertion": true,
Expand Down
34 changes: 25 additions & 9 deletions packages/stark-build/config/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = function(options) {
};

const tsConfigApp = buildUtils.readTsConfig(helpers.root(METADATA.tsConfigPath));

const defaultNgcOptions = {
generateCodeForLibraries: true,
skipMetadataEmit: false,
Expand Down Expand Up @@ -70,12 +70,28 @@ module.exports = function(options) {
};

return {
/**
* Stats lets you precisely control what bundle information gets displayed
* reference: https://webpack.js.org/configuration/stats/
*/
stats: {
assets: true,
children: true,
chunks: true,
chunkModules: false,
chunkOrigins: false,
colors: true,
reasons: true,
errorDetails: true // display error details. Same as the --show-error-details flag
// maxModules: Infinity, // examine all modules (ModuleConcatenationPlugin debugging)
// optimizationBailout: true // display bailout reasons (ModuleConcatenationPlugin debugging)
errors: true,
errorDetails: true, // display error details. Same as the --show-error-details flag,
hash: true,
modules: true,
moduleTrace: true,
performance: true,
reasons: false,
source: true,
timings: true,
version: true,
warnings: true
},

/**
Expand Down Expand Up @@ -114,23 +130,23 @@ module.exports = function(options) {
modules: [helpers.root("src"), helpers.root("node_modules")],

/**
* Add support for lettable operators.
* Add support for pipeable operators.
*
* For existing codebase a refactor is required.
* All rxjs operator imports (e.g. `import 'rxjs/add/operator/map'` or `import { map } from `rxjs/operator/map'`
* must change to `import { map } from 'rxjs/operators'` (note that all operators are now under that import.
* Additionally some operators have changed to to JS keyword constraints (do => tap, catch => catchError)
*
* Remember to use the `pipe()` method to chain operators, this functinoally makes lettable operators similar to
* Remember to use the `pipe()` method to chain operators, this functionally makes pipeable operators similar to
* the old operators usage paradigm.
*
* For more details see:
* https://github.com/ReactiveX/rxjs/blob/master/doc/lettable-operators.md#build-and-treeshaking
* https://github.com/ReactiveX/rxjs/blob/master/doc/pipeable-operators.md#build-and-treeshaking
*
* If you are not planning on refactoring your codebase (or not planning on using imports from `rxjs/operators`
* comment out this line.
*
* BE AWARE that not using lettable operators will probably result in significant payload added to your bundle.
* BE AWARE that not using pipeable operators will probably result in significant payload added to your bundle.
*/
alias: buildUtils.rxjsAlias(supportES2015)
},
Expand Down
12 changes: 12 additions & 0 deletions packages/stark-build/config/webpack.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ module.exports = function() {
METADATA.envFileSuffix = METADATA.E2E ? "e2e.prod" : "prod";

return webpackMerge(commonConfig({ ENV: ENV, metadata: METADATA }), {
/**
* Stats lets you precisely control what bundle information gets displayed
* reference: https://webpack.js.org/configuration/stats/
*/
stats: {
chunkModules: true,
chunkOrigins: true,
reasons: true,
maxModules: Infinity, // examine all modules (ModuleConcatenationPlugin debugging)
optimizationBailout: true // display bailout reasons (ModuleConcatenationPlugin debugging)
},

/**
* Options affecting the output of the compilation.
*
Expand Down
2 changes: 1 addition & 1 deletion packages/stark-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
},
"scripts": {
"ngc": "ngc",
"lint": "tslint --config tslint.json --project ./tsconfig.json --format codeFrame",
"lint": "tslint --config tslint.json --project ./tsconfig.spec.json --format codeFrame",
"test-fast": "node ./node_modules/@nationalbankbelgium/stark-testing/node_modules/karma/bin/karma start ./karma.conf.typescript.js",
"test-fast:ci": "node ./node_modules/@nationalbankbelgium/stark-testing/node_modules/karma/bin/karma start karma.conf.typescript.ci.js",
"tsc": "tsc -p tsconfig.json",
Expand Down
18 changes: 12 additions & 6 deletions packages/stark-core/src/http/http.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { HttpClient, HttpClientModule } from "@angular/common/http";
import { StarkHttpServiceImpl, starkHttpServiceName } from "./services/index";

// FIXME: remove this factory once LoggingService and SessionService are implemented
const starkHttpServiceFactory: any = (httpClient: HttpClient) => {
const starkHttpServiceFactory = (httpClient: HttpClient) => {
const logger: any = {
debug: console.debug,
warn: console.warn,
Expand All @@ -12,17 +12,23 @@ const starkHttpServiceFactory: any = (httpClient: HttpClient) => {
};

const sessionService: any = {
fakePreAuthenticationHeaders: new Map<string, string>([["nbb-dummy-header", "some value"], ["nbb-another-header", "whatever"]])
fakePreAuthenticationHeaders: new Map<string, string>([
["nbb-dummy-header", "some value"], ["nbb-another-header", "whatever"]
])
};

return new StarkHttpServiceImpl(logger, sessionService, httpClient);
return new StarkHttpServiceImpl(logger, sessionService, httpClient)
};

@NgModule({
imports: [HttpClientModule],
imports: [
HttpClientModule
],
providers: [
// FIXME: replace this Factory provider by a simple Class provider once LoggingService and SessionService are implemented
{ provide: starkHttpServiceName, useFactory: starkHttpServiceFactory, deps: [HttpClient] }
{provide: starkHttpServiceName, useFactory: starkHttpServiceFactory, deps: [HttpClient]},
]
})
export class StarkHttpModule {}
export class StarkHttpModule {

}
Loading

0 comments on commit 2f1af56

Please sign in to comment.