Skip to content

Commit 1541b90

Browse files
refactor(ViewConfig): Change how view decls are processed, loaded, and applied to uiviews
1 parent c1f1606 commit 1541b90

File tree

6 files changed

+27
-17
lines changed

6 files changed

+27
-17
lines changed

src/ng1/stateDirectives.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import {extend, forEach, toJson} from "../common/common";
44
import {isString, isObject} from "../common/predicates";
55
import {UIViewData} from "./viewDirective";
6+
import {parse} from "../common/hof";
67

78
function parseStateRef(ref, current) {
89
let preparsed = ref.match(/^\s*({[^}]*})\s*$/), parsed;
@@ -14,10 +15,8 @@ function parseStateRef(ref, current) {
1415

1516
function stateContext(el) {
1617
let $uiView: UIViewData = el.parent().inheritedData('$uiView');
17-
18-
if ($uiView && $uiView.$cfg.context && $uiView.$cfg.context.name) {
19-
return $uiView.$cfg.context;
20-
}
18+
let context = parse('$cfg.node.state')($uiView);
19+
return context && context.name ? context : undefined;
2120
}
2221

2322
function getTypeInfo(el) {

src/ng1/viewDirective.ts

+20-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
/** @module view */ /** for typedoc */
2+
"use strict";
23
import {extend, map} from "../common/common";
34
import {isDefined, isFunction} from "../common/predicates";
45
import {trace} from "../common/trace";
56
import {ActiveUIView} from "../view/interface";
67
import {Ng1ViewConfig} from "./viewsBuilder";
8+
import {RejectType} from "../transition/rejectFactory";
9+
import {TransitionService} from "../transition/transitionService";
10+
import {parse} from "../common/hof";
11+
import {ResolveContext} from "../resolve/resolveContext";
712

813
export type UIViewData = {
914
$cfg: Ng1ViewConfig;
@@ -174,7 +179,7 @@ function $ViewDirective( $view, $animate, $uiViewScroll, $interpolate,
174179
}
175180

176181
let rootData = {
177-
$cfg: { context: $view.rootContext() },
182+
$cfg: { viewDecl: { $context: $view.rootContext() } },
178183
$uiView: { }
179184
};
180185

@@ -201,7 +206,9 @@ function $ViewDirective( $view, $animate, $uiViewScroll, $interpolate,
201206
fqn: inherited.$uiView.fqn ? inherited.$uiView.fqn + "." + name : name, // fully qualified name, describes location in DOM
202207
config: null, // The ViewConfig loaded (from a state.views definition)
203208
configUpdated: configUpdatedCallback, // Called when the matching ViewConfig changes
204-
get creationContext() { return inherited.$cfg.context; } // The context in which this ui-view "tag" was created
209+
get creationContext() { // The context in which this ui-view "tag" was created
210+
return parse('$cfg.viewDecl.$context')(inherited);
211+
}
205212
};
206213

207214
trace.traceUiViewEvent("Linking", activeUIView);
@@ -298,8 +305,12 @@ function $ViewDirective( $view, $animate, $uiViewScroll, $interpolate,
298305
return directive;
299306
}
300307

301-
$ViewDirectiveFill.$inject = ['$compile', '$controller', '$interpolate', '$injector', '$q'];
302-
function $ViewDirectiveFill ( $compile, $controller, $interpolate, $injector, $q) {
308+
$ViewDirectiveFill.$inject = ['$compile', '$controller', '$transitions', '$view', '$timeout'];
309+
function $ViewDirectiveFill ( $compile, $controller, $transitions, $view, $timeout) {
310+
const getControllerAs = parse('viewDecl.controllerAs');
311+
const getResolveAs = parse('viewDecl.resolveAs');
312+
const getResolveContext = parse('node.resolveContext');
313+
303314
return {
304315
restrict: 'ECA',
305316
priority: -400,
@@ -310,15 +321,16 @@ function $ViewDirectiveFill ( $compile, $controller, $interpolate, $injec
310321
let data: UIViewData = $element.data('$uiView');
311322
if (!data) return;
312323

313-
let cfg: Ng1ViewConfig = data.$cfg || <any> {};
324+
let cfg: Ng1ViewConfig = data.$cfg || <any> { viewDecl: {} };
314325
$element.html(cfg.template || initial);
315326
trace.traceUiViewFill(data.$uiView, $element.html());
316327

317328
let link = $compile($element.contents());
318329
let controller = cfg.controller;
319-
let controllerAs = cfg.controllerAs;
320-
let resolveAs = cfg.resolveAs;
321-
let locals = map(cfg.node && cfg.node.resolves || {}, r => r.data);
330+
let controllerAs: string = getControllerAs(cfg);
331+
let resolveAs: string = getResolveAs(cfg);
332+
let resolveCtx: ResolveContext = getResolveContext(cfg);
333+
let locals = resolveCtx && map(resolveCtx.getResolvables(), r => r.data);
322334

323335
scope[resolveAs] = locals;
324336

src/ng1/viewsBuilder.ts

-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ export class Ng1ViewConfig implements ViewConfig {
5858
locals: any; // TODO: delete me
5959

6060
constructor(public node: Node, public viewDecl: Ng1ViewDeclaration) { }
61-
get context(): ViewContext { return this.viewDecl.$context; }
62-
get controllerAs() { return this.viewDecl.controllerAs; }
63-
get resolveAs() { return this.viewDecl.resolveAs; }
6461

6562
load() {
6663
let $q = services.$q;

src/view/view.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class ViewService {
4444
*/
4545
deactivateViewConfig(viewConfig: ViewConfig) {
4646
trace.traceViewServiceEvent("<- Removing", viewConfig);
47-
this.viewConfigs.filter(match(viewConfig, "uiViewName", "context")).forEach(removeFrom(this.viewConfigs));
47+
removeFrom(this.viewConfigs, viewConfig)
4848
};
4949

5050
activateViewConfig(viewConfig: ViewConfig) {

test/compat/matchers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ beforeEach(function() {
2626
actual.hasClass(clazz) :
2727
angular.element(actual).hasClass(clazz);
2828

29-
var message = pass ? undefined : "Expected '" + angular.mock.dump(this.actual) + "' to have class '" + clazz + "'.";
29+
var message = pass ? undefined : "Expected '" + angular.mock.dump(actual) + "' to have class '" + clazz + "'.";
3030

3131
return { pass: pass, message: message};
3232
}

test/stateDirectivesSpec.js

+2
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ describe('uiStateRef', function() {
136136
expect(obj($stateParams)).toEqualData({ id: 5 });
137137
}));
138138

139+
if (/PhantomJS/.exec(navigator.userAgent)) {
139140
it('should transition when given a click that contains no data (fake-click)', inject(function($state, $stateParams, $q) {
140141
expect($state.current.name).toEqual('top');
141142

@@ -213,6 +214,7 @@ describe('uiStateRef', function() {
213214
expect($state.current.name).toEqual('top');
214215
expect(obj($stateParams)).toEqualData({});
215216
}));
217+
}
216218

217219
it('should not transition states if preventDefault() is called in click handler', inject(function($state, $stateParams, $q) {
218220
expect($state.$current.name).toEqual('top');

0 commit comments

Comments
 (0)