Skip to content

Commit f356d03

Browse files
committed
feat(dom): add location and history as DOM-like APIs.
Instead of global access methods.
1 parent 0520ca6 commit f356d03

File tree

6 files changed

+34
-4
lines changed

6 files changed

+34
-4
lines changed

modules/angular2/src/dom/browser_adapter.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,4 +307,10 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter {
307307
return document.body;
308308
}
309309
}
310+
getHistory() {
311+
return window.history;
312+
}
313+
getLocation() {
314+
return window.location;
315+
}
310316
}

modules/angular2/src/dom/browser_adapter.es6

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,4 +372,10 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
372372
return document.body;
373373
}
374374
}
375+
getHistory() {
376+
return window.history;
377+
}
378+
getLocation() {
379+
return window.location;
380+
}
375381
}

modules/angular2/src/dom/dom_adapter.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,10 @@ export class DomAdapter {
283283
getGlobalEventTarget(target:string) {
284284
throw _abstract();
285285
}
286+
getHistory() {
287+
throw _abstract();
288+
}
289+
getLocation() {
290+
throw _abstract();
291+
}
286292
}

modules/angular2/src/dom/html_adapter.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,4 +281,10 @@ class Html5LibDomAdapter implements DomAdapter {
281281
bool supportsNativeShadowDOM() {
282282
throw 'not implemented';
283283
}
284+
getHistory() {
285+
throw 'not implemented';
286+
}
287+
getLocation() {
288+
throw 'not implemented';
289+
}
284290
}

modules/angular2/src/dom/parse5_adapter.cjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,12 @@ export class Parse5DomAdapter extends DomAdapter {
523523
return this.defaultDoc().body;
524524
}
525525
}
526+
getHistory() {
527+
throw 'not implemented';
528+
}
529+
getLocation() {
530+
throw 'not implemented';
531+
}
526532
}
527533

528534
//TODO: build a proper list, this one is all the keys of a HTMLInputElement

modules/angular2/src/router/location.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {global} from 'angular2/src/facade/lang';
1+
import {DOM} from 'angular2/src/dom/dom_adapter';
22
import {EventEmitter, ObservableWrapper} from 'angular2/src/facade/async';
33

44
export class Location {
@@ -7,9 +7,9 @@ export class Location {
77
_history;
88
constructor() {
99
this._subject = new EventEmitter();
10-
this._location = global.location;
11-
this._history = global.history;
12-
global.addEventListener('popstate', (_) => this._onPopState(_), false);
10+
this._location = DOM.getLocation();
11+
this._history = DOM.getHistory();
12+
DOM.getGlobalEventTarget('window').addEventListener('popstate', (_) => this._onPopState(_), false);
1313
}
1414

1515
_onPopState(_) {

0 commit comments

Comments
 (0)