Skip to content

Instantly share code, notes, and snippets.

@manekinekko
Last active August 29, 2015 14:27
Show Gist options
  • Save manekinekko/5598468c1e64c84d4481 to your computer and use it in GitHub Desktop.
Save manekinekko/5598468c1e64c84d4481 to your computer and use it in GitHub Desktop.
A proposal for universal/server_router module.
/// <reference path="../typings/tsd.d.ts" />
import {Injectable, bind} from 'angular2/di';
// error TS2307: Cannot find module 'angular2/src/router/location_strategy'.
import {LocationStrategy} from 'angular2/src/router/location_strategy';
class MockServerHistory implements History {
length: number;
state: any;
constructor(){/*TODO*/}
back(distance?: any): void {/*TODO*/}
forward(distance?: any): void {/*TODO*/}
go(delta?: any): void {/*TODO*/}
pushState(statedata: any, title?: string, url?: string): void {/*TODO*/}
replaceState(statedata: any, title?: string, url?: string): void {/*TODO*/}
}
class MockServerLocation implements Location {
hash: string;
host: string;
hostname: string;
href: string;
origin: string;
pathname: string;
port: string;
protocol: string;
search: string;
constructor(){/*TODO*/}
assign(url: string): void {/*TODO*/}
reload(forcedReload?: boolean): void {/*TODO*/}
replace(url: string): void {/*TODO*/}
toString(): string { /*TODO*/ return ''; }
}
@Injectable()
export class ServerLocationStrategy extends LocationStrategy {
private _location: Location;
private _history: History;
private _baseHref: string;
constructor() {
super();
this._location = new MockServerLocation();
this._history = new MockServerHistory();
this._baseHref = '/';
}
onPopState(fn: EventListener): void {/*TODO*/}
getBaseHref(): string { return this._baseHref; }
path(): string { return this._location.pathname; }
pushState(state: any, title: string, url: string) {/*TODO*/}
forward(): void {
this._history.forward();
}
back(): void {
this._history.back();
}
}
export const locationInjectables: Array<any> = [
bind(LocationStrategy).toClass(ServerLocationStrategy)
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment