1 | "use strict";
|
2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
6 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7 | };
|
8 | var __metadata = (this && this.__metadata) || function (k, v) {
|
9 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
10 | };
|
11 | var __param = (this && this.__param) || function (paramIndex, decorator) {
|
12 | return function (target, key) { decorator(target, key, paramIndex); }
|
13 | };
|
14 | var core_1 = require('@angular/core');
|
15 | var async_1 = require('../facade/async');
|
16 | var collection_1 = require('../facade/collection');
|
17 | var lang_1 = require('../facade/lang');
|
18 | var instruction_1 = require('../instruction');
|
19 | var hookMod = require('../lifecycle/lifecycle_annotations');
|
20 | var route_lifecycle_reflector_1 = require('../lifecycle/route_lifecycle_reflector');
|
21 | var routerMod = require('../router');
|
22 | var _resolveToTrue = async_1.PromiseWrapper.resolve(true);
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | var RouterOutlet = (function () {
|
33 | function RouterOutlet(_viewContainerRef, _loader, _parentRouter, nameAttr) {
|
34 | this._viewContainerRef = _viewContainerRef;
|
35 | this._loader = _loader;
|
36 | this._parentRouter = _parentRouter;
|
37 | this.name = null;
|
38 | this._componentRef = null;
|
39 | this._currentInstruction = null;
|
40 | this.activateEvents = new async_1.EventEmitter();
|
41 | if (lang_1.isPresent(nameAttr)) {
|
42 | this.name = nameAttr;
|
43 | this._parentRouter.registerAuxOutlet(this);
|
44 | }
|
45 | else {
|
46 | this._parentRouter.registerPrimaryOutlet(this);
|
47 | }
|
48 | }
|
49 | |
50 |
|
51 |
|
52 |
|
53 | RouterOutlet.prototype.activate = function (nextInstruction) {
|
54 | var _this = this;
|
55 | var previousInstruction = this._currentInstruction;
|
56 | this._currentInstruction = nextInstruction;
|
57 | var componentType = nextInstruction.componentType;
|
58 | var childRouter = this._parentRouter.childRouter(componentType);
|
59 | var providers = core_1.ReflectiveInjector.resolve([
|
60 | { provide: instruction_1.RouteData, useValue: nextInstruction.routeData },
|
61 | { provide: instruction_1.RouteParams, useValue: new instruction_1.RouteParams(nextInstruction.params) },
|
62 | { provide: routerMod.Router, useValue: childRouter }
|
63 | ]);
|
64 | this._componentRef =
|
65 | this._loader.loadNextToLocation(componentType, this._viewContainerRef, providers);
|
66 | return this._componentRef.then(function (componentRef) {
|
67 | _this.activateEvents.emit(componentRef.instance);
|
68 | if (route_lifecycle_reflector_1.hasLifecycleHook(hookMod.routerOnActivate, componentType)) {
|
69 | return _this._componentRef.then(function (ref) {
|
70 | return ref.instance.routerOnActivate(nextInstruction, previousInstruction);
|
71 | });
|
72 | }
|
73 | else {
|
74 | return componentRef;
|
75 | }
|
76 | });
|
77 | };
|
78 | |
79 |
|
80 |
|
81 |
|
82 |
|
83 | RouterOutlet.prototype.reuse = function (nextInstruction) {
|
84 | var previousInstruction = this._currentInstruction;
|
85 | this._currentInstruction = nextInstruction;
|
86 |
|
87 |
|
88 |
|
89 | if (lang_1.isBlank(this._componentRef)) {
|
90 | return this.activate(nextInstruction);
|
91 | }
|
92 | else {
|
93 | return async_1.PromiseWrapper.resolve(route_lifecycle_reflector_1.hasLifecycleHook(hookMod.routerOnReuse, this._currentInstruction.componentType) ?
|
94 | this._componentRef.then(function (ref) {
|
95 | return ref.instance.routerOnReuse(nextInstruction, previousInstruction);
|
96 | }) :
|
97 | true);
|
98 | }
|
99 | };
|
100 | |
101 |
|
102 |
|
103 |
|
104 | RouterOutlet.prototype.deactivate = function (nextInstruction) {
|
105 | var _this = this;
|
106 | var next = _resolveToTrue;
|
107 | if (lang_1.isPresent(this._componentRef) && lang_1.isPresent(this._currentInstruction) &&
|
108 | route_lifecycle_reflector_1.hasLifecycleHook(hookMod.routerOnDeactivate, this._currentInstruction.componentType)) {
|
109 | next = this._componentRef.then(function (ref) {
|
110 | return ref.instance
|
111 | .routerOnDeactivate(nextInstruction, _this._currentInstruction);
|
112 | });
|
113 | }
|
114 | return next.then(function (_) {
|
115 | if (lang_1.isPresent(_this._componentRef)) {
|
116 | var onDispose = _this._componentRef.then(function (ref) { return ref.destroy(); });
|
117 | _this._componentRef = null;
|
118 | return onDispose;
|
119 | }
|
120 | });
|
121 | };
|
122 | |
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 | RouterOutlet.prototype.routerCanDeactivate = function (nextInstruction) {
|
131 | var _this = this;
|
132 | if (lang_1.isBlank(this._currentInstruction)) {
|
133 | return _resolveToTrue;
|
134 | }
|
135 | if (route_lifecycle_reflector_1.hasLifecycleHook(hookMod.routerCanDeactivate, this._currentInstruction.componentType)) {
|
136 | return this._componentRef.then(function (ref) {
|
137 | return ref.instance
|
138 | .routerCanDeactivate(nextInstruction, _this._currentInstruction);
|
139 | });
|
140 | }
|
141 | else {
|
142 | return _resolveToTrue;
|
143 | }
|
144 | };
|
145 | |
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 | RouterOutlet.prototype.routerCanReuse = function (nextInstruction) {
|
156 | var _this = this;
|
157 | var result;
|
158 | if (lang_1.isBlank(this._currentInstruction) ||
|
159 | this._currentInstruction.componentType != nextInstruction.componentType) {
|
160 | result = false;
|
161 | }
|
162 | else if (route_lifecycle_reflector_1.hasLifecycleHook(hookMod.routerCanReuse, this._currentInstruction.componentType)) {
|
163 | result = this._componentRef.then(function (ref) {
|
164 | return ref.instance.routerCanReuse(nextInstruction, _this._currentInstruction);
|
165 | });
|
166 | }
|
167 | else {
|
168 | result = nextInstruction == this._currentInstruction ||
|
169 | (lang_1.isPresent(nextInstruction.params) && lang_1.isPresent(this._currentInstruction.params) &&
|
170 | collection_1.StringMapWrapper.equals(nextInstruction.params, this._currentInstruction.params));
|
171 | }
|
172 | return async_1.PromiseWrapper.resolve(result);
|
173 | };
|
174 | RouterOutlet.prototype.ngOnDestroy = function () { this._parentRouter.unregisterPrimaryOutlet(this); };
|
175 | __decorate([
|
176 | core_1.Output('activate'),
|
177 | __metadata('design:type', Object)
|
178 | ], RouterOutlet.prototype, "activateEvents", void 0);
|
179 | RouterOutlet = __decorate([
|
180 | core_1.Directive({ selector: 'router-outlet' }),
|
181 | __param(3, core_1.Attribute('name')),
|
182 | __metadata('design:paramtypes', [core_1.ViewContainerRef, core_1.DynamicComponentLoader, routerMod.Router, String])
|
183 | ], RouterOutlet);
|
184 | return RouterOutlet;
|
185 | }());
|
186 | exports.RouterOutlet = RouterOutlet;
|
187 |
|
\ | No newline at end of file |