Skip to content

Commit

Permalink
refactor(all): upgrade to angular 5.0 (#552)
Browse files Browse the repository at this point in the history
close #520 close #514 close #533
  • Loading branch information
vthinkxie committed Nov 16, 2017
1 parent 22e2931 commit 8dd8a43
Show file tree
Hide file tree
Showing 28 changed files with 286 additions and 233 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ integration/**/*.ngsummary.json

# dependencies
node_modules/
node_modules.*/
package-lock.json
integration/**/package-lock.json
yarn.lock
Expand Down
1 change: 0 additions & 1 deletion index.ts

This file was deleted.

24 changes: 1 addition & 23 deletions integration/angular-cli/.angular-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,6 @@
},
"defaults": {
"styleExt": "css",
"component": {
"spec": false,
"inlineStyle": true,
"inlineTemplate": true
},
"directive": {
"spec": false
},
"class": {
"spec": false
},
"guard": {
"spec": false
},
"module": {
"spec": false
},
"pipe": {
"spec": false
},
"service": {
"spec": false
}
"component": {}
}
}
2 changes: 1 addition & 1 deletion integration/rollup/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function enableProdMode() {


export default {
input: './out-tsc/app/main.js',
input: './out-tsc/app/src/main.js',
output: {
file: './dist/main.bundle.js',
format: 'iife',
Expand Down
4 changes: 2 additions & 2 deletions integration/webpack/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
const { AotPlugin } = require('@ngtools/webpack')
const { AngularCompilerPlugin } = require('@ngtools/webpack')
const { PurifyPlugin } = require('@angular-devkit/build-optimizer')

function packageSort(packages) {
Expand Down Expand Up @@ -49,7 +49,7 @@ module.exports = {
extensions: ['.js', '.ts'],
},
plugins: [
new AotPlugin({
new AngularCompilerPlugin({
tsConfigPath: path.resolve(__dirname, 'src/tsconfig.app.json'),
entryModule: path.resolve(__dirname, 'src/app/app.module#AppModule'),
}),
Expand Down
46 changes: 23 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,28 @@
"url": "https://github.com/NG-ZORRO/ng-zorro-antd/issues"
},
"dependencies": {
"@angular/cdk": "2.0.0-beta.12",
"@angular/cdk": "5.0.0-rc0",
"moment": "^2.18.1",
"tslib": "^1.7.1"
},
"devDependencies": {
"@angular/animations": "^4.4.4",
"@angular/cli": "1.4.7",
"@angular/common": "^4.4.4",
"@angular/compiler": "^4.4.4",
"@angular/compiler-cli": "^4.4.4",
"@angular/core": "^4.4.4",
"@angular/forms": "^4.4.4",
"@angular/http": "^4.4.4",
"@angular/language-service": "^4.4.4",
"@angular/platform-browser": "^4.4.4",
"@angular/platform-browser-dynamic": "^4.4.4",
"@angular/router": "^4.4.4",
"@angular/animations": "^5.0.0",
"@angular/cli": "1.5.0",
"@angular/common": "^5.0.0",
"@angular/compiler": "^5.0.0",
"@angular/compiler-cli": "^5.0.0",
"@angular/core": "^5.0.0",
"@angular/forms": "^5.0.0",
"@angular/http": "^5.0.0",
"@angular/language-service": "^5.0.0",
"@angular/platform-browser": "^5.0.0",
"@angular/platform-browser-dynamic": "^5.0.0",
"@angular/router": "^5.0.0",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"classlist.js": "^1.1.20150312",
"codelyzer": "~3.1.1",
"codelyzer": "~4.0.1",
"core-js": "^2.4.1",
"coveralls": "^2.13.1",
"highlight.js": "^9.12.0",
Expand All @@ -75,20 +75,20 @@
"rollup-plugin-commonjs": "^8.2.1",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-replace": "^2.0.0",
"rxjs": "^5.0.1",
"rxjs": "^5.5.2",
"ts-node": "~3.2.0",
"tslint": "~5.3.2",
"typescript": "~2.3.3",
"tslint": "~5.7.0",
"typescript": "~2.4.2",
"uglify-js": "^3.0.28",
"web-animations-js": "^2.3.1",
"zone.js": "^0.8.14"
"zone.js": "^0.8.17"
},
"peerDependencies": {
"@angular/animations": "^4.4.4",
"@angular/cdk": "2.0.0-beta.12",
"@angular/common": "^4.4.4",
"@angular/core": "^4.4.4",
"@angular/forms": "^4.4.4",
"@angular/animations": "^5.0.0",
"@angular/cdk": "5.0.0-rc0",
"@angular/common": "^5.0.0",
"@angular/core": "^5.0.0",
"@angular/forms": "^5.0.0",
"moment": "^2.18.1"
}
}
82 changes: 74 additions & 8 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,65 @@ const format = process.env.ROLLUP_FORMAT || 'es';

let globals = {
'@angular/animations': 'ng.animations',
// '@angular/cdk': 'ng.cdk',
'@angular/cdk/rxjs': 'ng.cdk.rxjs',
'@angular/cdk/keycodes': 'ng.cdk.keycodes',
'@angular/cdk/overlay': 'ng.cdk.overlay',
'@angular/cdk/portal': 'ng.cdk.portal',
'@angular/cdk/bidi': 'ng.cdk.bidi',
'@angular/cdk/observers': 'ng.cdk.observers',
'@angular/core': 'ng.core',
'@angular/common': 'ng.common',
'@angular/compiler': 'ng.compiler',
'@angular/forms': 'ng.forms',
'@angular/common/http': 'ng.common.http',
'@angular/router': 'ng.router',
'@angular/platform-browser': 'ng.platformBrowser',
'@angular/platform-server': 'ng.platformServer',
'@angular/platform-browser-dynamic': 'ng.platformBrowserDynamic',
'@angular/platform-browser/animations': 'ng.platformBrowser.animations',
'@angular/core/testing': 'ng.core.testing',
'@angular/common/testing': 'ng.common.testing',
'@angular/common/http/testing': 'ng.common.http.testing',

'@angular/cdk': 'ng.cdk',
'@angular/cdk/keycodes': 'ng.cdk.keycodes',
'@angular/cdk/a11y': 'ng.cdk.a11y',
'@angular/cdk/accordion': 'ng.cdk.accordion',
'@angular/cdk/bidi': 'ng.cdk.bidi',
'@angular/cdk/coercion': 'ng.cdk.coercion',
'@angular/cdk/collections': 'ng.cdk.collections',
'@angular/cdk/layout': 'ng.cdk.layout',
'@angular/cdk/observers': 'ng.cdk.observers',
'@angular/cdk/overlay': 'ng.cdk.overlay',
'@angular/cdk/platform': 'ng.cdk.platform',
'@angular/cdk/portal': 'ng.cdk.portal',
'@angular/cdk/scrolling': 'ng.cdk.scrolling',
'@angular/cdk/stepper': 'ng.cdk.stepper',
'@angular/cdk/table': 'ng.cdk.table',

'moment': 'moment',
'moment/locale/zh-cn': null,

'rxjs/Observer': 'Rx',
'rxjs/Subscriber': 'Rx',
'rxjs/Scheduler': 'Rx',

'rxjs/observable/combineLatest': 'Rx.Observable',
'rxjs/observable/throw': 'Rx.Observable',
'rxjs/observable/defer': 'Rx.Observable',
'rxjs/observable/fromEventPattern': 'Rx.Observable',
'rxjs/observable/empty': 'Rx.Observable',

'rxjs/operators/finalize': 'Rx.Observable',
'rxjs/operators/catchError': 'Rx.Observable',
'rxjs/operators/combineLatest': 'Rx.Observable',

'rxjs/add/observable/merge': 'Rx.Observable',
'rxjs/add/observable/fromEvent': 'Rx.Observable',
'rxjs/add/observable/of': 'Rx.Observable',
'rxjs/add/observable/interval': 'Rx.Observable',
'rxjs/add/operator/startWith': 'Rx.Observable.prototype',
'rxjs/add/operator/map': 'Rx.Observable.prototype',
'rxjs/add/operator/debounceTime': 'Rx.Observable.prototype',
'rxjs/add/operator/distinctUntilChanged': 'Rx.Observable.prototype',
'rxjs/add/operator/first': 'Rx.Observable.prototype',
'rxjs/add/operator/catch': 'Rx.Observable.prototype',
'rxjs/add/operator/switchMap': 'Rx.Observable.prototype',


'rxjs/BehaviorSubject': 'Rx',
'rxjs/Observable': 'Rx',
'rxjs/Subject': 'Rx',
Expand All @@ -29,6 +74,8 @@ let globals = {
'rxjs/observable/fromEvent': 'Rx.Observable',
'rxjs/observable/merge': 'Rx.Observable',
'rxjs/observable/of': 'Rx.Observable',

// Legacy operators used by 3rd packages like @angular/core
'rxjs/operator/auditTime': 'Rx.Observable.prototype',
'rxjs/operator/catch': 'Rx.Observable.prototype',
'rxjs/operator/debounceTime': 'Rx.Observable.prototype',
Expand All @@ -45,6 +92,25 @@ let globals = {
'rxjs/operator/switchMap': 'Rx.Observable.prototype',
'rxjs/operator/takeUntil': 'Rx.Observable.prototype',
'rxjs/operator/throttleTime': 'Rx.Observable.prototype',

// Operators with chain-functionality itself (from rxjs 5.x) used by us
'rxjs/operators/auditTime': 'Rx.Observable.prototype',
'rxjs/operators/catch': 'Rx.Observable.prototype',
'rxjs/operators/debounceTime': 'Rx.Observable.prototype',
'rxjs/operators/delay': 'Rx.Observable.prototype',
'rxjs/operators/distinctUntilChanged': 'Rx.Observable.prototype',
'rxjs/operators/do': 'Rx.Observable.prototype',
'rxjs/operators/filter': 'Rx.Observable.prototype',
'rxjs/operators/finally': 'Rx.Observable.prototype',
'rxjs/operators/first': 'Rx.Observable.prototype',
'rxjs/operators/map': 'Rx.Observable.prototype',
'rxjs/operators/pluck': 'Rx.Observable.prototype',
'rxjs/operators/share': 'Rx.Observable.prototype',
'rxjs/operators/startWith': 'Rx.Observable.prototype',
'rxjs/operators/switchMap': 'Rx.Observable.prototype',
'rxjs/operators/takeUntil': 'Rx.Observable.prototype',
'rxjs/operators/throttleTime': 'Rx.Observable.prototype',
'rxjs/operators/tap': 'Rx.Observable.prototype',
};

if (format === 'es') {
Expand Down
68 changes: 39 additions & 29 deletions src/components/affix/nz-affix.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,25 @@ import {
Input,
EventEmitter,
Output,
Renderer2,
OnDestroy,
ViewChild,
ElementRef,
HostBinding
ElementRef
} from '@angular/core';
// import { Observable } from 'rxjs/Observable';
import { RxChain } from '@angular/cdk/rxjs';
import { fromEvent } from 'rxjs/observable/fromEvent';
import { throttleTime } from 'rxjs/operator/throttleTime';
import { distinctUntilChanged } from 'rxjs/operator/distinctUntilChanged';
import { Subscription } from 'rxjs/Subscription';
import { throttleTime } from 'rxjs/operators/throttleTime';
import { distinctUntilChanged } from 'rxjs/operators/distinctUntilChanged';

import { NzScrollService } from '../core/scroll/nz-scroll.service';

@Component({
selector: 'nz-affix',
selector : 'nz-affix',
encapsulation: ViewEncapsulation.None,
template: `<div #wrap><ng-content></ng-content></div>`,
styleUrls: [
template : `
<div #wrap>
<ng-content></ng-content>
</div>`,
styleUrls : [
'./style/index.less',
'./style/patch.less'
]
Expand All @@ -38,7 +37,7 @@ export class NzAffixComponent implements OnInit, OnDestroy {
private target: Element = null;
@ViewChild('wrap') private wrap: ElementRef;
// 缓存固定状态
private fixed: boolean = false;
private fixed = false;
// 原始位置
private orgOffset: { top: number, left: number };

Expand All @@ -48,41 +47,48 @@ export class NzAffixComponent implements OnInit, OnDestroy {
this.registerScrollEvent();
}

@Input() nzOffsetTop: number = 0;
@Input() nzOffsetTop = 0;

@Input() nzOffsetBottom: number = 0;
@Input() nzOffsetBottom = 0;

@Output() nzChange: EventEmitter<boolean> = new EventEmitter();

constructor(private scrollSrv: NzScrollService, private _el: ElementRef, private _renderer: Renderer2) { }
constructor(private scrollSrv: NzScrollService, private _el: ElementRef) {
}

ngOnInit(): void {
if (!this.scroll$) this.registerScrollEvent();
if (!this.scroll$) {
this.registerScrollEvent();
}
}

private getTarget(): Element | Window {
return this.target || window;
}

private reCalculate() {
let elOffset = this.scrollSrv.getOffset(this._el.nativeElement);
const elOffset = this.scrollSrv.getOffset(this._el.nativeElement);
this.orgOffset = {
top: elOffset.top + this.scrollSrv.getScroll(this.getTarget()),
top : elOffset.top + this.scrollSrv.getScroll(this.getTarget()),
left: elOffset.left + this.scrollSrv.getScroll(this.getTarget(), false)
};

return this;
}

private process() {
if (!this.orgOffset) this.reCalculate();
if (!this.orgOffset) {
this.reCalculate();
}
const containerScrollTop = this.scrollSrv.getScroll(this.getTarget());
let fixTop = this.getTarget() === window ? 0 : this.scrollSrv.getOffset(this.getTarget() as Element).top;
let hasFixed = this.orgOffset.top - fixTop - containerScrollTop - this.nzOffsetTop <= 0;
if (this.fixed === hasFixed) return;
const fixTop = this.getTarget() === window ? 0 : this.scrollSrv.getOffset(this.getTarget() as Element).top;
const hasFixed = this.orgOffset.top - fixTop - containerScrollTop - this.nzOffsetTop <= 0;
if (this.fixed === hasFixed) {
return;
}

const wrapEl = this.wrap.nativeElement;
wrapEl.classList[hasFixed ? 'add' : 'remove']('ant-affix');
wrapEl.classList[ hasFixed ? 'add' : 'remove' ]('ant-affix');
if (hasFixed) {
wrapEl.style.cssText = `top:${this.nzOffsetTop + fixTop}px;left:${this.orgOffset.left}px`;
} else {
Expand All @@ -94,9 +100,15 @@ export class NzAffixComponent implements OnInit, OnDestroy {
}

private removeListen() {
if (this.scrollTime) clearTimeout(this.scrollTime);
if (this.scroll$) this.scroll$.unsubscribe();
if (this.scrollWinInTarget$) this.scrollWinInTarget$.unsubscribe();
if (this.scrollTime) {
clearTimeout(this.scrollTime);
}
if (this.scroll$) {
this.scroll$.unsubscribe();
}
if (this.scrollWinInTarget$) {
this.scrollWinInTarget$.unsubscribe();
}
}

private registerScrollEvent() {
Expand All @@ -108,14 +120,12 @@ export class NzAffixComponent implements OnInit, OnDestroy {
this.process();
}
}, 100);
this.scroll$ = (RxChain.from(fromEvent(this.getTarget(), 'scroll')) as RxChain<any>)
this.scroll$ = fromEvent(this.getTarget(), 'scroll')
.subscribe(() => this.didScroll = true);

if (this.getTarget() !== window) {
// 当 window 滚动位发生变动时,需要重新计算滚动容器
this.scrollWinInTarget$ = (RxChain.from(fromEvent(window, 'scroll')) as RxChain<any>)
.call(throttleTime, 50)
.call(distinctUntilChanged)
this.scrollWinInTarget$ = fromEvent(window, 'scroll').pipe(throttleTime(50), distinctUntilChanged())
.subscribe(e => {
this.orgOffset = null;
this.fixed = false;
Expand Down
Loading

0 comments on commit 8dd8a43

Please sign in to comment.