Skip to content

Commit 3e5ef86

Browse files
committed
Minor refactoring related to module instantiation
1 parent b095eef commit 3e5ef86

File tree

21 files changed

+289
-184
lines changed

21 files changed

+289
-184
lines changed

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"reflect-metadata": "^0.1.9",
4343
"rimraf": "^2.5.4",
4444
"rxjs": "^5.1.0",
45-
"typescript": "^2.1.5"
45+
"typescript": "^2.1.6"
4646
},
4747
"devDependencies": {
4848
"@angular/common": "^2.4.6",
@@ -59,12 +59,17 @@
5959
"zone.js": "^0.7.6"
6060
},
6161
"jest": {
62-
"modulePaths": ["<rootDir>/source"],
62+
"modulePaths": [
63+
"<rootDir>/source"
64+
],
6365
"setupTestFrameworkScriptFile": "jasmine-promises",
6466
"transform": {
6567
".ts": "<rootDir>/node_modules/ts-jest/preprocessor.js"
6668
},
6769
"testRegex": "source/.*/tests/.*\\.ts$",
68-
"moduleFileExtensions": ["ts", "js"]
70+
"moduleFileExtensions": [
71+
"ts",
72+
"js"
73+
]
6974
}
7075
}

source/disposable.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface Disposable {
2+
dispose(): void;
3+
}

source/exception.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export class Exception extends Error {
55

66
public get stack(): string {
77
if (this.innerException) {
8-
return `${super.stack} -> (inner ex) ${this.innerException.stack}`;
8+
return `${super.stack} -> ${this.innerException.stack}`;
99
}
1010

1111
return super.stack;

source/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import './dependencies';
22

33
export * from './exception';
44
export * from './platform';
5+
export * from './publisher';
56
export * from './service';
67
export * from './transformation';
78
export * from './variance';
8-
export * from './subscription';
Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const domino = require('domino');
88

99
import {TemplateDocument, RequestUri} from './tokens';
1010

11+
import {PlatformException} from '../exception';
12+
1113
@Injectable()
1214
export class DocumentContainer implements OnDestroy {
1315
private windowRef: Window;
@@ -20,15 +22,14 @@ export class DocumentContainer implements OnDestroy {
2022
}
2123

2224
get window(): Window {
23-
if (this.windowRef == null) {
24-
throw new Error('No window container has been initialized');
25-
}
26-
return this.windowRef;
25+
return this.windowRef || (() => {
26+
throw new PlatformException('No window container has been initialized');
27+
})();
2728
}
2829

2930
get document(): Document {
3031
if (this.windowRef == null) {
31-
throw new Error('No DOM has been initialized');
32+
throw new PlatformException('No DOM has been initialized');
3233
}
3334
return this.windowRef.document;
3435
}
@@ -40,7 +41,15 @@ export class DocumentContainer implements OnDestroy {
4041
ngOnDestroy() {
4142
this.complete();
4243

43-
this.window.releaseEvents();
44+
// This may seem pointless but we just want to release all references
45+
// to the node elements in this document so that they can be garbage
46+
// collected.
47+
if (this.document) {
48+
const child = () => this.document.body.firstChild;
49+
while (child()) {
50+
this.document.removeChild(child());
51+
}
52+
}
4453

4554
this.windowRef = null;
4655
}

source/platform/document/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export * from './document';
1+
export * from './container';
22
export * from './tokens';

source/platform/exception-stream/exception-stream.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {Observable, ReplaySubject} from 'rxjs';
44

55
import {ErrorHandlerImpl} from './handler';
66

7-
import {Subscription} from 'subscription';
7+
import {Subscription} from 'publisher';
88

99
@Injectable()
1010
export class ExceptionStream implements OnDestroy {
Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Injectable, ErrorHandler, OnDestroy} from '@angular/core';
22

3-
import {Subscription} from 'subscription';
3+
import {Publisher, Subscription} from 'publisher';
44

55
export type ExceptionHandler = (exception: Error) => void;
66

@@ -10,23 +10,19 @@ export class ErrorHandlerImpl extends ErrorHandler implements OnDestroy {
1010
super(true);
1111
}
1212

13-
private subscriptions = new Set<ExceptionHandler>();
13+
private subscriber = new Publisher<ExceptionHandler>();
1414

1515
subscribe(handler: ExceptionHandler): Subscription {
16-
this.subscriptions.add(handler);
17-
18-
return {
19-
unsubscribe: () => this.subscriptions.delete(handler)
20-
};
16+
return this.subscriber.subscribe(handler);
2117
}
2218

2319
handleError(exception: Error) {
24-
this.subscriptions.forEach(subscription => subscription(exception));
20+
this.subscriber.publish(exception);
2521

2622
super.handleError(exception);
2723
}
2824

2925
ngOnDestroy() {
30-
this.subscriptions.clear();
26+
this.subscriber.dispose();
3127
}
3228
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import {Exception} from '../../exception';
1+
import {Exception} from '../exception';
22

33
export class PlatformException extends Exception {}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {Exception} from '../../exception';
2+
3+
export class ModuleException extends Exception {}

0 commit comments

Comments
 (0)