feat(dom): add location and history as DOM-like APIs.

Instead of global access methods.
This commit is contained in:
Rado Kirov 2015-05-05 14:50:53 -07:00
parent 0520ca68b4
commit f356d03362
6 changed files with 34 additions and 4 deletions

View File

@ -307,4 +307,10 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter {
return document.body;
}
}
getHistory() {
return window.history;
}
getLocation() {
return window.location;
}
}

View File

@ -372,4 +372,10 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
return document.body;
}
}
getHistory() {
return window.history;
}
getLocation() {
return window.location;
}
}

View File

@ -283,4 +283,10 @@ export class DomAdapter {
getGlobalEventTarget(target:string) {
throw _abstract();
}
getHistory() {
throw _abstract();
}
getLocation() {
throw _abstract();
}
}

View File

@ -281,4 +281,10 @@ class Html5LibDomAdapter implements DomAdapter {
bool supportsNativeShadowDOM() {
throw 'not implemented';
}
getHistory() {
throw 'not implemented';
}
getLocation() {
throw 'not implemented';
}
}

View File

@ -523,6 +523,12 @@ export class Parse5DomAdapter extends DomAdapter {
return this.defaultDoc().body;
}
}
getHistory() {
throw 'not implemented';
}
getLocation() {
throw 'not implemented';
}
}
//TODO: build a proper list, this one is all the keys of a HTMLInputElement

View File

@ -1,4 +1,4 @@
import {global} from 'angular2/src/facade/lang';
import {DOM} from 'angular2/src/dom/dom_adapter';
import {EventEmitter, ObservableWrapper} from 'angular2/src/facade/async';
export class Location {
@ -7,9 +7,9 @@ export class Location {
_history;
constructor() {
this._subject = new EventEmitter();
this._location = global.location;
this._history = global.history;
global.addEventListener('popstate', (_) => this._onPopState(_), false);
this._location = DOM.getLocation();
this._history = DOM.getHistory();
DOM.getGlobalEventTarget('window').addEventListener('popstate', (_) => this._onPopState(_), false);
}
_onPopState(_) {