Skip to content

Commit cdf0273

Browse files
Matt Lewischristopherthielen
authored andcommitted
feat(angular): Drop Angular v4 support, add Angular v6 support
BREAKING CHANGE: RxJS v6 and Angular v5 or higher is now required to use this package. If using Angular v5, you should update to `"rxjs": "^6.0.0"` and also add `"rxjs-compat": "^6.0.0"`. Closes #301
1 parent eb6aa7e commit cdf0273

File tree

19 files changed

+254
-246
lines changed

19 files changed

+254
-246
lines changed

karma.conf.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
// Karma configuration file
22
var karma = require('karma');
3+
var webpack = require('webpack');
34

4-
module.exports = function (karma) {
5+
module.exports = function(karma) {
56
var config = {
67
singleRun: true,
78
autoWatch: false,
89
autoWatchInterval: 0,
910

1011
// level of logging
1112
// possible values: LOG_DISABLE, LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DEBUG
12-
logLevel: "warn",
13+
logLevel: 'warn',
1314
// possible values: 'dots', 'progress'
1415
reporters: ['super-dots', 'mocha'],
1516
colors: true,
@@ -27,7 +28,7 @@ module.exports = function (karma) {
2728
// Chrome, ChromeCanary, Firefox, Opera, Safari, PhantomJS
2829
browsers: ['ChromeHeadlessNoSandbox'],
2930
customLaunchers: {
30-
ChromeHeadlessNoSandbox: { base: 'ChromeHeadless', flags: ['--no-sandbox'] }
31+
ChromeHeadlessNoSandbox: { base: 'ChromeHeadless', flags: ['--no-sandbox'] },
3132
},
3233

3334
frameworks: ['jasmine'],
@@ -38,29 +39,30 @@ module.exports = function (karma) {
3839
require('karma-super-dots-reporter'),
3940
require('karma-mocha-reporter'),
4041
require('karma-jasmine'),
41-
require('karma-chrome-launcher')
42+
require('karma-chrome-launcher'),
4243
],
4344

4445
webpack: {
4546
devtool: 'eval',
4647

4748
resolve: {
4849
modules: ['node_modules'],
49-
extensions: ['.js', '.ts']
50+
extensions: ['.js', '.ts'],
5051
},
5152

5253
module: {
5354
rules: [
5455
{
5556
test: /\.ts$/,
56-
loader: "ts-loader",
57+
loader: 'ts-loader',
5758
options: {
58-
configFile: "test/tsconfig.json",
59-
}
60-
}
61-
]
59+
configFile: 'test/tsconfig.json',
60+
},
61+
},
62+
],
6263
},
6364

65+
plugins: [new webpack.ContextReplacementPlugin(/angular(\\|\/)core(\\|\/)fesm5/, __dirname + '/src')],
6466
},
6567

6668
webpackMiddleware: {
@@ -72,9 +74,7 @@ module.exports = function (karma) {
7274
preprocessors: {
7375
'test/index.js': ['webpack', 'sourcemap'],
7476
},
75-
7677
};
7778

7879
karma.set(config);
7980
};
80-

package.json

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,23 @@
5050
"typings": "lib/index.d.ts",
5151
"dependencies": {
5252
"@uirouter/core": "5.0.18",
53-
"@uirouter/rx": "0.4.5"
53+
"@uirouter/rx": "0.5.0-alpha.1"
5454
},
5555
"peerDependencies": {
56-
"@angular/common": "^4.0.0 || ^5.0.0",
57-
"@angular/core": "^4.0.0 || ^5.0.0",
58-
"@angular/router": "^4.0.0 || ^5.0.0"
56+
"@angular/common": "^6.0.0",
57+
"@angular/core": "^6.0.0",
58+
"@angular/router": "^6.0.0"
5959
},
6060
"devDependencies": {
61-
"@angular/common": "^4.0.0",
62-
"@angular/compiler": "^4.0.0",
63-
"@angular/compiler-cli": "^4.0.0",
64-
"@angular/core": "^4.0.0",
65-
"@angular/platform-browser": "^4.0.0",
66-
"@angular/platform-browser-dynamic": "^4.0.0",
67-
"@angular/platform-server": "^4.0.0",
68-
"@angular/router": "^4.0.0",
61+
"@angular/animations": "^6.0.0",
62+
"@angular/common": "^6.0.0",
63+
"@angular/compiler": "^6.0.0",
64+
"@angular/compiler-cli": "^6.0.0",
65+
"@angular/core": "^6.0.0",
66+
"@angular/platform-browser": "^6.0.0",
67+
"@angular/platform-browser-dynamic": "^6.0.0",
68+
"@angular/platform-server": "^6.0.0",
69+
"@angular/router": "^6.0.0",
6970
"@types/jasmine": "^2.8.6",
7071
"@types/jquery": "^3.3.1",
7172
"@uirouter/publish-scripts": "^2.3.4",
@@ -85,13 +86,13 @@
8586
"rollup-plugin-node-resolve": "^3.3.0",
8687
"rollup-plugin-sourcemaps": "^0.4.2",
8788
"rollup-plugin-uglify": "^3.0.0",
88-
"rxjs": "^5.5.8",
89+
"rxjs": "^6.1.0",
8990
"shelljs": "^0.8.1",
9091
"shx": "^0.2.2",
9192
"ts-loader": "^3.5.0",
9293
"tslib": "^1.9.0",
9394
"tslint": "^5.9.1",
94-
"typescript": "^2.8.3",
95+
"typescript": "~2.7.2",
9596
"webpack": "^3.11.0",
9697
"webpack-dev-server": "^3.1.4",
9798
"zone.js": "^0.8.20"

src/directives/uiSref.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import {
1313
HostListener,
1414
} from '@angular/core';
1515
import { UIView, ParentUIViewInject } from './uiView';
16-
import { ReplaySubject } from 'rxjs/ReplaySubject';
17-
import { Subscription } from 'rxjs/Subscription';
16+
import { ReplaySubject, Subscription } from 'rxjs';
1817

1918
/**
2019
* @internalapi

src/directives/uiSrefActive.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @ng2api @module directives */ /** */
2-
import { Directive, Input, ElementRef, Host, Renderer } from '@angular/core';
2+
import { Directive, Input, ElementRef, Host, Renderer2 } from '@angular/core';
33
import { UISrefStatus, SrefStatus } from './uiSrefStatus';
4-
import { Subscription } from 'rxjs/Subscription';
4+
import { Subscription } from 'rxjs';
55

66
/**
77
* A directive that adds a CSS class when its associated `uiSref` link is active.
@@ -98,10 +98,22 @@ export class UISrefActive {
9898
}
9999

100100
private _subscription: Subscription;
101-
constructor(uiSrefStatus: UISrefStatus, rnd: Renderer, @Host() host: ElementRef) {
101+
constructor(uiSrefStatus: UISrefStatus, rnd: Renderer2, @Host() host: ElementRef) {
102102
this._subscription = uiSrefStatus.uiSrefStatus.subscribe((next: SrefStatus) => {
103-
this._classes.forEach(cls => rnd.setElementClass(host.nativeElement, cls, next.active));
104-
this._classesEq.forEach(cls => rnd.setElementClass(host.nativeElement, cls, next.exact));
103+
this._classes.forEach(cls => {
104+
if (next.active) {
105+
rnd.addClass(host.nativeElement, cls);
106+
} else {
107+
rnd.removeClass(host.nativeElement, cls);
108+
}
109+
});
110+
this._classesEq.forEach(cls => {
111+
if (next.exact) {
112+
rnd.addClass(host.nativeElement, cls);
113+
} else {
114+
rnd.removeClass(host.nativeElement, cls);
115+
}
116+
});
105117
});
106118
}
107119

src/directives/uiSrefStatus.ts

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,10 @@ import {
1414
UIRouterGlobals,
1515
Param,
1616
PathUtils,
17-
StateOrName,
1817
} from '@uirouter/core';
1918

20-
import { Subscription } from 'rxjs/Subscription';
21-
import { Observable } from 'rxjs/Observable';
22-
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
23-
24-
import { of } from 'rxjs/observable/of';
25-
import { fromPromise } from 'rxjs/observable/fromPromise';
26-
import { combineLatest } from 'rxjs/observable/combineLatest';
27-
import { switchMap } from 'rxjs/operator/switchMap';
28-
import { map } from 'rxjs/operator/map';
29-
import { concat } from 'rxjs/operator/concat';
19+
import { Subscription, Observable, BehaviorSubject, of, from, combineLatest, concat } from 'rxjs';
20+
import { switchMap, map } from 'rxjs/operators';
3021

3122
/** @internalapi */
3223
interface TransEvt {
@@ -223,35 +214,41 @@ export class UISrefStatus {
223214
ngAfterContentInit() {
224215
// Map each transition start event to a stream of:
225216
// start -> (success|error)
226-
const transEvents$: Observable<TransEvt> = switchMap.call(this._globals.start$, (trans: Transition) => {
227-
const event = (evt: string) => ({ evt, trans } as TransEvt);
217+
const transEvents$: Observable<TransEvt> = this._globals.start$.pipe(
218+
switchMap((trans: Transition) => {
219+
const event = (evt: string) => ({ evt, trans } as TransEvt);
228220

229-
const transStart$ = of(event('start'));
230-
const transResult = trans.promise.then(() => event('success'), () => event('error'));
231-
const transFinish$ = fromPromise(transResult);
221+
const transStart$ = of(event('start'));
222+
const transResult = trans.promise.then(() => event('success'), () => event('error'));
223+
const transFinish$ = from(transResult);
232224

233-
return concat.call(transStart$, transFinish$);
234-
});
225+
return concat(transStart$, transFinish$);
226+
}),
227+
);
235228

236229
// Watch the @ContentChildren UISref[] components and get their target states
237230

238231
// let srefs$: Observable<UISref[]> = of(this.srefs.toArray()).concat(this.srefs.changes);
239232
this._srefs$ = new BehaviorSubject(this._srefs.toArray());
240233
this._srefChangesSub = this._srefs.changes.subscribe(srefs => this._srefs$.next(srefs));
241234

242-
const targetStates$: Observable<TargetState[]> = switchMap.call(this._srefs$, (srefs: UISref[]) =>
243-
combineLatest<TargetState[]>(srefs.map(sref => sref.targetState$)),
235+
const targetStates$: Observable<TargetState[]> = this._srefs$.pipe(
236+
switchMap((srefs: UISref[]) => combineLatest<TargetState>(srefs.map(sref => sref.targetState$))),
244237
);
245238

246239
// Calculate the status of each UISref based on the transition event.
247240
// Reduce the statuses (if multiple) by or-ing each flag.
248-
this._subscription = switchMap
249-
.call(transEvents$, (evt: TransEvt) => {
250-
return map.call(targetStates$, (targets: TargetState[]) => {
251-
const statuses: SrefStatus[] = targets.map(target => getSrefStatus(evt, target));
252-
return statuses.reduce(mergeSrefStatus);
253-
});
254-
})
241+
this._subscription = transEvents$
242+
.pipe(
243+
switchMap((evt: TransEvt) => {
244+
return targetStates$.pipe(
245+
map((targets: TargetState[]) => {
246+
const statuses: SrefStatus[] = targets.map(target => getSrefStatus(evt, target));
247+
return statuses.reduce(mergeSrefStatus);
248+
}),
249+
);
250+
}),
251+
)
255252
.subscribe(this._setStatus.bind(this));
256253
}
257254

test/ngModule/augment/augment.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Ng2StateDeclaration } from '../../../src/interface';
55

66
@Component({
77
selector: 'component1',
8-
template: '<h1>Component 1</h1><ui-view></ui-view>',
8+
template: '<h1>Component 1</h1>&ngsp;<ui-view></ui-view>',
99
})
1010
export class Component1 {}
1111

test/ts/typescript2.3/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"@angular/common": "latest",
1212
"@angular/core": "latest",
1313
"@uirouter/angular": "latest",
14-
"rxjs": "^5.0.0",
14+
"rxjs": "^6.0.0",
1515
"typescript": "2.3"
1616
},
1717
"devDependencies": {}

test/ts/typescript2.4/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"@angular/common": "latest",
1212
"@angular/core": "latest",
1313
"@uirouter/angular": "latest",
14-
"rxjs": "^5.0.0",
14+
"rxjs": "^6.0.0",
1515
"typescript": "2.4"
1616
},
1717
"devDependencies": {}

test/ts/typescript2.5/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"@angular/common": "latest",
1212
"@angular/core": "latest",
1313
"@uirouter/angular": "latest",
14-
"rxjs": "^5.0.0",
14+
"rxjs": "^6.0.0",
1515
"typescript": "2.5"
1616
},
1717
"devDependencies": {}

test/ts/typescript2.6/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"@angular/common": "latest",
1212
"@angular/core": "latest",
1313
"@uirouter/angular": "latest",
14-
"rxjs": "^5.0.0",
14+
"rxjs": "^6.0.0",
1515
"typescript": "2.6"
1616
},
1717
"devDependencies": {}

0 commit comments

Comments
 (0)