From ef67a0c57fdf21d5fe3f46f1150123d6d22c9431 Mon Sep 17 00:00:00 2001 From: vsavkin Date: Fri, 22 Apr 2016 12:05:18 -0700 Subject: [PATCH] feat(router): add router metadata --- .../src/alt_router/metadata/decorators.dart | 8 +++++++ .../src/alt_router/metadata/decorators.ts | 7 ++++++ .../src/alt_router/metadata/metadata.ts | 23 +++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 modules/angular2/src/alt_router/metadata/decorators.dart create mode 100644 modules/angular2/src/alt_router/metadata/decorators.ts create mode 100644 modules/angular2/src/alt_router/metadata/metadata.ts diff --git a/modules/angular2/src/alt_router/metadata/decorators.dart b/modules/angular2/src/alt_router/metadata/decorators.dart new file mode 100644 index 0000000000..b230a6c4c0 --- /dev/null +++ b/modules/angular2/src/alt_router/metadata/decorators.dart @@ -0,0 +1,8 @@ +library angular.alt_router.decorators; + +import 'metadata.dart'; +export 'metadata.dart'; + +class Routes extends RoutesMetadata { + const Routes(List routes): super(routes); +} \ No newline at end of file diff --git a/modules/angular2/src/alt_router/metadata/decorators.ts b/modules/angular2/src/alt_router/metadata/decorators.ts new file mode 100644 index 0000000000..e4ecb4569b --- /dev/null +++ b/modules/angular2/src/alt_router/metadata/decorators.ts @@ -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 = makeDecorator(RoutesMetadata); diff --git a/modules/angular2/src/alt_router/metadata/metadata.ts b/modules/angular2/src/alt_router/metadata/metadata.ts new file mode 100644 index 0000000000..8eee6dbace --- /dev/null +++ b/modules/angular2/src/alt_router/metadata/metadata.ts @@ -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})`; } +} \ No newline at end of file