Skip to content

Commit c1c3cb5

Browse files
Just Use Prettier™
1 parent 9f6ec33 commit c1c3cb5

26 files changed

+560
-368
lines changed

src/directives/uiSref.ts

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
/** @ng2api @module directives */
22
/** */
33
import { UIRouter, extend, Obj, TransitionOptions, TargetState, isNumber } from '@uirouter/core';
4-
import { Directive, Inject, Input, Optional, ElementRef, Renderer2, OnChanges, SimpleChanges, HostListener } from '@angular/core';
4+
import {
5+
Directive,
6+
Inject,
7+
Input,
8+
Optional,
9+
ElementRef,
10+
Renderer2,
11+
OnChanges,
12+
SimpleChanges,
13+
HostListener,
14+
} from '@angular/core';
515
import { UIView, ParentUIViewInject } from './uiView';
616
import { ReplaySubject } from 'rxjs/ReplaySubject';
717
import { Subscription } from 'rxjs/Subscription';
@@ -12,7 +22,7 @@ import { Subscription } from 'rxjs/Subscription';
1222
*/
1323
@Directive({ selector: 'a[uiSref]' })
1424
export class AnchorUISref {
15-
constructor(public _el: ElementRef, public _renderer: Renderer2) { }
25+
constructor(public _el: ElementRef, public _renderer: Renderer2) {}
1626
openInNewTab() {
1727
return this._el.nativeElement.target === '_blank';
1828
}
@@ -71,7 +81,6 @@ export class AnchorUISref {
7181
exportAs: 'uiSref',
7282
})
7383
export class UISref implements OnChanges {
74-
7584
/**
7685
* `@Input('uiSref')` The name of the state to link to
7786
*
@@ -112,9 +121,9 @@ export class UISref implements OnChanges {
112121
/** @internalapi */ private _parent: ParentUIViewInject;
113122

114123
constructor(
115-
_router: UIRouter,
116-
@Optional() _anchorUISref: AnchorUISref,
117-
@Inject(UIView.PARENT_INJECT) parent: ParentUIViewInject,
124+
_router: UIRouter,
125+
@Optional() _anchorUISref: AnchorUISref,
126+
@Inject(UIView.PARENT_INJECT) parent: ParentUIViewInject,
118127
) {
119128
this._router = _router;
120129
this._anchorUISref = _anchorUISref;
@@ -124,11 +133,20 @@ export class UISref implements OnChanges {
124133
}
125134

126135
/** @internalapi */
127-
set 'uiSref'(val: string) { this.state = val; this.update(); }
136+
set uiSref(val: string) {
137+
this.state = val;
138+
this.update();
139+
}
128140
/** @internalapi */
129-
set 'uiParams'(val: Obj) { this.params = val; this.update(); }
141+
set uiParams(val: Obj) {
142+
this.params = val;
143+
this.update();
144+
}
130145
/** @internalapi */
131-
set 'uiOptions'(val: TransitionOptions) { this.options = val; this.update(); }
146+
set uiOptions(val: TransitionOptions) {
147+
this.options = val;
148+
this.update();
149+
}
132150

133151
ngOnInit() {
134152
this._emit = true;
@@ -161,16 +179,20 @@ export class UISref implements OnChanges {
161179
getOptions() {
162180
const defaultOpts: TransitionOptions = {
163181
relative: this._parent && this._parent.context && this._parent.context.name,
164-
inherit: true ,
165-
source: 'sref'
182+
inherit: true,
183+
source: 'sref',
166184
};
167185
return extend(defaultOpts, this.options || {});
168186
}
169187

170188
/** When triggered by a (click) event, this function transitions to the UISref's target state */
171189
@HostListener('click', ['$event.button', '$event.ctrlKey', '$event.metaKey'])
172190
go(button: number, ctrlKey: boolean, metaKey: boolean) {
173-
if (this._anchorUISref && (this._anchorUISref.openInNewTab() || button || !isNumber(button) || ctrlKey || metaKey) || !this.state) {
191+
if (
192+
(this._anchorUISref &&
193+
(this._anchorUISref.openInNewTab() || button || !isNumber(button) || ctrlKey || metaKey)) ||
194+
!this.state
195+
) {
174196
return;
175197
}
176198

src/directives/uiSrefActive.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,20 @@ import { Subscription } from 'rxjs/Subscription';
8282
* ```
8383
*/
8484
@Directive({
85-
selector: '[uiSrefActive],[uiSrefActiveEq]'
85+
selector: '[uiSrefActive],[uiSrefActiveEq]',
8686
})
8787
export class UISrefActive {
88-
8988
private _classes: string[] = [];
90-
@Input('uiSrefActive') set active(val: string) { this._classes = val.split(/\s+/)};
89+
@Input('uiSrefActive')
90+
set active(val: string) {
91+
this._classes = val.split(/\s+/);
92+
}
9193

9294
private _classesEq: string[] = [];
93-
@Input('uiSrefActiveEq') set activeEq(val: string) { this._classesEq = val.split(/\s+/)};
95+
@Input('uiSrefActiveEq')
96+
set activeEq(val: string) {
97+
this._classesEq = val.split(/\s+/);
98+
}
9499

95100
private _subscription: Subscription;
96101
constructor(uiSrefStatus: UISrefStatus, rnd: Renderer, @Host() host: ElementRef) {

src/directives/uiSrefStatus.ts

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,18 @@
33
import { Directive, Output, EventEmitter, ContentChildren, QueryList } from '@angular/core';
44
import { UISref } from './uiSref';
55
import {
6-
PathNode, Transition, TargetState, StateObject, anyTrueR, tail, unnestR, Predicate, UIRouterGlobals, Param, PathUtils, StateOrName
6+
PathNode,
7+
Transition,
8+
TargetState,
9+
StateObject,
10+
anyTrueR,
11+
tail,
12+
unnestR,
13+
Predicate,
14+
UIRouterGlobals,
15+
Param,
16+
PathUtils,
17+
StateOrName,
718
} from '@uirouter/core';
819

920
import { Subscription } from 'rxjs/Subscription';
@@ -18,7 +29,10 @@ import { map } from 'rxjs/operator/map';
1829
import { concat } from 'rxjs/operator/concat';
1930

2031
/** @internalapi */
21-
interface TransEvt { evt: string; trans: Transition; }
32+
interface TransEvt {
33+
evt: string;
34+
trans: Transition;
35+
}
2236

2337
/**
2438
* UISref status emitted from [[UISrefStatus]]
@@ -58,9 +72,10 @@ const pathMatches = (target: TargetState): Predicate<PathNode[]> => {
5872
const state: StateObject = target.$state();
5973
const targetParamVals = target.params();
6074
const targetPath: PathNode[] = PathUtils.buildPath(target);
61-
const paramSchema: Param[] = targetPath.map(node => node.paramSchema)
62-
.reduce(unnestR, [])
63-
.filter((param: Param) => targetParamVals.hasOwnProperty(param.id));
75+
const paramSchema: Param[] = targetPath
76+
.map(node => node.paramSchema)
77+
.reduce(unnestR, [])
78+
.filter((param: Param) => targetParamVals.hasOwnProperty(param.id));
6479

6580
return (path: PathNode[]) => {
6681
const tailNode = tail(path);
@@ -98,22 +113,21 @@ function getSrefStatus(event: TransEvt, srefTarget: TargetState): SrefStatus {
98113
const activePath: PathNode[] = isSuccessEvent ? tc.to : tc.from;
99114

100115
const isActive = () =>
101-
spreadToSubPaths([], activePath)
102-
.map(pathMatchesTarget)
103-
.reduce(anyTrueR, false);
116+
spreadToSubPaths([], activePath)
117+
.map(pathMatchesTarget)
118+
.reduce(anyTrueR, false);
104119

105-
const isExact = () =>
106-
pathMatchesTarget(activePath);
120+
const isExact = () => pathMatchesTarget(activePath);
107121

108122
const isEntering = () =>
109-
spreadToSubPaths(tc.retained, tc.entering)
110-
.map(pathMatchesTarget)
111-
.reduce(anyTrueR, false);
123+
spreadToSubPaths(tc.retained, tc.entering)
124+
.map(pathMatchesTarget)
125+
.reduce(anyTrueR, false);
112126

113127
const isExiting = () =>
114-
spreadToSubPaths(tc.retained, tc.exiting)
115-
.map(pathMatchesTarget)
116-
.reduce(anyTrueR, false);
128+
spreadToSubPaths(tc.retained, tc.exiting)
129+
.map(pathMatchesTarget)
130+
.reduce(anyTrueR, false);
117131

118132
return {
119133
active: isActive(),
@@ -185,13 +199,14 @@ function mergeSrefStatus(left: SrefStatus, right: SrefStatus): SrefStatus {
185199
*/
186200
@Directive({
187201
selector: '[uiSrefStatus],[uiSrefActive],[uiSrefActiveEq]',
188-
exportAs: 'uiSrefStatus'
202+
exportAs: 'uiSrefStatus',
189203
})
190204
export class UISrefStatus {
191205
/** current statuses of the state/params the uiSref directive is linking to */
192206
@Output('uiSrefStatus') uiSrefStatus = new EventEmitter<SrefStatus>(false);
193207
/** Monitor all child components for UISref(s) */
194-
@ContentChildren(UISref, { descendants: true }) private _srefs: QueryList<UISref>;
208+
@ContentChildren(UISref, { descendants: true })
209+
private _srefs: QueryList<UISref>;
195210

196211
/** The current status */
197212
status: SrefStatus;
@@ -224,18 +239,20 @@ export class UISrefStatus {
224239
this._srefs$ = new BehaviorSubject(this._srefs.toArray());
225240
this._srefChangesSub = this._srefs.changes.subscribe(srefs => this._srefs$.next(srefs));
226241

227-
const targetStates$: Observable<TargetState[]> =
228-
switchMap.call(this._srefs$, (srefs: UISref[]) =>
229-
combineLatest<TargetState[]>(srefs.map(sref => sref.targetState$)));
242+
const targetStates$: Observable<TargetState[]> = switchMap.call(this._srefs$, (srefs: UISref[]) =>
243+
combineLatest<TargetState[]>(srefs.map(sref => sref.targetState$)),
244+
);
230245

231246
// Calculate the status of each UISref based on the transition event.
232247
// Reduce the statuses (if multiple) by or-ing each flag.
233-
this._subscription = switchMap.call(transEvents$, (evt: TransEvt) => {
234-
return map.call(targetStates$, (targets: TargetState[]) => {
235-
const statuses: SrefStatus[] = targets.map(target => getSrefStatus(evt, target));
236-
return statuses.reduce(mergeSrefStatus);
237-
});
238-
}).subscribe(this._setStatus.bind(this));
248+
this._subscription = switchMap
249+
.call(transEvents$, (evt: TransEvt) => {
250+
return map.call(targetStates$, (targets: TargetState[]) => {
251+
const statuses: SrefStatus[] = targets.map(target => getSrefStatus(evt, target));
252+
return statuses.reduce(mergeSrefStatus);
253+
});
254+
})
255+
.subscribe(this._setStatus.bind(this));
239256
}
240257

241258
ngOnDestroy() {

src/directives/uiView.ts

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,34 @@
11
/** @ng2api @module directives */
22
/** */
33
import {
4-
Component, ComponentFactoryResolver, ViewContainerRef, Input, ComponentRef, Type, ReflectiveInjector, ViewChild,
5-
Injector, Inject, ComponentFactory
4+
Component,
5+
ComponentFactoryResolver,
6+
ViewContainerRef,
7+
Input,
8+
ComponentRef,
9+
Type,
10+
ReflectiveInjector,
11+
ViewChild,
12+
Injector,
13+
Inject,
14+
ComponentFactory,
615
} from '@angular/core';
716

817
import {
9-
UIRouter, isFunction, Transition, parse, TransitionHookFn, StateDeclaration, inArray, trace, ViewContext, ViewConfig,
10-
ActiveUIView, ResolveContext, NATIVE_INJECTOR_TOKEN, flattenR
18+
UIRouter,
19+
isFunction,
20+
Transition,
21+
parse,
22+
TransitionHookFn,
23+
StateDeclaration,
24+
inArray,
25+
trace,
26+
ViewContext,
27+
ViewConfig,
28+
ActiveUIView,
29+
ResolveContext,
30+
NATIVE_INJECTOR_TOKEN,
31+
flattenR,
1132
} from '@uirouter/core';
1233
import { Ng2ViewConfig } from '../statebuilders/views';
1334
import { MergeInjector } from '../mergeInjector';
@@ -91,28 +112,32 @@ const ng2ComponentInputs = (factory: ComponentFactory<any>): InputMapping[] => {
91112
template: `
92113
<ng-template #componentTarget></ng-template>
93114
<ng-content *ngIf="!_componentRef"></ng-content>
94-
`
115+
`,
95116
})
96117
export class UIView {
97118
static PARENT_INJECT = 'UIView.PARENT_INJECT';
98119

99-
@ViewChild('componentTarget', { read: ViewContainerRef }) _componentTarget: ViewContainerRef;
120+
@ViewChild('componentTarget', { read: ViewContainerRef })
121+
_componentTarget: ViewContainerRef;
100122
@Input('name') name: string;
101-
@Input('ui-view') set _name(val: string) { this.name = val; }
123+
@Input('ui-view')
124+
set _name(val: string) {
125+
this.name = val;
126+
}
102127
/** The reference to the component currently inside the viewport */
103128
_componentRef: ComponentRef<any>;
104129
/** Deregisters the ui-view from the view service */
105130
private _deregisterUIView: Function;
106131
/** Deregisters the master uiCanExit transition hook */
107132
private _deregisterHook: Function;
108133
/** Data about the this UIView */
109-
private _uiViewData: ActiveUIView = <any> {};
134+
private _uiViewData: ActiveUIView = <any>{};
110135
private _parent: ParentUIViewInject;
111136

112137
constructor(
113-
public router: UIRouter,
114-
@Inject(UIView.PARENT_INJECT) parent,
115-
public viewContainerRef: ViewContainerRef,
138+
public router: UIRouter,
139+
@Inject(UIView.PARENT_INJECT) parent,
140+
public viewContainerRef: ViewContainerRef,
116141
) {
117142
this._parent = parent;
118143
}
@@ -136,7 +161,7 @@ export class UIView {
136161
fqn: parentFqn ? parentFqn + '.' + name : name,
137162
creationContext: this._parent.context,
138163
configUpdated: this._viewConfigUpdated.bind(this),
139-
config: undefined
164+
config: undefined,
140165
};
141166

142167
this._deregisterHook = router.transitionService.onBefore({}, trans => this._applyUiCanExitHook(trans));
@@ -232,7 +257,10 @@ export class UIView {
232257
*/
233258
private _getComponentInjector(context: ResolveContext): Injector {
234259
// Map resolves to "useValue: providers"
235-
const resolvables = context.getTokens().map(token => context.getResolvable(token)).filter(r => r.resolved);
260+
const resolvables = context
261+
.getTokens()
262+
.map(token => context.getResolvable(token))
263+
.filter(r => r.resolved);
236264
const newProviders = resolvables.map(r => ({ provide: r.token, useValue: r.data }));
237265

238266
const parentInject = { context: this._uiViewData.config.viewDecl.$context, fqn: this._uiViewData.fqn };
@@ -259,25 +287,29 @@ export class UIView {
259287
// return the `_foo` property
260288
const renamedInputProp = (prop: string) => {
261289
const input = factory.inputs.find(i => i.templateName === prop);
262-
return input && input.propName || prop;
290+
return (input && input.propName) || prop;
263291
};
264292

265293
// Supply resolve data to component as specified in the state's `bindings: {}`
266-
const explicitInputTuples = explicitBoundProps
267-
.reduce((acc, key) => acc.concat([{ prop: renamedInputProp(key), token: bindings[key] }]), []);
294+
const explicitInputTuples = explicitBoundProps.reduce(
295+
(acc, key) => acc.concat([{ prop: renamedInputProp(key), token: bindings[key] }]),
296+
[],
297+
);
268298

269299
// Supply resolve data to matching @Input('prop') or inputs: ['prop']
270-
const implicitInputTuples = ng2ComponentInputs(factory)
271-
.filter(tuple => !inArray(explicitBoundProps, tuple.prop));
300+
const implicitInputTuples = ng2ComponentInputs(factory).filter(tuple => !inArray(explicitBoundProps, tuple.prop));
272301

273302
const addResolvable = (tuple: InputMapping) => ({
274303
prop: tuple.prop,
275304
resolvable: context.getResolvable(tuple.token),
276305
});
277306

278-
explicitInputTuples.concat(implicitInputTuples)
279-
.map(addResolvable)
280-
.filter(tuple => tuple.resolvable && tuple.resolvable.resolved)
281-
.forEach(tuple => { component[tuple.prop] = tuple.resolvable.data; });
307+
explicitInputTuples
308+
.concat(implicitInputTuples)
309+
.map(addResolvable)
310+
.filter(tuple => tuple.resolvable && tuple.resolvable.resolved)
311+
.forEach(tuple => {
312+
component[tuple.prop] = tuple.resolvable.data;
313+
});
282314
}
283315
}

src/interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export interface Ng2StateDeclaration extends StateDeclaration, Ng2ViewDeclaratio
132132
* if _any view_ for a state is declared in the `views` object, then _all of the state's views_ must be defined in
133133
* the `views` object.
134134
*/
135-
views?: { [key: string]: Ng2ViewDeclaration; };
135+
views?: { [key: string]: Ng2ViewDeclaration };
136136

137137
/**
138138
* A string or function used to lazy load an `NgModule`

0 commit comments

Comments
 (0)