feat(router): add router metadata

This commit is contained in:
vsavkin 2016-04-22 12:05:18 -07:00 committed by Victor Savkin
parent ef6163e652
commit ef67a0c57f
3 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,8 @@
library angular.alt_router.decorators;
import 'metadata.dart';
export 'metadata.dart';
class Routes extends RoutesMetadata {
const Routes(List<RouteMetadata> routes): super(routes);
}

View File

@ -0,0 +1,7 @@
import {RoutesMetadata, RouteMetadata} from "./metadata";
import {makeDecorator} from 'angular2/src/core/util/decorators';
export interface RoutesFactory {
(routes: RouteMetadata[]): any;
new (routes: RouteMetadata[]): RoutesMetadata;
}
export var Routes: RoutesFactory = <RoutesFactory>makeDecorator(RoutesMetadata);

View File

@ -0,0 +1,23 @@
import {CONST, Type, stringify} from "angular2/src/facade/lang";
export abstract class RouteMetadata {
abstract get path(): string;
abstract get component(): Type;
}
@CONST()
export class Route implements RouteMetadata {
path: string;
component: Type;
constructor({path, component}: {path?: string, component?: Type} = {}) {
this.path = path;
this.component = component;
}
toString(): string { return `@Route(${this.path}, ${stringify(this.component)})`; }
}
@CONST()
export class RoutesMetadata {
constructor(public routes: RouteMetadata[]) {}
toString(): string { return `@Routes(${this.routes})`; }
}