Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit fed87fa

Browse files
crisbetokara
authored andcommitted
fix(build): support Angular 4 and AOT (#255)
Fixes #254, #236, #227.
1 parent e0b9044 commit fed87fa

30 files changed

+384
-514
lines changed

package.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,27 @@
3636
"node": ">= 5.4.1 < 7"
3737
},
3838
"dependencies": {
39-
"@angular/common": "^2.3.5",
40-
"@angular/compiler": "^2.3.5",
41-
"@angular/core": "^2.3.5",
42-
"@angular/platform-browser": "^2.3.5",
43-
"@angular/platform-browser-dynamic": "^2.3.5",
39+
"@angular/common": "^4.0.0",
40+
"@angular/compiler": "^4.0.0",
41+
"@angular/core": "^4.0.0",
42+
"@angular/platform-browser": "^4.0.0",
43+
"@angular/platform-browser-dynamic": "^4.0.0",
4444
"@types/gulp-util": "^3.0.30",
4545
"core-js": "^2.4.1",
4646
"reflect-metadata": "^0.1.8",
4747
"rxjs": "^5.0.1",
4848
"systemjs": "^0.19.41",
49-
"zone.js": "^0.7.2"
49+
"zone.js": "^0.8.4"
5050
},
5151
"devDependencies": {
52-
"@angular/compiler-cli": "^2.3.5",
53-
"@angular/forms": "^2.3.5",
54-
"@angular/http": "^2.3.5",
55-
"@angular/material": "^2.0.0-beta.2",
56-
"@angular/platform-server": "^2.3.5",
57-
"@angular/router": "~3.1.1",
58-
"@angular/tsc-wrapped": "~0.4.0",
52+
"@angular/animations": "^4.0.1",
53+
"@angular/compiler-cli": "^4.0.0",
54+
"@angular/forms": "^4.0.0",
55+
"@angular/http": "^4.0.0",
56+
"@angular/material": "^2.0.0-beta.3",
57+
"@angular/platform-server": "^4.0.0",
58+
"@angular/router": "^4.0.0",
59+
"@angular/tsc-wrapped": "~4.0.0",
5960
"@angularclass/conventions-loader": "^1.0.2",
6061
"@angularclass/request-idle-callback": "^1.0.7",
6162
"@angularclass/webpack-toolkit": "^1.3.3",
@@ -72,7 +73,6 @@
7273
"@types/source-map": "^0.1.27",
7374
"@types/uglify-js": "^2.0.27",
7475
"@types/webpack": "^1.12.34",
75-
"angular-in-memory-web-api": "~0.1.13",
7676
"angular2-template-loader": "^0.6.0",
7777
"assets-webpack-plugin": "^3.4.0",
7878
"awesome-typescript-loader": "3.0.0-beta.9",
@@ -131,7 +131,7 @@
131131
"ts-node": "^0.7.3",
132132
"tslint": "^4.2.0",
133133
"tslint-loader": "^3.3.0",
134-
"typescript": "^2.0.10",
134+
"typescript": "^2.1.10",
135135
"url-loader": "^0.5.7",
136136
"webpack": "2.2.0-rc.3",
137137
"webpack-bundle-analyzer": "^2.2.0",

src/demo-app/index.html

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,18 @@
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0">
66
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7-
7+
88
<title>Angular Layouts</title>
99
<base href="/">
1010

1111
<link href="https://fonts.googleapis.com/css?family=Roboto:400,500,700" rel="stylesheet">
1212
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
13-
14-
<link href="https://unpkg.com/@angular/material/core/theming/prebuilt/indigo-pink.css" rel="stylesheet">
15-
<script src="https://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.8/hammer.min.js"></script>
16-
17-
<!--<link href="./assets/indigo-pink.css" rel="stylesheet">-->
18-
<!--<script src="./assets/hammer.min.js"></script>-->
19-
13+
<link href="../node_modules/@angular/material/prebuilt-themes/indigo-pink.css" rel="stylesheet">
14+
2015
</head>
2116
<body>
2217
<demo-app>Loading...</demo-app>
2318

19+
<script src="https://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.8/hammer.min.js"></script>
2420
</body>
2521
</html>

src/lib/flexbox/api/base-adapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import {ElementRef, Renderer} from '@angular/core';
8+
import {ElementRef, Renderer2} from '@angular/core';
99

1010
import {BaseFxDirective} from './base';
1111
import {ResponsiveActivation} from './../responsive/responsive-activation';
@@ -48,7 +48,7 @@ export class BaseFxDirectiveAdapter extends BaseFxDirective {
4848
constructor(protected _baseKey: string, // non-responsive @Input property name
4949
protected _mediaMonitor: MediaMonitor,
5050
protected _elementRef: ElementRef,
51-
protected _renderer: Renderer ) {
51+
protected _renderer: Renderer2 ) {
5252
super(_mediaMonitor, _elementRef, _renderer);
5353
}
5454

src/lib/flexbox/api/base.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import {ElementRef, Renderer, OnDestroy} from '@angular/core';
8+
import {ElementRef, Renderer2, OnDestroy} from '@angular/core';
99

1010
import {applyCssPrefixes} from '../../utils/auto-prefixer';
1111
import {buildLayoutCSS} from '../../utils/layout-validator';
@@ -32,7 +32,7 @@ export abstract class BaseFxDirective implements OnDestroy {
3232
*/
3333
constructor(protected _mediaMonitor: MediaMonitor,
3434
protected _elementRef: ElementRef,
35-
protected _renderer: Renderer) {
35+
protected _renderer: Renderer2) {
3636
this._display = this._getDisplayStyle();
3737
}
3838

@@ -121,9 +121,9 @@ export abstract class BaseFxDirective implements OnDestroy {
121121
styles = applyCssPrefixes(style);
122122

123123
// Iterate all properties in hashMap and set styles
124-
for (let key in styles) {
125-
this._renderer.setElementStyle(element, key, styles[key] as string);
126-
}
124+
Object.keys(styles).forEach(key => {
125+
this._renderer.setStyle(element, key, styles[key]);
126+
});
127127
}
128128

129129
/**
@@ -132,13 +132,9 @@ export abstract class BaseFxDirective implements OnDestroy {
132132
protected _applyStyleToElements(style: StyleDefinition, elements: HTMLElement[ ]) {
133133
let styles = applyCssPrefixes(style);
134134

135-
elements.forEach(el => {
136-
// Iterate all properties in hashMap and set styles
137-
for (let key in styles) {
138-
this._renderer.setElementStyle(el, key, styles[key] as string);
139-
}
135+
Object.keys(styles).forEach(key => {
136+
elements.forEach(el => this._renderer.setStyle(el, key, styles[key]));
140137
});
141-
142138
}
143139

144140
/**

src/lib/flexbox/api/class.spec.ts

Lines changed: 50 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
import {Component, OnInit} from '@angular/core';
99
import {CommonModule} from '@angular/common';
10-
import {ComponentFixture, TestBed, async} from '@angular/core/testing';
10+
import {ComponentFixture, TestBed, async, inject} from '@angular/core/testing';
1111

1212
import {customMatchers} from '../../utils/testing/custom-matchers';
1313
import {makeCreateTestComponent, expectNativeEl} from '../../utils/testing/helpers';
@@ -23,10 +23,13 @@ import {MediaQueriesModule} from '../../media-query/_module';
2323

2424
describe('class directive', () => {
2525
let fixture: ComponentFixture<any>;
26-
let createTestComponent = makeCreateTestComponent(() => TestClassComponent);
27-
let activateMediaQuery: Function = (alias, useOverlaps = false): void => {
28-
let matchMedia: MockMatchMedia = fixture.debugElement.injector.get(MatchMedia);
29-
matchMedia.activate(alias, useOverlaps);
26+
let matchMedia: MockMatchMedia;
27+
let createTestComponent = (template: string) => {
28+
fixture = makeCreateTestComponent(() => TestClassComponent)(template);
29+
30+
inject([MatchMedia], (_matchMedia: MockMatchMedia) => {
31+
matchMedia = _matchMedia;
32+
})();
3033
};
3134

3235
beforeEach(() => {
@@ -42,163 +45,139 @@ describe('class directive', () => {
4245
]
4346
});
4447
});
45-
afterEach(() => {
46-
if (fixture) {
47-
fixture.debugElement.injector.get(MatchMedia).clearAll();
48-
fixture = null;
49-
}
50-
});
5148

52-
['xs', 'sm', 'md', 'lg']
53-
.forEach(mq => {
54-
const selector = `class-${mq}`;
55-
it(`should apply '${selector}' with '${mq}' media query`, () => {
56-
fixture = createTestComponent(`
57-
<div ngClass.${mq}="${selector}">
58-
</div>
59-
`);
60-
activateMediaQuery(mq);
61-
expectNativeEl(fixture).toHaveCssClass(selector);
62-
});
63-
});
49+
['xs', 'sm', 'md', 'lg'].forEach(mq => {
50+
const selector = `class-${mq}`;
51+
52+
it(`should apply '${selector}' with '${mq}' media query`, () => {
53+
createTestComponent(`<div ngClass.${mq}="${selector}"></div>`);
54+
matchMedia.activate(mq);
55+
expectNativeEl(fixture).toHaveCssClass(selector);
56+
});
57+
});
6458

6559
it('should merge `ngClass` values with any `class` values', () => {
66-
fixture = createTestComponent(`
67-
<div class="class0" ngClass="class1 class2">
68-
</div>
69-
`);
60+
createTestComponent(`<div class="class0" ngClass="class1 class2"></div>`);
7061

7162
expectNativeEl(fixture).toHaveCssClass('class0');
7263
expectNativeEl(fixture).toHaveCssClass('class1');
7364
expectNativeEl(fixture).toHaveCssClass('class2');
7465
});
7566

7667
it('should override base `class` values with responsive values', () => {
77-
fixture = createTestComponent(`
78-
<div class="class0"
79-
class.xs="class1 class2"
80-
ngClass.xs="what">
81-
</div>
82-
`);
68+
createTestComponent(`<div class="class0" class.xs="class1 class2" ngClass.xs="what"></div>`);
8369

8470
expectNativeEl(fixture).toHaveCssClass('class0');
8571
expectNativeEl(fixture).not.toHaveCssClass('class1');
8672
expectNativeEl(fixture).not.toHaveCssClass('class2');
8773

88-
activateMediaQuery('xs');
74+
matchMedia.activate('xs');
8975
expectNativeEl(fixture).not.toHaveCssClass('class0');
9076
expectNativeEl(fixture).toHaveCssClass('class1');
9177
expectNativeEl(fixture).toHaveCssClass('class2');
9278

93-
// activateMediaQuery('lg');
79+
// matchMedia.activate('lg');
9480
// expectNativeEl(fixture).toHaveCssClass('class0');
9581
// expectNativeEl(fixture).not.toHaveCssClass('class1');
9682
// expectNativeEl(fixture).not.toHaveCssClass('class2');
9783
});
9884

9985
it('should keep the raw existing `class` with responsive updates', () => {
100-
fixture = createTestComponent(`
86+
createTestComponent(`
10187
<div class="existing-class" ngClass="class1" ngClass.xs="xs-class">
10288
</div>
10389
`);
10490

10591
expectNativeEl(fixture).toHaveCssClass('existing-class');
10692
expectNativeEl(fixture).toHaveCssClass('class1');
10793

108-
activateMediaQuery('xs');
94+
matchMedia.activate('xs');
10995
expectNativeEl(fixture).toHaveCssClass('xs-class');
11096
expectNativeEl(fixture).toHaveCssClass('existing-class');
11197
expectNativeEl(fixture).not.toHaveCssClass('class1');
11298

113-
activateMediaQuery('lg');
99+
matchMedia.activate('lg');
114100
expectNativeEl(fixture).not.toHaveCssClass('xs-class');
115101
expectNativeEl(fixture).toHaveCssClass('existing-class');
116102
expectNativeEl(fixture).toHaveCssClass('class1');
117103
});
118104

119105

120106
it('should keep allow removal of class selector', () => {
121-
fixture = createTestComponent(`
122-
<div
123-
class="existing-class"
124-
[ngClass.xs]="{'xs-class':true, 'existing-class':false}">
125-
</div>
107+
createTestComponent(`
108+
<div
109+
class="existing-class"
110+
[ngClass.xs]="{'xs-class':true, 'existing-class':false}">
111+
</div>
126112
`);
127113

128114
expectNativeEl(fixture).toHaveCssClass('existing-class');
129-
activateMediaQuery('xs');
115+
matchMedia.activate('xs');
130116
expectNativeEl(fixture).not.toHaveCssClass('existing-class');
131117
expectNativeEl(fixture).toHaveCssClass('xs-class');
132118

133-
activateMediaQuery('lg');
119+
matchMedia.activate('lg');
134120
expectNativeEl(fixture).toHaveCssClass('existing-class');
135121
expectNativeEl(fixture).not.toHaveCssClass('xs-class');
136122
});
137123

138124
it('should keep existing ngClass selector', () => {
139125
// @see documentation for @angular/core ngClass =http://bit.ly/2mz0LAa
140-
fixture = createTestComponent(`
141-
<div class="always"
142-
ngClass="existing-class"
143-
ngClass.xs="existing-class xs-class">
144-
</div>
126+
createTestComponent(`
127+
<div class="always"
128+
ngClass="existing-class"
129+
ngClass.xs="existing-class xs-class">
130+
</div>
145131
`);
146132

147133
expectNativeEl(fixture).toHaveCssClass('always');
148134
expectNativeEl(fixture).toHaveCssClass('existing-class');
149135

150-
activateMediaQuery('xs');
136+
matchMedia.activate('xs');
151137
expectNativeEl(fixture).toHaveCssClass('always');
152138
expectNativeEl(fixture).toHaveCssClass('existing-class');
153139
expectNativeEl(fixture).toHaveCssClass('xs-class');
154140

155-
activateMediaQuery('lg');
141+
matchMedia.activate('lg');
156142
expectNativeEl(fixture).toHaveCssClass('always');
157143
expectNativeEl(fixture).toHaveCssClass('existing-class');
158144
expectNativeEl(fixture).not.toHaveCssClass('xs-class');
159145
});
160146

161147
it('should support more than one responsive breakpoint on one element', () => {
162-
fixture = createTestComponent(`
163-
<div ngClass.xs="xs-class"
164-
ngClass.md="md-class">
165-
</div>
166-
`);
167-
activateMediaQuery('xs');
148+
createTestComponent(`<div ngClass.xs="xs-class" ngClass.md="md-class"></div>`);
149+
matchMedia.activate('xs');
168150
expectNativeEl(fixture).toHaveCssClass('xs-class');
169151
expectNativeEl(fixture).not.toHaveCssClass('md-class');
170-
activateMediaQuery('md');
152+
matchMedia.activate('md');
171153
expectNativeEl(fixture).not.toHaveCssClass('xs-class');
172154
expectNativeEl(fixture).toHaveCssClass('md-class');
173155
});
174156

175157
it('should work with ngClass object notation', () => {
176-
fixture = createTestComponent(`
177-
<div [ngClass]="{'x1': hasX1, 'x3': hasX3}"
178-
[ngClass.xs]="{'x1': hasX1, 'x2': hasX2}">
179-
</div>
158+
createTestComponent(`
159+
<div [ngClass]="{'x1': hasX1, 'x3': hasX3}"
160+
[ngClass.xs]="{'x1': hasX1, 'x2': hasX2}">
161+
</div>
180162
`);
181163
expectNativeEl(fixture, {hasX1: true, hasX2: true, hasX3: true}).toHaveCssClass('x1');
182164
expectNativeEl(fixture, {hasX1: true, hasX2: true, hasX3: true}).not.toHaveCssClass('x2');
183165
expectNativeEl(fixture, {hasX1: true, hasX2: true, hasX3: true}).toHaveCssClass('x3');
184166

185-
activateMediaQuery('X');
167+
matchMedia.activate('X');
186168
expectNativeEl(fixture, {hasX1: true, hasX2: false, hasX3: false}).toHaveCssClass('x1');
187169
expectNativeEl(fixture, {hasX1: true, hasX2: false, hasX3: false}).not.toHaveCssClass('x2');
188170
expectNativeEl(fixture, {hasX1: true, hasX2: false, hasX3: false}).not.toHaveCssClass('x3');
189171

190-
activateMediaQuery('md');
172+
matchMedia.activate('md');
191173
expectNativeEl(fixture, {hasX1: true, hasX2: false, hasX3: true}).toHaveCssClass('x1');
192174
expectNativeEl(fixture, {hasX1: true, hasX2: false, hasX3: true}).not.toHaveCssClass('x2');
193175
expectNativeEl(fixture, {hasX1: true, hasX2: false, hasX3: true}).toHaveCssClass('x3');
194176
});
195177

196178
it('should work with ngClass array notation', () => {
197-
fixture = createTestComponent(`
198-
<div [ngClass.xs]="['xs-1', 'xs-2']">
199-
</div>
200-
`);
201-
activateMediaQuery('xs');
179+
createTestComponent(`<div [ngClass.xs]="['xs-1', 'xs-2']"></div>`);
180+
matchMedia.activate('xs');
202181
expectNativeEl(fixture).toHaveCssClass('xs-1');
203182
expectNativeEl(fixture).toHaveCssClass('xs-2');
204183
});
@@ -565,7 +544,7 @@ describe('binding to CSS class list', () => {
565544

566545
@Component({selector: 'test-cmp', template: ''})
567546
class TestComponent {
568-
condition: boolean = true;
547+
condition = true;
569548
items: any[];
570549
arrExpr: string[] = ['foo'];
571550
setExpr: Set<string> = new Set<string>();

0 commit comments

Comments
 (0)