From d42e37b21541c379970d9f9fa0d4597a055960e5 Mon Sep 17 00:00:00 2001 From: Hristo Deshev Date: Mon, 21 Nov 2016 18:38:51 +0200 Subject: [PATCH 1/2] Enable TypeScript checks for unused locals and parameters. --- nativescript-angular/animation-driver.ts | 2 +- nativescript-angular/animation-player.ts | 4 +- nativescript-angular/collection-facade.ts | 63 ------------------- .../common/detached-loader.ts | 6 -- nativescript-angular/directives/action-bar.ts | 2 +- nativescript-angular/directives/dialogs.ts | 2 +- .../directives/list-view-comp.ts | 4 +- nativescript-angular/directives/tab-view.ts | 10 +-- nativescript-angular/dom-adapter.ts | 18 +++--- nativescript-angular/http/ns-http.ts | 4 +- nativescript-angular/parse5_adapter.ts | 40 ++++++------ nativescript-angular/platform-common.ts | 16 ++--- nativescript-angular/platform-providers.ts | 14 ++++- nativescript-angular/platform.ts | 10 ++- nativescript-angular/renderer.ts | 16 ++--- .../router/ns-platform-location.ts | 4 +- .../router/ns-router-link-active.ts | 4 +- nativescript-angular/router/ns-router-link.ts | 2 +- .../router/page-router-outlet.ts | 3 +- nativescript-angular/tsconfig.json | 4 +- .../value-accessors/base-value-accessor.ts | 5 +- .../value-accessors/checked-value-accessor.ts | 2 +- .../value-accessors/date-value-accessor.ts | 2 +- .../value-accessors/number-value-accessor.ts | 2 +- .../selectedIndex-value-accessor.ts | 3 +- .../value-accessors/text-value-accessor.ts | 2 +- .../value-accessors/time-value-accessor.ts | 2 +- nativescript-angular/view-util.ts | 6 +- 28 files changed, 99 insertions(+), 153 deletions(-) diff --git a/nativescript-angular/animation-driver.ts b/nativescript-angular/animation-driver.ts index afc881db1..fbc1f74f2 100644 --- a/nativescript-angular/animation-driver.ts +++ b/nativescript-angular/animation-driver.ts @@ -16,7 +16,7 @@ export class NativeScriptAnimationDriver implements AnimationDriver { return (element).style._getValue(getPropertyByCssName(prop)); } - animate(element: any, startingStyles: AnimationStyles, keyframes: AnimationKeyframe[], duration: number, delay: number, easing: string): AnimationPlayer { + animate(element: any, _startingStyles: AnimationStyles, keyframes: AnimationKeyframe[], duration: number, delay: number, easing: string): AnimationPlayer { return new NativeScriptAnimationPlayer(element, keyframes, duration, delay, easing); } } diff --git a/nativescript-angular/animation-player.ts b/nativescript-angular/animation-player.ts index b30e0b6ab..bcba52474 100644 --- a/nativescript-angular/animation-player.ts +++ b/nativescript-angular/animation-player.ts @@ -98,7 +98,7 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer { this._onStart(); this.animation.play(this.target) .then(() => { this._onFinish(); }) - .catch((e) => { }); + .catch((_e) => { }); } } @@ -126,7 +126,7 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer { this._onFinish(); } - setPosition(p: any): void { + setPosition(_p: any): void { throw new Error("AnimationPlayer.setPosition method is not supported!"); } diff --git a/nativescript-angular/collection-facade.ts b/nativescript-angular/collection-facade.ts index 03d3b56b0..b573dd639 100644 --- a/nativescript-angular/collection-facade.ts +++ b/nativescript-angular/collection-facade.ts @@ -131,66 +131,3 @@ function _flattenArray(source: any[], target: any[]): any[] { } return target; } - -export class StringMapWrapper { - static create(): {[k: /*any*/ string]: any} { - // Note: We are not using Object.create(null) here due to - // performance! - // http://jsperf.com/ng2-object-create-null - return {}; - } - static contains(map: {[key: string]: any}, key: string): boolean { - return map.hasOwnProperty(key); - } - static get(map: {[key: string]: V}, key: string): V { - return map.hasOwnProperty(key) ? map[key] : undefined; - } - static set(map: {[key: string]: V}, key: string, value: V) { map[key] = value; } - - static keys(map: {[key: string]: any}): string[] { return Object.keys(map); } - static values(map: {[key: string]: T}): T[] { - return Object.keys(map).map((k: string): T => map[k]); - } - static isEmpty(map: {[key: string]: any}): boolean { - for (var prop in map) { - return false; - } - return true; - } - static delete (map: {[key: string]: any}, key: string) { delete map[key]; } - static forEach(map: {[key: string]: V}, callback: (v: V, K: string) => void) { - for (let k of Object.keys(map)) { - callback(map[k], k); - } - } - - static merge(m1: {[key: string]: V}, m2: {[key: string]: V}): {[key: string]: V} { - var m: {[key: string]: V} = {}; - - for (let k of Object.keys(m1)) { - m[k] = m1[k]; - } - - for (let k of Object.keys(m2)) { - m[k] = m2[k]; - } - - return m; - } - - static equals(m1: {[key: string]: V}, m2: {[key: string]: V}): boolean { - var k1 = Object.keys(m1); - var k2 = Object.keys(m2); - if (k1.length != k2.length) { - return false; - } - var key: any /** TODO #???? */; - for (var i = 0; i < k1.length; i++) { - key = k1[i]; - if (m1[key] !== m2[key]) { - return false; - } - } - return true; - } -} diff --git a/nativescript-angular/common/detached-loader.ts b/nativescript-angular/common/detached-loader.ts index 5501d59b0..0f9a3d4b8 100644 --- a/nativescript-angular/common/detached-loader.ts +++ b/nativescript-angular/common/detached-loader.ts @@ -4,12 +4,6 @@ import { } from '@angular/core'; import * as trace from "trace"; -type AnyComponentRef = ComponentRef; -interface PendingLoadEntry { - componentType: Type; - resolveCallback: (AnyComponentRef) => void; -} - export const CATEGORY = "detached-loader"; function log(message: string) { trace.write(message, CATEGORY); diff --git a/nativescript-angular/directives/action-bar.ts b/nativescript-angular/directives/action-bar.ts index 28b7a835c..47ba7d356 100644 --- a/nativescript-angular/directives/action-bar.ts +++ b/nativescript-angular/directives/action-bar.ts @@ -7,7 +7,7 @@ import { registerElement, ViewClassMeta, NgView } from '../element-registry'; var actionBarMeta: ViewClassMeta = { skipAddToDom: true, - insertChild: (parent: NgView, child: NgView, atIndex: number) => { + insertChild: (parent: NgView, child: NgView, _atIndex: number) => { const bar = (parent); const childView = child; diff --git a/nativescript-angular/directives/dialogs.ts b/nativescript-angular/directives/dialogs.ts index 892b0e9be..b54c85534 100644 --- a/nativescript-angular/directives/dialogs.ts +++ b/nativescript-angular/directives/dialogs.ts @@ -39,7 +39,7 @@ export class ModalDialogService { const resolver: ComponentFactoryResolver = viewContainerRef.injector.get(ComponentFactoryResolver); const pageFactory: PageFactory = viewContainerRef.injector.get(PAGE_FACTORY); - return new Promise((resolve, reject) => { + return new Promise((resolve) => { setTimeout(() => ModalDialogService.showDialog(type, options, resolve, viewContainerRef, resolver, parentPage, pageFactory), 10); }); } diff --git a/nativescript-angular/directives/list-view-comp.ts b/nativescript-angular/directives/list-view-comp.ts index de133b17f..47fb8cd0d 100644 --- a/nativescript-angular/directives/list-view-comp.ts +++ b/nativescript-angular/directives/list-view-comp.ts @@ -79,13 +79,13 @@ export class ListViewComponent implements DoCheck, OnDestroy, AfterContentInit { needDiffer = false; } if (needDiffer && !this._differ && isListLikeIterable(value)) { - this._differ = this._iterableDiffers.find(this._items).create(this._cdr, (index, item) => { return item; }); + this._differ = this._iterableDiffers.find(this._items).create(this._cdr, (_index, item) => { return item; }); } this.listView.items = this._items; } - constructor(private _elementRef: ElementRef, + constructor(_elementRef: ElementRef, private _iterableDiffers: IterableDiffers, private _cdr: ChangeDetectorRef) { this.listView = _elementRef.nativeElement; diff --git a/nativescript-angular/directives/tab-view.ts b/nativescript-angular/directives/tab-view.ts index 2f8689841..44a6a1d0c 100644 --- a/nativescript-angular/directives/tab-view.ts +++ b/nativescript-angular/directives/tab-view.ts @@ -1,8 +1,8 @@ -import {ElementRef, Directive, Input, TemplateRef, ViewContainerRef} from "@angular/core"; -import {TabView, TabViewItem} from "ui/tab-view"; +import { ElementRef, Directive, Input, TemplateRef, ViewContainerRef } from "@angular/core"; +import { TabView, TabViewItem } from "ui/tab-view"; import * as utils from '../common/utils'; -import {rendererLog, rendererError} from "../trace"; -import {isBlank} from "../lang-facade"; +import { rendererLog } from "../trace"; +import { isBlank } from "../lang-facade"; @Directive({ selector: 'TabView', @@ -24,7 +24,7 @@ export class TabViewDirective { } } - constructor(private element: ElementRef) { + constructor(element: ElementRef) { this.tabView = element.nativeElement; } diff --git a/nativescript-angular/dom-adapter.ts b/nativescript-angular/dom-adapter.ts index fff7c605a..1c248f8b4 100644 --- a/nativescript-angular/dom-adapter.ts +++ b/nativescript-angular/dom-adapter.ts @@ -1,8 +1,8 @@ import { ElementSchemaRegistry } from '@angular/compiler'; -import { Sanitizer, SchemaMetadata } from '@angular/core'; +import { SchemaMetadata } from '@angular/core'; import { Parse5DomAdapter } from "./parse5_adapter"; import { setRootDomAdapter } from './private_import_platform-browser'; -import { rendererLog, rendererError } from "./trace"; +import { rendererLog } from "./trace"; import { print } from "./lang-facade"; export enum SecurityContext { @@ -15,11 +15,11 @@ export enum SecurityContext { } export class NativeScriptElementSchemaRegistry extends ElementSchemaRegistry { - hasProperty(tagName: string, propName: string): boolean { + hasProperty(_tagName: string, _propName: string): boolean { return true; } - hasElement(tagName: string, schemaMetas: SchemaMetadata[]): boolean { + hasElement(_tagName: string, _schemaMetas: SchemaMetadata[]): boolean { return true; } @@ -32,15 +32,15 @@ export class NativeScriptElementSchemaRegistry extends ElementSchemaRegistry { return 'ng-component'; } - securityContext(tagName: string, propName: string): any { + securityContext(_tagName: string, _propName: string): any { return SecurityContext.NONE; } - validateProperty(name: string): { error: boolean, msg?: string } { + validateProperty(_name: string): { error: boolean, msg?: string } { return { error: false }; } - validateAttribute(name: string): { error: boolean, msg?: string } { + validateAttribute(_name: string): { error: boolean, msg?: string } { return { error: false }; } @@ -52,7 +52,7 @@ export class NativeScriptElementSchemaRegistry extends ElementSchemaRegistry { return propName; } - normalizeAnimationStyleValue(camelCaseProp: string, userProvidedProp: string, val: string | number): + normalizeAnimationStyleValue(_camelCaseProp: string, _userProvidedProp: string, val: string | number): { error: string, value: string } { return { error: null, value: val.toString() }; } @@ -64,7 +64,7 @@ export class NativeScriptDomAdapter extends Parse5DomAdapter { setRootDomAdapter(new NativeScriptDomAdapter()); } - hasProperty(element, name: string) { + hasProperty(_element: any, _name: string) { //TODO: actually check if the property exists. return true; } diff --git a/nativescript-angular/http/ns-http.ts b/nativescript-angular/http/ns-http.ts index ef542a5e9..5c504dcff 100644 --- a/nativescript-angular/http/ns-http.ts +++ b/nativescript-angular/http/ns-http.ts @@ -1,11 +1,11 @@ import {Injectable} from '@angular/core'; -import {Http, XHRBackend, ConnectionBackend, RequestOptions, RequestOptionsArgs, ResponseOptions, ResponseType, Response, XSRFStrategy} from '@angular/http'; +import {Http, ConnectionBackend, RequestOptionsArgs, ResponseOptions, ResponseType, Response} from '@angular/http'; import {Observable} from 'rxjs/Observable'; import 'rxjs/add/observable/fromPromise'; import {NSFileSystem} from '../file-system/ns-file-system'; export class NSXSRFStrategy { - public configureRequest(req: any) { + public configureRequest(_req: any) { // noop } } diff --git a/nativescript-angular/parse5_adapter.ts b/nativescript-angular/parse5_adapter.ts index 07907ab95..3c4782940 100644 --- a/nativescript-angular/parse5_adapter.ts +++ b/nativescript-angular/parse5_adapter.ts @@ -47,7 +47,7 @@ export class Parse5DomAdapter extends DomAdapter { setRootDomAdapter(new Parse5DomAdapter()); } - hasProperty(element: any, name: string): boolean { + hasProperty(_element: any, name: string): boolean { return _HTMLElementPropertyList.indexOf(name) > -1; } // TODO(tbosch): don't even call this method when we run the tests on server side @@ -75,7 +75,7 @@ export class Parse5DomAdapter extends DomAdapter { get attrToPropMap() { return _attrToPropMap; } - query(selector: any) { throw _notImplemented('query'); } + query(_selector: any) { throw _notImplemented('query'); } querySelector(el: any, selector: string): any { return this.querySelectorAll(el, selector)[0]; } querySelectorAll(el: any, selector: string): any[] { const res: any[] = []; @@ -121,7 +121,7 @@ export class Parse5DomAdapter extends DomAdapter { cssSelector.addClassName(classList[i]); } - matcher.match(cssSelector, function(selector: any, cb: any) { result = true; }); + matcher.match(cssSelector, function(_selector: any, _cb: any) { result = true; }); } return result; } @@ -171,7 +171,7 @@ export class Parse5DomAdapter extends DomAdapter { getInnerHTML(el: any): string { return parse5.serialize(this.templateAwareRoot(el), {treeAdapter}); } - getTemplateContent(el: any): Node { return null; } + getTemplateContent(_el: any): Node { return null; } getOuterHTML(el: any): string { const fragment = treeAdapter.createDocumentFragment(); this.appendChild(fragment, el); @@ -179,7 +179,7 @@ export class Parse5DomAdapter extends DomAdapter { } nodeName(node: any): string { return node.tagName; } nodeValue(node: any): string { return node.nodeValue; } - type(node: any): string { throw _notImplemented('type'); } + type(_node: any): string { throw _notImplemented('type'); } content(node: any): string { return node.childNodes[0]; } firstChild(el: any): Node { return el.firstChild; } nextSibling(el: any): Node { return el.nextSibling; } @@ -313,7 +313,7 @@ export class Parse5DomAdapter extends DomAdapter { } getShadowRoot(el: any): Element { return el.shadowRoot; } getHost(el: any): string { return el.host; } - getDistributedNodes(el: any): Node[] { throw _notImplemented('getDistributedNodes'); } + getDistributedNodes(_el: any): Node[] { throw _notImplemented('getDistributedNodes'); } clone(node: Node): Node { const _recursive = (node: any) => { const nodeClone = Object.create(Object.getPrototypeOf(node)); @@ -358,7 +358,7 @@ export class Parse5DomAdapter extends DomAdapter { getElementsByClassName(element: any, name: string): HTMLElement[] { return this.querySelectorAll(element, '.' + name); } - getElementsByTagName(element: any, name: string): HTMLElement[] { + getElementsByTagName(_element: any, _name: string): HTMLElement[] { throw _notImplemented('getElementsByTagName'); } classList(element: any): string[] { @@ -442,13 +442,13 @@ export class Parse5DomAdapter extends DomAdapter { hasAttribute(element: any, attribute: string): boolean { return element.attribs && element.attribs.hasOwnProperty(attribute); } - hasAttributeNS(element: any, ns: string, attribute: string): boolean { throw 'not implemented'; } + hasAttributeNS(_element: any, _ns: string, _attribute: string): boolean { throw 'not implemented'; } getAttribute(element: any, attribute: string): string { return element.attribs && element.attribs.hasOwnProperty(attribute) ? element.attribs[attribute] : null; } - getAttributeNS(element: any, ns: string, attribute: string): string { throw 'not implemented'; } + getAttributeNS(_element: any, _ns: string, _attribute: string): string { throw 'not implemented'; } setAttribute(element: any, attribute: string, value: string) { if (attribute) { element.attribs[attribute] = value; @@ -457,7 +457,7 @@ export class Parse5DomAdapter extends DomAdapter { } } } - setAttributeNS(element: any, ns: string, attribute: string, value: string) { + setAttributeNS(_element: any, _ns: string, _attribute: string, _value: string) { throw 'not implemented'; } removeAttribute(element: any, attribute: string) { @@ -465,7 +465,7 @@ export class Parse5DomAdapter extends DomAdapter { delete element.attribs[attribute]; } } - removeAttributeNS(element: any, ns: string, name: string) { throw 'not implemented'; } + removeAttributeNS(_element: any, _ns: string, _name: string) { throw 'not implemented'; } templateAwareRoot(el: any): any { return this.isTemplateElement(el) ? treeAdapter.getTemplateContent(el) : el; } @@ -482,7 +482,7 @@ export class Parse5DomAdapter extends DomAdapter { return newDoc; } defaultDoc(): Document { return defDoc = defDoc || this.createHtmlDocument(); } - getBoundingClientRect(el: any): any { return {left: 0, top: 0, width: 0, height: 0}; } + getBoundingClientRect(_el: any): any { return {left: 0, top: 0, width: 0, height: 0}; } getTitle(): string { return this.defaultDoc().title || ''; } setTitle(newTitle: string) { this.defaultDoc().title = newTitle; } isTemplateElement(el: any): boolean { @@ -556,7 +556,7 @@ export class Parse5DomAdapter extends DomAdapter { getLocation(): Location { throw 'not implemented'; } getUserAgent(): string { return 'Fake user agent'; } getData(el: any, name: string): string { return this.getAttribute(el, 'data-' + name); } - getComputedStyle(el: any): any { throw 'not implemented'; } + getComputedStyle(_el: any): any { throw 'not implemented'; } setData(el: any, name: string, value: string) { this.setAttribute(el, 'data-' + name, value); } // TODO(tbosch): move this into a separate environment class once we have it setGlobalVar(path: string, value: any) { setValueOnPath(global, path, value); } @@ -566,15 +566,15 @@ export class Parse5DomAdapter extends DomAdapter { getTransitionEnd(): string { return 'transitionend'; } supportsAnimation(): boolean { return true; } - replaceChild(el: any, newNode: any, oldNode: any) { throw new Error('not implemented'); } - parse(templateHtml: string) { throw new Error('not implemented'); } - invoke(el: Element, methodName: string, args: any[]): any { throw new Error('not implemented'); } - getEventKey(event: any): string { throw new Error('not implemented'); } + replaceChild(_el: any, _newNode: any, _oldNode: any) { throw new Error('not implemented'); } + parse(_templateHtml: string) { throw new Error('not implemented'); } + invoke(_el: Element, _methodName: string, _args: any[]): any { throw new Error('not implemented'); } + getEventKey(_event: any): string { throw new Error('not implemented'); } supportsCookies(): boolean { return false; } - getCookie(name: string): string { throw new Error('not implemented'); } - setCookie(name: string, value: string) { throw new Error('not implemented'); } - animate(element: any, keyframes: any[], options: any): any { throw new Error('not implemented'); } + getCookie(_name: string): string { throw new Error('not implemented'); } + setCookie(_name: string, _value: string) { throw new Error('not implemented'); } + animate(_element: any, _keyframes: any[], _options: any): any { throw new Error('not implemented'); } } // TODO: build a proper list, this one is all the keys of a HTMLInputElement diff --git a/nativescript-angular/platform-common.ts b/nativescript-angular/platform-common.ts index 5b01c149e..4598083a7 100644 --- a/nativescript-angular/platform-common.ts +++ b/nativescript-angular/platform-common.ts @@ -18,6 +18,13 @@ import { OpaqueToken, } from '@angular/core'; +//Work around a TS bug requiring an import of OpaqueToken without using it +if (global.___TS_UNUSED) { + () => { + return OpaqueToken; + } +} + import { rendererLog, rendererError } from "./trace"; import { PAGE_FACTORY, PageFactory, defaultPageFactoryProvider } from './platform-providers'; @@ -34,11 +41,6 @@ export const onAfterLivesync = new EventEmitter>(); let lastBootstrappedModule: WeakRef>; type BootstrapperAction = () => Promise>; -interface BootstrapParams { - appModuleType: Type; - appOptions?: AppOptions; -} - export interface AppOptions { bootInExistingPage: boolean; cssFile?: string; @@ -48,7 +50,7 @@ export interface AppOptions { export type PlatformFactory = (extraProviders?: Provider[]) => PlatformRef; export class NativeScriptSanitizer extends Sanitizer { - sanitize(context: any, value: string): string { + sanitize(_context: any, value: string): string { return value; } } @@ -144,7 +146,7 @@ export class NativeScriptPlatformRef extends PlatformRef { page.actionBarHidden = this.appOptions.startPageActionBarHidden; } - let onLoadedHandler = function (args) { + let onLoadedHandler = function () { page.off('loaded', onLoadedHandler); //profiling.stop('application-start'); rendererLog('Page loaded'); diff --git a/nativescript-angular/platform-providers.ts b/nativescript-angular/platform-providers.ts index 4635de4df..98fbb374c 100644 --- a/nativescript-angular/platform-providers.ts +++ b/nativescript-angular/platform-providers.ts @@ -1,12 +1,20 @@ import { topmost, Frame } from 'ui/frame'; import { Page } from 'ui/page'; -import { OpaqueToken, Type } from '@angular/core'; -import { device, Device } from "platform"; +import { OpaqueToken } from '@angular/core'; +import { device } from "platform"; +import * as platform from "platform"; export const APP_ROOT_VIEW = new OpaqueToken('App Root View'); export const DEVICE = new OpaqueToken('platfrom device'); export const PAGE_FACTORY = new OpaqueToken('page factory'); +//Work around a TS bug requiring an import of platform.Device without using it +if (global.___TS_UNUSED) { + () => { + return platform; + } +} + export function getDefaultPage(): Page { const frame = topmost(); if (frame) { @@ -29,7 +37,7 @@ export interface PageFactoryOptions { isNavigation?: boolean, componentType?: any } -export const defaultPageFactory: PageFactory = function (opts: PageFactoryOptions) { +export const defaultPageFactory: PageFactory = function (_opts: PageFactoryOptions) { return new Page(); } export const defaultPageFactoryProvider = { provide: PAGE_FACTORY, useValue: defaultPageFactory }; diff --git a/nativescript-angular/platform.ts b/nativescript-angular/platform.ts index 25fb55b5c..60d3fbdc5 100644 --- a/nativescript-angular/platform.ts +++ b/nativescript-angular/platform.ts @@ -10,12 +10,18 @@ import { import { COMPILER_OPTIONS, - Sanitizer, PlatformRef, OpaqueToken, createPlatformFactory } from '@angular/core'; +//Work around a TS bug requiring an import of OpaqueToken without using it +if (global.___TS_UNUSED) { + () => { + return OpaqueToken; + } +} + import { NativeScriptElementSchemaRegistry } from './dom-adapter'; import { FileSystemResourceLoader } from './resource-loader'; @@ -46,4 +52,4 @@ export function platformNativeScriptDynamic(options?: AppOptions, extraProviders } else { return new NativeScriptPlatformRef(_platformNativeScriptDynamic(extraProviders), options); } -} \ No newline at end of file +} diff --git a/nativescript-angular/renderer.ts b/nativescript-angular/renderer.ts index 18147ebd0..728edf378 100644 --- a/nativescript-angular/renderer.ts +++ b/nativescript-angular/renderer.ts @@ -88,7 +88,7 @@ export class NativeScriptRenderer extends Renderer { constructor( private rootRenderer: NativeScriptRootRenderer, - private componentProto: RenderComponentType, + componentProto: RenderComponentType, private animationDriver: nsAnimationDriver.NativeScriptAnimationDriver, private zone: NgZone) { @@ -154,7 +154,7 @@ export class NativeScriptRenderer extends Renderer { } } - public destroyView(hostElement: NgView, viewAllNodes: NgView[]) { + public destroyView(_hostElement: NgView, _viewAllNodes: NgView[]) { traceLog("NativeScriptRenderer.destroyView"); // Seems to be called on component dispose only (router outlet) //TODO: handle this when we resolve routing and navigation. @@ -192,18 +192,18 @@ export class NativeScriptRenderer extends Renderer { traceLog('NativeScriptRenderer.setBindingDebugInfo: ' + renderElement + ', ' + propertyName + ' = ' + propertyValue); } - setElementDebugInfo(renderElement: any, info: any /*RenderDebugInfo*/): void { + setElementDebugInfo(renderElement: any, _info: any /*RenderDebugInfo*/): void { traceLog('NativeScriptRenderer.setElementDebugInfo: ' + renderElement); } /** * Calls a method on an element. */ - invokeElementMethod(renderElement: NgView, methodName: string, args: Array) { + invokeElementMethod(_renderElement: NgView, methodName: string, args: Array) { traceLog("NativeScriptRenderer.invokeElementMethod " + methodName + " " + args); } - setText(renderNode: any, text: string) { + setText(_renderNode: any, _text: string) { traceLog("NativeScriptRenderer.setText"); } @@ -224,9 +224,9 @@ export class NativeScriptRenderer extends Renderer { }); } - public createText(parentElement: NgView, value: string): NgView { + public createText(_parentElement: NgView, _value: string): NgView { traceLog('NativeScriptRenderer.createText'); - return this.viewUtil.createText(value); + return this.viewUtil.createText(); } public listen(renderElement: NgView, eventName: string, callback: Function): Function { @@ -246,7 +246,7 @@ export class NativeScriptRenderer extends Renderer { return () => renderElement.off(eventName, zonedCallback); } - public listenGlobal(target: string, eventName: string, callback: Function): Function { + public listenGlobal(_target: string, _eventName: string, _callback: Function): Function { throw new Error('NativeScriptRenderer.listenGlobal() - Not implemented.'); } diff --git a/nativescript-angular/router/ns-platform-location.ts b/nativescript-angular/router/ns-platform-location.ts index 777f0bc73..297396988 100644 --- a/nativescript-angular/router/ns-platform-location.ts +++ b/nativescript-angular/router/ns-platform-location.ts @@ -20,7 +20,7 @@ export class NativescriptPlatformLocation extends PlatformLocation { this.locationStartegy.onPopState(fn); } - onHashChange(fn: LocationChangeListener): void { + onHashChange(_fn: LocationChangeListener): void { } get search(): string { @@ -32,7 +32,7 @@ export class NativescriptPlatformLocation extends PlatformLocation { get pathname(): string { return this.locationStartegy.path(); } - set pathname(newPath: string) { + set pathname(_newPath: string) { throw new Error("NativescriptPlatformLocation set pathname - not implemented") } diff --git a/nativescript-angular/router/ns-router-link-active.ts b/nativescript-angular/router/ns-router-link-active.ts index 94af17ce5..926b129e4 100644 --- a/nativescript-angular/router/ns-router-link-active.ts +++ b/nativescript-angular/router/ns-router-link-active.ts @@ -67,7 +67,7 @@ export class NSRouterLinkActive implements OnChanges, OnDestroy, AfterContentIni } ngAfterContentInit(): void { - this.links.changes.subscribe(s => this.update()); + this.links.changes.subscribe(() => this.update()); this.update(); } @@ -80,7 +80,7 @@ export class NSRouterLinkActive implements OnChanges, OnDestroy, AfterContentIni } } - ngOnChanges(changes: {}): any { this.update(); } + ngOnChanges(_: {}): any { this.update(); } ngOnDestroy(): any { this.subscription.unsubscribe(); } private update(): void { diff --git a/nativescript-angular/router/ns-router-link.ts b/nativescript-angular/router/ns-router-link.ts index b8322465a..161e71d18 100644 --- a/nativescript-angular/router/ns-router-link.ts +++ b/nativescript-angular/router/ns-router-link.ts @@ -105,7 +105,7 @@ export class NSRouterLink implements OnChanges { } } - ngOnChanges(changes: {}): any { + ngOnChanges(_: {}): any { this.updateUrlTree(); } diff --git a/nativescript-angular/router/page-router-outlet.ts b/nativescript-angular/router/page-router-outlet.ts index a99075d44..bfbdeaf56 100644 --- a/nativescript-angular/router/page-router-outlet.ts +++ b/nativescript-angular/router/page-router-outlet.ts @@ -152,7 +152,7 @@ export class PageRouterOutlet { this.currentActivatedRoute = activatedRoute; if (this.locationStrategy._isPageNavigatingBack()) { - this.activateOnGoBack(activatedRoute, providers, outletMap); + this.activateOnGoBack(activatedRoute, outletMap); } else { this.activateOnGoForward(activatedRoute, providers, outletMap, resolver, injector); } @@ -194,7 +194,6 @@ export class PageRouterOutlet { private activateOnGoBack( activatedRoute: ActivatedRoute, - providers: ResolvedReflectiveProvider[], outletMap: RouterOutletMap): void { log("PageRouterOutlet.activate() - Back navigation, so load from cache"); diff --git a/nativescript-angular/tsconfig.json b/nativescript-angular/tsconfig.json index 1041e1a0e..0515ad379 100644 --- a/nativescript-angular/tsconfig.json +++ b/nativescript-angular/tsconfig.json @@ -10,6 +10,8 @@ "declaration": true, "removeComments": false, "noEmitOnError": true, + "noUnusedLocals": true, + "noUnusedParameters": true, "noImplicitAny": false }, "angularCompilerOptions": { @@ -18,4 +20,4 @@ "skipTemplateCodegen": true, "debug": true } -} \ No newline at end of file +} diff --git a/nativescript-angular/value-accessors/base-value-accessor.ts b/nativescript-angular/value-accessors/base-value-accessor.ts index a0ccea8da..6e5b63e78 100644 --- a/nativescript-angular/value-accessors/base-value-accessor.ts +++ b/nativescript-angular/value-accessors/base-value-accessor.ts @@ -1,4 +1,3 @@ -import {View} from "ui/core/view"; import {ControlValueAccessor} from "@angular/forms"; export class BaseValueAccessor implements ControlValueAccessor { @@ -19,11 +18,11 @@ export class BaseValueAccessor implements ControlValueAccessor { } } - writeValue(value: any) { + writeValue(_: any) { // } - registerOnTouched(fn: () => void): void { + registerOnTouched(_: () => void): void { // } } diff --git a/nativescript-angular/value-accessors/checked-value-accessor.ts b/nativescript-angular/value-accessors/checked-value-accessor.ts index b93fc9cc2..3b434d7f8 100644 --- a/nativescript-angular/value-accessors/checked-value-accessor.ts +++ b/nativescript-angular/value-accessors/checked-value-accessor.ts @@ -1,4 +1,4 @@ -import {Directive, ElementRef, Renderer, Self, forwardRef } from '@angular/core'; +import {Directive, ElementRef, forwardRef } from '@angular/core'; import {NG_VALUE_ACCESSOR} from "@angular/forms"; import {isBlank} from "../lang-facade"; import {BaseValueAccessor} from './base-value-accessor'; diff --git a/nativescript-angular/value-accessors/date-value-accessor.ts b/nativescript-angular/value-accessors/date-value-accessor.ts index f052db7fc..c94094dc7 100644 --- a/nativescript-angular/value-accessors/date-value-accessor.ts +++ b/nativescript-angular/value-accessors/date-value-accessor.ts @@ -1,4 +1,4 @@ -import {Directive, ElementRef, Renderer, Self, forwardRef } from '@angular/core'; +import {Directive, ElementRef, forwardRef } from '@angular/core'; import {NG_VALUE_ACCESSOR} from '@angular/forms'; import {isBlank, isDate} from "../lang-facade"; import {BaseValueAccessor} from './base-value-accessor'; diff --git a/nativescript-angular/value-accessors/number-value-accessor.ts b/nativescript-angular/value-accessors/number-value-accessor.ts index 6b067d520..76e59fbbb 100644 --- a/nativescript-angular/value-accessors/number-value-accessor.ts +++ b/nativescript-angular/value-accessors/number-value-accessor.ts @@ -1,4 +1,4 @@ -import {Directive, ElementRef, Renderer, Self, forwardRef } from '@angular/core'; +import {Directive, ElementRef, forwardRef } from '@angular/core'; import {NG_VALUE_ACCESSOR} from "@angular/forms"; import {isBlank, isNumber} from "../lang-facade"; import {BaseValueAccessor} from './base-value-accessor'; diff --git a/nativescript-angular/value-accessors/selectedIndex-value-accessor.ts b/nativescript-angular/value-accessors/selectedIndex-value-accessor.ts index ecca988e0..40d99445b 100644 --- a/nativescript-angular/value-accessors/selectedIndex-value-accessor.ts +++ b/nativescript-angular/value-accessors/selectedIndex-value-accessor.ts @@ -1,6 +1,5 @@ -import {Directive, ElementRef, Renderer, Self, forwardRef } from '@angular/core'; +import {Directive, ElementRef, forwardRef } from '@angular/core'; import {NG_VALUE_ACCESSOR} from "@angular/forms"; -import {isBlank, isNumber} from "../lang-facade"; import {BaseValueAccessor} from './base-value-accessor'; import {View} from "ui/core/view"; import * as utils from '../common/utils'; diff --git a/nativescript-angular/value-accessors/text-value-accessor.ts b/nativescript-angular/value-accessors/text-value-accessor.ts index d141652c6..dc99a9cde 100644 --- a/nativescript-angular/value-accessors/text-value-accessor.ts +++ b/nativescript-angular/value-accessors/text-value-accessor.ts @@ -1,4 +1,4 @@ -import {Directive, ElementRef, Renderer, Self, forwardRef } from '@angular/core'; +import {Directive, ElementRef, forwardRef } from '@angular/core'; import {NG_VALUE_ACCESSOR} from "@angular/forms"; import {isBlank} from "../lang-facade"; import {BaseValueAccessor} from './base-value-accessor' diff --git a/nativescript-angular/value-accessors/time-value-accessor.ts b/nativescript-angular/value-accessors/time-value-accessor.ts index 36d081c1b..d1242a690 100644 --- a/nativescript-angular/value-accessors/time-value-accessor.ts +++ b/nativescript-angular/value-accessors/time-value-accessor.ts @@ -1,4 +1,4 @@ -import {Directive, ElementRef, Renderer, Self, forwardRef } from '@angular/core'; +import {Directive, ElementRef, forwardRef } from '@angular/core'; import {NG_VALUE_ACCESSOR} from '@angular/forms'; import {isBlank, isDate} from "../lang-facade"; import {BaseValueAccessor} from './base-value-accessor'; diff --git a/nativescript-angular/view-util.ts b/nativescript-angular/view-util.ts index e604d81d8..45b0cda85 100644 --- a/nativescript-angular/view-util.ts +++ b/nativescript-angular/view-util.ts @@ -119,11 +119,11 @@ export class ViewUtil { const viewClass = getViewClass(name); return this.createAndAttach(name, viewClass, parent, beforeAttach); } else { - return this.createViewContainer(name, parent, beforeAttach); + return this.createViewContainer(parent, beforeAttach); } } - public createText(value: string): NgView { + public createText(): NgView { const text = new Placeholder(); text.nodeName = "#text"; text.visibility = "collapse"; @@ -131,7 +131,7 @@ export class ViewUtil { return text; } - public createViewContainer(name: string, parentElement: NgView, beforeAttach: BeforeAttachAction) { + public createViewContainer(parentElement: NgView, beforeAttach: BeforeAttachAction) { traceLog('Creating view container in:' + parentElement); const layout = this.createView('ProxyViewContainer', parentElement, beforeAttach); From a19fdc1a33867f81787d6f3b3dacb6f213400f26 Mon Sep 17 00:00:00 2001 From: Hristo Deshev Date: Tue, 22 Nov 2016 15:12:13 +0200 Subject: [PATCH 2/2] Enable tslint and fix complaints. --- .travis.yml | 1 + nativescript-angular/.npmignore | 3 +- nativescript-angular/animation-driver.ts | 13 +- nativescript-angular/animation-player.ts | 82 ++++++++---- nativescript-angular/collection-facade.ts | 33 ++--- .../common/detached-loader.ts | 23 ++-- nativescript-angular/common/utils.ts | 2 +- nativescript-angular/directives.ts | 42 ++++--- nativescript-angular/directives/action-bar.ts | 13 +- nativescript-angular/directives/dialogs.ts | 34 +++-- .../directives/list-view-comp.ts | 51 ++++---- .../directives/platform-filters.ts | 2 +- nativescript-angular/directives/tab-view.ts | 22 ++-- nativescript-angular/dom-adapter.ts | 16 ++- nativescript-angular/element-registry.ts | 20 +-- .../file-system/ns-file-system.ts | 6 +- nativescript-angular/forms.ts | 12 +- nativescript-angular/http.ts | 7 +- nativescript-angular/http/ns-http.ts | 25 ++-- nativescript-angular/index.ts | 2 +- nativescript-angular/lang-facade.ts | 15 +-- nativescript-angular/nativescript.module.ts | 18 +-- nativescript-angular/package.json | 10 +- nativescript-angular/parse5_adapter.ts | 7 +- nativescript-angular/platform-common.ts | 51 ++++---- nativescript-angular/platform-providers.ts | 30 ++--- nativescript-angular/platform-static.ts | 13 +- nativescript-angular/platform.ts | 30 +++-- nativescript-angular/polyfills/array.ts | 40 +++--- nativescript-angular/polyfills/console.ts | 2 +- nativescript-angular/private_import_core.ts | 30 ++--- .../private_import_platform-browser.ts | 8 +- nativescript-angular/renderer.ts | 76 ++++++----- nativescript-angular/resource-loader.ts | 4 +- nativescript-angular/router-url-tree.ts | 59 ++++++--- nativescript-angular/router.ts | 20 +-- .../router/ns-location-strategy.ts | 35 +++--- .../router/ns-platform-location.ts | 8 +- .../router/ns-router-link-active.ts | 45 ++++--- nativescript-angular/router/ns-router-link.ts | 21 ++-- .../router/page-router-outlet.ts | 54 ++++---- .../router/router-extensions.ts | 6 +- nativescript-angular/tslint.json | 118 ++++++++++++++++++ .../value-accessors/base-value-accessor.ts | 8 +- .../value-accessors/checked-value-accessor.ts | 17 +-- .../value-accessors/date-value-accessor.ts | 21 ++-- .../value-accessors/number-value-accessor.ts | 13 +- .../selectedIndex-value-accessor.ts | 20 +-- .../value-accessors/text-value-accessor.ts | 16 +-- .../value-accessors/time-value-accessor.ts | 21 ++-- nativescript-angular/view-util.ts | 50 +++++--- 51 files changed, 790 insertions(+), 485 deletions(-) create mode 100644 nativescript-angular/tslint.json diff --git a/.travis.yml b/.travis.yml index 5aa4b1735..3163a2b44 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,6 +35,7 @@ install: - tns error-reporting disable - cd nativescript-angular - npm install +- npm run tslint - cd ../tests - npm install - tns platform add android diff --git a/nativescript-angular/.npmignore b/nativescript-angular/.npmignore index 7375cfceb..3eb3853e2 100644 --- a/nativescript-angular/.npmignore +++ b/nativescript-angular/.npmignore @@ -8,4 +8,5 @@ tsconfig.json global.d.ts .npmignore -gulpfile.js \ No newline at end of file +gulpfile.js +tslint.json diff --git a/nativescript-angular/animation-driver.ts b/nativescript-angular/animation-driver.ts index fbc1f74f2..c381e0bae 100644 --- a/nativescript-angular/animation-driver.ts +++ b/nativescript-angular/animation-driver.ts @@ -1,8 +1,8 @@ import { AnimationPlayer } from "@angular/core"; import { AnimationStyles, AnimationKeyframe } from "./private_import_core"; -import { NativeScriptAnimationPlayer } from './animation-player'; +import { NativeScriptAnimationPlayer } from "./animation-player"; import { View } from "ui/core/view"; -import { getPropertyByCssName } from 'ui/styling/style-property'; +import { getPropertyByCssName } from "ui/styling/style-property"; export abstract class AnimationDriver { abstract animate( @@ -16,7 +16,14 @@ export class NativeScriptAnimationDriver implements AnimationDriver { return (element).style._getValue(getPropertyByCssName(prop)); } - animate(element: any, _startingStyles: AnimationStyles, keyframes: AnimationKeyframe[], duration: number, delay: number, easing: string): AnimationPlayer { + animate( + element: any, + _startingStyles: AnimationStyles, + keyframes: AnimationKeyframe[], + duration: number, + delay: number, + easing: string + ): AnimationPlayer { return new NativeScriptAnimationPlayer(element, keyframes, duration, delay, easing); } } diff --git a/nativescript-angular/animation-player.ts b/nativescript-angular/animation-player.ts index bcba52474..5fec24bb0 100644 --- a/nativescript-angular/animation-player.ts +++ b/nativescript-angular/animation-player.ts @@ -1,11 +1,16 @@ import { AnimationPlayer } from "@angular/core"; import { AnimationKeyframe } from "./private_import_core"; -import { KeyframeAnimation, KeyframeAnimationInfo, KeyframeInfo, KeyframeDeclaration } from 'ui/animation/keyframe-animation'; +import { + KeyframeAnimation, + KeyframeAnimationInfo, + KeyframeInfo, + KeyframeDeclaration +} from "ui/animation/keyframe-animation"; import { View } from "ui/core/view"; import { AnimationCurve } from "ui/enums"; -import { ValueSource } from 'ui/core/dependency-observable'; +import { ValueSource } from "ui/core/dependency-observable"; import { isString } from "utils/types"; -import * as styleProperty from 'ui/styling/style-property'; +import * as styleProperty from "ui/styling/style-property"; export class NativeScriptAnimationPlayer implements AnimationPlayer { @@ -18,7 +23,13 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer { private animation: KeyframeAnimation; private target: View; - constructor(element: Node, keyframes: AnimationKeyframe[], duration: number, delay: number, easing: string) { + constructor( + element: Node, + keyframes: AnimationKeyframe[], + duration: number, + delay: number, + easing: string + ) { this.parentPlayer = null; @@ -36,7 +47,9 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer { keyframeAnimationInfo.duration = duration; keyframeAnimationInfo.delay = delay; keyframeAnimationInfo.iterations = 1; - keyframeAnimationInfo.curve = easing ? NativeScriptAnimationPlayer.animationTimingFunctionConverter(easing) : AnimationCurve.ease; + keyframeAnimationInfo.curve = easing ? + NativeScriptAnimationPlayer.animationTimingFunctionConverter(easing) : + AnimationCurve.ease; keyframeAnimationInfo.keyframes = new Array(); keyframeAnimationInfo.isForwards = true; @@ -53,8 +66,7 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer { value = property.valueConverter(value); } keyframeInfo.declarations.push({ property: property.name, value: value }); - } - else if (typeof value === "string" && substyle === "transform") { + } else if (typeof value === "string" && substyle === "transform") { NativeScriptAnimationPlayer.parseTransform(value, keyframeInfo); } } @@ -62,7 +74,8 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer { keyframeAnimationInfo.keyframes.push(keyframeInfo); } - this.animation = KeyframeAnimation.keyframeAnimationFromInfo(keyframeAnimationInfo, ValueSource.VisualState); + this.animation = KeyframeAnimation.keyframeAnimationFromInfo( + keyframeAnimationInfo, ValueSource.VisualState); } init(): void { @@ -159,8 +172,7 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer { NativeScriptAnimationPlayer.bezieArgumentConverter(bezierArr[1]), NativeScriptAnimationPlayer.bezieArgumentConverter(bezierArr[2]), NativeScriptAnimationPlayer.bezieArgumentConverter(bezierArr[3])); - } - else { + } else { throw new Error("Invalid value for animation: " + value); } } @@ -178,16 +190,14 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer { let operations = {}; operations[value] = value; return operations; - } - else if (isString(value)) { + } else if (isString(value)) { let operations = {}; let operator = ""; let pos = 0; while (pos < value.length) { if (value[pos] === " " || value[pos] === ",") { pos++; - } - else if (value[pos] === "(") { + } else if (value[pos] === "(") { let start = pos + 1; while (pos < value.length && value[pos] !== ")") { pos++; @@ -196,14 +206,12 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer { operations[operator] = operand.trim(); operator = ""; pos++; - } - else { + } else { operator += value[pos++]; } } return operations; - } - else { + } else { return undefined; } } @@ -215,29 +223,50 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer { for (let transform in newTransform) { switch (transform) { case "scaleX": - animationInfo.declarations.push({ property: "scale", value: { x: parseFloat(newTransform[transform]), y: 1 } }); + animationInfo.declarations.push({ + property: "scale", + value: { x: parseFloat(newTransform[transform]), y: 1 } + }); break; case "scaleY": - animationInfo.declarations.push({ property: "scale", value: { x: 1, y: parseFloat(newTransform[transform]) } }); + animationInfo.declarations.push({ + property: "scale", + value: { x: 1, y: parseFloat(newTransform[transform]) } + }); break; case "scale": case "scale3d": values = newTransform[transform].split(","); if (values.length === 2 || values.length === 3) { - animationInfo.declarations.push({ property: "scale", value: { x: parseFloat(values[0]), y: parseFloat(values[1]) } }); + animationInfo.declarations.push({ + property: "scale", + value: { x: parseFloat(values[0]), y: parseFloat(values[1]) } + }); } break; case "translateX": - animationInfo.declarations.push({ property: "translate", value: { x: parseFloat(newTransform[transform]), y: 0 } }); + animationInfo.declarations.push({ + property: "translate", + value: { x: parseFloat(newTransform[transform]), y: 0 } + }); break; case "translateY": - animationInfo.declarations.push({ property: "translate", value: { x: 0, y: parseFloat(newTransform[transform]) } }); + animationInfo.declarations.push({ + property: "translate", + value: { x: 0, y: parseFloat(newTransform[transform]) } + }); break; case "translate": case "translate3d": values = newTransform[transform].split(","); if (values.length === 2 || values.length === 3) { - animationInfo.declarations.push({ property: "translate", value: { x: parseFloat(values[0]), y: parseFloat(values[1]) } }); + animationInfo.declarations.push({ + property: "translate", + value: { + x: parseFloat(values[0]), + y: parseFloat(values[1]) + } + }); } break; case "rotate": @@ -250,9 +279,12 @@ export class NativeScriptAnimationPlayer implements AnimationPlayer { break; case "none": animationInfo.declarations.push({ property: "scale", value: { x: 1, y: 1 } }); - animationInfo.declarations.push({ property: "translate", value: { x: 0, y: 0 } }); + animationInfo.declarations.push( + { property: "translate", value: { x: 0, y: 0 } }); animationInfo.declarations.push({ property: "rotate", value: 0 }); break; + default: + throw new Error("Unsupported transform: " + transform); } } return array; diff --git a/nativescript-angular/collection-facade.ts b/nativescript-angular/collection-facade.ts index b573dd639..08c2f6742 100644 --- a/nativescript-angular/collection-facade.ts +++ b/nativescript-angular/collection-facade.ts @@ -1,3 +1,4 @@ +/* tslint:disable */ //Copied unexported functions from @angular/core/src/facade/collection import { isJsObject, isArray, getSymbolIterator, @@ -18,7 +19,7 @@ export class ListWrapper { static createGrowableSize(size: number): any[] { return new Array(size); } static clone(array: T[]): T[] { return array.slice(0); } static forEachWithIndex(array: T[], fn: (t: T, n: number) => void) { - for (var i = 0; i < array.length; i++) { + for (let i = 0; i < array.length; i++) { fn(array[i], i); } } @@ -35,24 +36,24 @@ export class ListWrapper { } static contains(list: T[], el: T): boolean { return list.indexOf(el) !== -1; } static reversed(array: T[]): T[] { - var a = ListWrapper.clone(array); + let a = ListWrapper.clone(array); return a.reverse(); } static concat(a: any[], b: any[]): any[] { return a.concat(b); } static insert(list: T[], index: number, value: T) { list.splice(index, 0, value); } static removeAt(list: T[], index: number): T { - var res = list[index]; + let res = list[index]; list.splice(index, 1); return res; } static removeAll(list: T[], items: T[]) { - for (var i = 0; i < items.length; ++i) { - var index = list.indexOf(items[i]); + for (let i = 0; i < items.length; ++i) { + let index = list.indexOf(items[i]); list.splice(index, 1); } } static remove(list: T[], el: T): boolean { - var index = list.indexOf(el); + let index = list.indexOf(el); if (index > -1) { list.splice(index, 1); return true; @@ -66,7 +67,7 @@ export class ListWrapper { } static equals(a: any[], b: any[]): boolean { if (a.length != b.length) return false; - for (var i = 0; i < a.length; ++i) { + for (let i = 0; i < a.length; ++i) { if (a[i] !== b[i]) return false; } return true; @@ -89,14 +90,14 @@ export class ListWrapper { if (list.length == 0) { return null; } - var solution: any /** TODO #???? */ = null; - var maxValue = -Infinity; - for (var index = 0; index < list.length; index++) { - var candidate = list[index]; + let solution: any /** TODO #???? */ = null; + let maxValue = -Infinity; + for (let index = 0; index < list.length; index++) { + let candidate = list[index]; if (isBlank(candidate)) { continue; } - var candidateValue = predicate(candidate); + let candidateValue = predicate(candidate); if (candidateValue > maxValue) { solution = candidate; maxValue = candidateValue; @@ -106,13 +107,13 @@ export class ListWrapper { } static flatten(list: Array): T[] { - var target: any[] = []; + let target: any[] = []; _flattenArray(list, target); return target; } static addAll(list: Array, source: Array): void { - for (var i = 0; i < source.length; i++) { + for (let i = 0; i < source.length; i++) { list.push(source[i]); } } @@ -120,8 +121,8 @@ export class ListWrapper { function _flattenArray(source: any[], target: any[]): any[] { if (isPresent(source)) { - for (var i = 0; i < source.length; i++) { - var item = source[i]; + for (let i = 0; i < source.length; i++) { + let item = source[i]; if (isArray(item)) { _flattenArray(item, target); } else { diff --git a/nativescript-angular/common/detached-loader.ts b/nativescript-angular/common/detached-loader.ts index 0f9a3d4b8..927a3ca38 100644 --- a/nativescript-angular/common/detached-loader.ts +++ b/nativescript-angular/common/detached-loader.ts @@ -1,7 +1,7 @@ import { ComponentRef, ComponentFactory, ViewContainerRef, Component, Type, ComponentFactoryResolver, ChangeDetectorRef -} from '@angular/core'; +} from "@angular/core"; import * as trace from "trace"; export const CATEGORY = "detached-loader"; @@ -12,36 +12,43 @@ function log(message: string) { /** * Wrapper component used for loading components when navigating - * It uses DetachedContainer as selector so that it is containerRef is not attached to the visual tree. + * It uses DetachedContainer as selector so that it is containerRef is not attached to + * the visual tree. */ @Component({ - selector: 'DetachedContainer', + selector: "DetachedContainer", template: `` }) export class DetachedLoader { - constructor(private resolver: ComponentFactoryResolver, private changeDetector: ChangeDetectorRef, private containerRef: ViewContainerRef) { } + constructor( + private resolver: ComponentFactoryResolver, + private changeDetector: ChangeDetectorRef, + private containerRef: ViewContainerRef + ) { } private loadInLocation(componentType: Type): Promise> { - const factory = this.resolver.resolveComponentFactory(componentType) + const factory = this.resolver.resolveComponentFactory(componentType); const componentRef = this.containerRef.createComponent( factory, this.containerRef.length, this.containerRef.parentInjector); // Component is created, buit may not be checked if we are loading // inside component with OnPush CD strategy. Mark us for check to be sure CD will reach us. - // We are inside a promise here so no need for setTimeout - CD should trigger after the promise. + // We are inside a promise here so no need for setTimeout - CD should trigger + // after the promise. log("DetachedLoader.loadInLocation component loaded -> markForCheck"); this.changeDetector.markForCheck(); return Promise.resolve(componentRef); } - //TODO: change this API -- async promises not needed here anymore. + // TODO: change this API -- async promises not needed here anymore. public loadComponent(componentType: Type): Promise> { log("DetachedLoader.loadComponent"); return this.loadInLocation(componentType); } public loadWithFactory(factory: ComponentFactory): ComponentRef { - return this.containerRef.createComponent(factory, this.containerRef.length, this.containerRef.parentInjector, null); + return this.containerRef.createComponent(factory, + this.containerRef.length, this.containerRef.parentInjector, null); } } diff --git a/nativescript-angular/common/utils.ts b/nativescript-angular/common/utils.ts index 82d05ec9e..d357145a5 100644 --- a/nativescript-angular/common/utils.ts +++ b/nativescript-angular/common/utils.ts @@ -8,7 +8,7 @@ export function convertToInt(value): number { if (isNumber(value)) { normalizedValue = value; } else { - let parsedValue = parseInt(value.toString()); + let parsedValue = parseInt(value.toString(), 10); normalizedValue = isNaN(parsedValue) ? 0 : parsedValue; } } diff --git a/nativescript-angular/directives.ts b/nativescript-angular/directives.ts index 9c13a56ae..2e07c59d5 100644 --- a/nativescript-angular/directives.ts +++ b/nativescript-angular/directives.ts @@ -1,7 +1,12 @@ -import { ListViewComponent, TemplateKeyDirective } from './directives/list-view-comp'; -import { TabViewDirective, TabViewItemDirective } from './directives/tab-view'; -import { ActionBarComponent, ActionBarScope, ActionItemDirective, NavigationButtonDirective } from './directives/action-bar'; -import { AndroidFilterComponent, IosFilterComponent } from './directives/platform-filters'; +import { ListViewComponent, TemplateKeyDirective } from "./directives/list-view-comp"; +import { TabViewDirective, TabViewItemDirective } from "./directives/tab-view"; +import { + ActionBarComponent, + ActionBarScope, + ActionItemDirective, + NavigationButtonDirective +} from "./directives/action-bar"; +import { AndroidFilterComponent, IosFilterComponent } from "./directives/platform-filters"; export const NS_DIRECTIVES = [ ListViewComponent, @@ -16,13 +21,22 @@ export const NS_DIRECTIVES = [ IosFilterComponent, ]; -export { ListViewComponent, SetupItemViewArgs, TemplateKeyDirective } from './directives/list-view-comp'; -export { TextValueAccessor } from './value-accessors/text-value-accessor'; -export { CheckedValueAccessor } from './value-accessors/checked-value-accessor'; -export { DateValueAccessor } from './value-accessors/date-value-accessor'; -export { TimeValueAccessor } from './value-accessors/time-value-accessor'; -export { NumberValueAccessor } from './value-accessors/number-value-accessor'; -export { SelectedIndexValueAccessor } from './value-accessors/selectedIndex-value-accessor'; -export { TabViewDirective, TabViewItemDirective } from './directives/tab-view'; -export { ActionBarComponent, ActionBarScope, ActionItemDirective, NavigationButtonDirective } from './directives/action-bar'; -export { AndroidFilterComponent, IosFilterComponent } from './directives/platform-filters'; +export { + ListViewComponent, + SetupItemViewArgs, + TemplateKeyDirective +} from "./directives/list-view-comp"; +export { TextValueAccessor } from "./value-accessors/text-value-accessor"; +export { CheckedValueAccessor } from "./value-accessors/checked-value-accessor"; +export { DateValueAccessor } from "./value-accessors/date-value-accessor"; +export { TimeValueAccessor } from "./value-accessors/time-value-accessor"; +export { NumberValueAccessor } from "./value-accessors/number-value-accessor"; +export { SelectedIndexValueAccessor } from "./value-accessors/selectedIndex-value-accessor"; +export { TabViewDirective, TabViewItemDirective } from "./directives/tab-view"; +export { + ActionBarComponent, + ActionBarScope, + ActionItemDirective, + NavigationButtonDirective +} from "./directives/action-bar"; +export { AndroidFilterComponent, IosFilterComponent } from "./directives/platform-filters"; diff --git a/nativescript-angular/directives/action-bar.ts b/nativescript-angular/directives/action-bar.ts index 47ba7d356..5452e4dd5 100644 --- a/nativescript-angular/directives/action-bar.ts +++ b/nativescript-angular/directives/action-bar.ts @@ -1,11 +1,11 @@ -import { Directive, Component, ElementRef, Optional } from '@angular/core'; +import { Directive, Component, ElementRef, Optional } from "@angular/core"; import { ActionItem, ActionBar, NavigationButton } from "ui/action-bar"; import { isBlank } from "../lang-facade"; import {Page} from "ui/page"; -import { View } from 'ui/core/view'; -import { registerElement, ViewClassMeta, NgView } from '../element-registry'; +import { View } from "ui/core/view"; +import { registerElement, ViewClassMeta, NgView } from "../element-registry"; -var actionBarMeta: ViewClassMeta = { +let actionBarMeta: ViewClassMeta = { skipAddToDom: true, insertChild: (parent: NgView, child: NgView, _atIndex: number) => { const bar = (parent); @@ -34,11 +34,12 @@ var actionBarMeta: ViewClassMeta = { } else if (child instanceof ActionItem) { bar.actionItems.removeItem(childView); childView.parent = null; - } else if (child.nodeName !== "template" && child instanceof View && bar.titleView && bar.titleView === childView) { + } else if (child.nodeName !== "template" && child instanceof View && + bar.titleView && bar.titleView === childView) { bar.titleView = null; } }, -} +}; registerElement("ActionBar", () => require("ui/action-bar").ActionBar, actionBarMeta); registerElement("ActionItem", () => require("ui/action-bar").ActionItem); diff --git a/nativescript-angular/directives/dialogs.ts b/nativescript-angular/directives/dialogs.ts index b54c85534..493768b73 100644 --- a/nativescript-angular/directives/dialogs.ts +++ b/nativescript-angular/directives/dialogs.ts @@ -1,11 +1,11 @@ import { ReflectiveInjector, ComponentFactoryResolver, ViewContainerRef, Type, Injectable, ComponentRef, Directive -} from '@angular/core'; -import { Page } from 'ui/page'; -import { View } from 'ui/core/view'; -import { DetachedLoader } from '../common/detached-loader'; -import { PageFactory, PAGE_FACTORY } from '../platform-providers'; +} from "@angular/core"; +import { Page } from "ui/page"; +import { View } from "ui/core/view"; +import { DetachedLoader } from "../common/detached-loader"; +import { PageFactory, PAGE_FACTORY } from "../platform-providers"; export interface ModalDialogOptions { context?: any; @@ -32,15 +32,25 @@ export class ModalDialogService { let viewContainerRef = options.viewContainerRef || this.containerRef; if (!viewContainerRef) { - throw new Error("No viewContainerRef: Make sure you pass viewContainerRef in ModalDialogOptions."); + throw new Error( + "No viewContainerRef: Make sure you pass viewContainerRef in ModalDialogOptions."); } const parentPage: Page = viewContainerRef.injector.get(Page); - const resolver: ComponentFactoryResolver = viewContainerRef.injector.get(ComponentFactoryResolver); + const resolver: ComponentFactoryResolver = viewContainerRef.injector.get( + ComponentFactoryResolver); const pageFactory: PageFactory = viewContainerRef.injector.get(PAGE_FACTORY); return new Promise((resolve) => { - setTimeout(() => ModalDialogService.showDialog(type, options, resolve, viewContainerRef, resolver, parentPage, pageFactory), 10); + setTimeout(() => ModalDialogService.showDialog( + type, + options, + resolve, + viewContainerRef, + resolver, + parentPage, + pageFactory + ), 10); }); } @@ -69,7 +79,8 @@ export class ModalDialogService { { provide: ModalDialogParams, useValue: modalParams }, ]); - const childInjector = ReflectiveInjector.fromResolvedProviders(providers, containerRef.parentInjector); + const childInjector = ReflectiveInjector.fromResolvedProviders( + providers, containerRef.parentInjector); const detachedFactory = resolver.resolveComponentFactory(DetachedLoader); detachedLoaderRef = containerRef.createComponent(detachedFactory, -1, childInjector, null); detachedLoaderRef.instance.loadComponent(type).then((compRef) => { @@ -91,8 +102,9 @@ export class ModalDialogService { }) export class ModalDialogHost { constructor(containerRef: ViewContainerRef, modalService: ModalDialogService) { - console.log("ModalDialogHost is deprecated. Call ModalDialogService.showModal() by passing ViewContainerRef in the options instead.") + console.log("ModalDialogHost is deprecated. Call ModalDialogService.showModal() " + + "by passing ViewContainerRef in the options instead."); modalService.registerViewContainerRef(containerRef); } -} +} diff --git a/nativescript-angular/directives/list-view-comp.ts b/nativescript-angular/directives/list-view-comp.ts index 47fb8cd0d..0b9613c1c 100644 --- a/nativescript-angular/directives/list-view-comp.ts +++ b/nativescript-angular/directives/list-view-comp.ts @@ -18,13 +18,13 @@ import { Output, Host, ChangeDetectionStrategy -} from '@angular/core'; +} from "@angular/core"; import { isBlank } from "../lang-facade"; import { isListLikeIterable } from "../collection-facade"; -import { ListView } from 'ui/list-view'; -import { View, KeyedTemplate } from 'ui/core/view'; -import { ObservableArray } from 'data/observable-array'; -import { LayoutBase } from 'ui/layouts/layout-base'; +import { ListView } from "ui/list-view"; +import { View, KeyedTemplate } from "ui/core/view"; +import { ObservableArray } from "data/observable-array"; +import { LayoutBase } from "ui/layouts/layout-base"; import { listViewLog } from "../trace"; const NG_VIEW = "_ngViewRef"; @@ -48,12 +48,12 @@ export interface SetupItemViewArgs { } @Component({ - selector: 'ListView', + selector: "ListView", template: ` `, - inputs: ['items'], + inputs: ["items"], changeDetection: ChangeDetectionStrategy.OnPush }) export class ListViewComponent implements DoCheck, OnDestroy, AfterContentInit { @@ -66,9 +66,9 @@ export class ListViewComponent implements DoCheck, OnDestroy, AfterContentInit { private _differ: IterableDiffer; private _templateMap: Map; - @ViewChild('loader', { read: ViewContainerRef }) loader: ViewContainerRef; + @ViewChild("loader", { read: ViewContainerRef }) loader: ViewContainerRef; - @Output() public setupItemView: EventEmitter = new EventEmitter(); + @Output() public setupItemView = new EventEmitter(); @ContentChild(TemplateRef) itemTemplate: TemplateRef; @@ -79,7 +79,8 @@ export class ListViewComponent implements DoCheck, OnDestroy, AfterContentInit { needDiffer = false; } if (needDiffer && !this._differ && isListLikeIterable(value)) { - this._differ = this._iterableDiffers.find(this._items).create(this._cdr, (_index, item) => { return item; }); + this._differ = this._iterableDiffers.find(this._items) + .create(this._cdr, (_index, item) => { return item; }); } this.listView.items = this._items; @@ -143,18 +144,20 @@ export class ListViewComponent implements DoCheck, OnDestroy, AfterContentInit { let index = args.index; let items = args.object.items; - let currentItem = typeof (items.getItem) === "function" ? items.getItem(index) : items[index]; + let currentItem = typeof (items.getItem) === "function" ? + items.getItem(index) : items[index]; let viewRef: EmbeddedViewRef; if (args.view) { listViewLog("onItemLoading: " + index + " - Reusing existing view"); viewRef = args.view[NG_VIEW]; - // getting angular view from original element (in cases when ProxyViewContainer is used NativeScript internally wraps it in a StackLayout) + // getting angular view from original element (in cases when ProxyViewContainer + // is used NativeScript internally wraps it in a StackLayout) if (!viewRef) { - viewRef = (args.view._subViews && args.view._subViews.length > 0) ? args.view._subViews[0][NG_VIEW] : undefined; + viewRef = (args.view._subViews && args.view._subViews.length > 0) ? + args.view._subViews[0][NG_VIEW] : undefined; } - } - else { + } else { listViewLog("onItemLoading: " + index + " - Creating view from template"); viewRef = this.loader.createEmbeddedView(this.itemTemplate, new ListItemContext(), 0); args.view = getSingleViewFromViewRef(viewRef); @@ -182,7 +185,7 @@ export class ListViewComponent implements DoCheck, OnDestroy, AfterContentInit { private detectChangesOnChild(viewRef: EmbeddedViewRef, index: number) { // Manually detect changes in child view ref - // TODO: Is there a better way of getting viewRef's change detector + // TODO: Is there a better way of getting viewRef"s change detector const childChangeDetector = (viewRef); listViewLog("Manually detect changes in child: " + index); @@ -207,19 +210,16 @@ function getSingleViewRecursive(nodes: Array, nestLevel: number) { if (actualNodes.length === 0) { throw new Error("No suitable views found in list template! Nesting level: " + nestLevel); - } - else if (actualNodes.length > 1) { + } else if (actualNodes.length > 1) { throw new Error("More than one view found in list template! Nesting level: " + nestLevel); - } - else { + } else { if (actualNodes[0]) { let parentLayout = actualNodes[0].parent; if (parentLayout instanceof LayoutBase) { parentLayout.removeChild(actualNodes[0]); } return actualNodes[0]; - } - else { + } else { return getSingleViewRecursive(actualNodes[0].children, nestLevel + 1); } } @@ -243,10 +243,3 @@ export class TemplateKeyDirective { } } } - -// Debug helpers: -// const changeDetectorMode = ["CheckOnce", "Checked", "CheckAlways", "Detached", "OnPush", "Default"]; -// const changeDetectorStates = ["Never", "CheckedBefore", "Error"]; -// function getChangeDetectorState(cdr: any) { -// return "Mode: " + changeDetectorMode[parseInt(cdr.cdMode)] + " State: " + changeDetectorStates[parseInt(cdr.cdState)]; -// } diff --git a/nativescript-angular/directives/platform-filters.ts b/nativescript-angular/directives/platform-filters.ts index 797bba2b0..47fcb5c8d 100644 --- a/nativescript-angular/directives/platform-filters.ts +++ b/nativescript-angular/directives/platform-filters.ts @@ -1,4 +1,4 @@ -import {Component, Inject} from '@angular/core'; +import {Component, Inject} from "@angular/core"; import {Device, platformNames} from "platform"; import {DEVICE} from "../platform-providers"; diff --git a/nativescript-angular/directives/tab-view.ts b/nativescript-angular/directives/tab-view.ts index 44a6a1d0c..7b60330b9 100644 --- a/nativescript-angular/directives/tab-view.ts +++ b/nativescript-angular/directives/tab-view.ts @@ -1,22 +1,22 @@ import { ElementRef, Directive, Input, TemplateRef, ViewContainerRef } from "@angular/core"; import { TabView, TabViewItem } from "ui/tab-view"; -import * as utils from '../common/utils'; +import * as utils from "../common/utils"; import { rendererLog } from "../trace"; import { isBlank } from "../lang-facade"; @Directive({ - selector: 'TabView', - inputs: ['selectedIndex'] + selector: "TabView", + inputs: ["selectedIndex"] }) export class TabViewDirective { public tabView: TabView; private _selectedIndex: number; private viewInitialized: boolean; - + get selectedIndex(): number { return this._selectedIndex; } - + set selectedIndex(value) { this._selectedIndex = utils.convertToInt(value); if (this.viewInitialized) { @@ -27,7 +27,7 @@ export class TabViewDirective { constructor(element: ElementRef) { this.tabView = element.nativeElement; } - + ngAfterViewInit() { this.viewInitialized = true; rendererLog("this._selectedIndex: " + this._selectedIndex); @@ -38,8 +38,8 @@ export class TabViewDirective { } @Directive({ - selector: '[tabItem]', - inputs: ['title', 'iconSource'] + selector: "[tabItem]", + inputs: ["title", "iconSource"] }) export class TabViewItemDirective { private item: TabViewItem; @@ -53,7 +53,7 @@ export class TabViewItemDirective { ) { } - @Input('tabItem') config: any; + @Input("tabItem") config: any; set title(value: string) { if (this._title !== value) { @@ -85,9 +85,9 @@ export class TabViewItemDirective { } const viewRef = this.viewContainer.createEmbeddedView(this.templateRef); - //Filter out text nodes, etc + // Filter out text nodes, etc const realViews = viewRef.rootNodes.filter((node) => - node.nodeName && node.nodeName !== '#text') + node.nodeName && node.nodeName !== "#text"); if (realViews.length > 0) { this.item.view = realViews[0]; diff --git a/nativescript-angular/dom-adapter.ts b/nativescript-angular/dom-adapter.ts index 1c248f8b4..f80986637 100644 --- a/nativescript-angular/dom-adapter.ts +++ b/nativescript-angular/dom-adapter.ts @@ -1,7 +1,7 @@ -import { ElementSchemaRegistry } from '@angular/compiler'; -import { SchemaMetadata } from '@angular/core'; +import { ElementSchemaRegistry } from "@angular/compiler"; +import { SchemaMetadata } from "@angular/core"; import { Parse5DomAdapter } from "./parse5_adapter"; -import { setRootDomAdapter } from './private_import_platform-browser'; +import { setRootDomAdapter } from "./private_import_platform-browser"; import { rendererLog } from "./trace"; import { print } from "./lang-facade"; @@ -29,7 +29,7 @@ export class NativeScriptElementSchemaRegistry extends ElementSchemaRegistry { } getDefaultComponentElementName(): string { - return 'ng-component'; + return "ng-component"; } securityContext(_tagName: string, _propName: string): any { @@ -52,7 +52,11 @@ export class NativeScriptElementSchemaRegistry extends ElementSchemaRegistry { return propName; } - normalizeAnimationStyleValue(_camelCaseProp: string, _userProvidedProp: string, val: string | number): + normalizeAnimationStyleValue( + _camelCaseProp: string, + _userProvidedProp: string, + val: string | number + ): { error: string, value: string } { return { error: null, value: val.toString() }; } @@ -65,7 +69,7 @@ export class NativeScriptDomAdapter extends Parse5DomAdapter { } hasProperty(_element: any, _name: string) { - //TODO: actually check if the property exists. + // TODO: actually check if the property exists. return true; } diff --git a/nativescript-angular/element-registry.ts b/nativescript-angular/element-registry.ts index dff81eb01..948db15f1 100644 --- a/nativescript-angular/element-registry.ts +++ b/nativescript-angular/element-registry.ts @@ -1,4 +1,4 @@ -import {View} from 'ui/core/view'; +import {View} from "ui/core/view"; export type ViewResolver = () => ViewClass; export type NgView = View & ViewExtensions; @@ -17,17 +17,21 @@ export interface ViewExtensions { } export interface ViewClass { - new (): View + new (): View; } const defaultViewMeta: ViewClassMeta = { skipAddToDom: false, }; -const elementMap: Map = new Map(); +const elementMap = new Map(); const camelCaseSplit = /([a-z0-9])([A-Z])/g; -export function registerElement(elementName: string, resolver: ViewResolver, meta?: ViewClassMeta): void { +export function registerElement( + elementName: string, + resolver: ViewResolver, + meta?: ViewClassMeta +): void { if (elementMap.has(elementName)) { throw new Error(`Element for ${elementName} already registered.`); } else { @@ -66,9 +70,8 @@ export function isKnownView(elementName: string): boolean { } - -//Register default NativeScript components -//Note: ActionBar related components are registerd together with action-bar directives. +// Register default NativeScript components +// Note: ActionBar related components are registerd together with action-bar directives. registerElement("AbsoluteLayout", () => require("ui/layouts/absolute-layout").AbsoluteLayout); registerElement("ActivityIndicator", () => require("ui/activity-indicator").ActivityIndicator); registerElement("Border", () => require("ui/border").Border); @@ -106,4 +109,5 @@ registerElement("WrapLayout", () => require("ui/layouts/wrap-layout").WrapLayout registerElement("FormattedString", () => require("text/formatted-string").FormattedString); registerElement("Span", () => require("text/span").Span); -registerElement("DetachedContainer", () => require("ui/proxy-view-container").ProxyViewContainer, { skipAddToDom: true }); \ No newline at end of file +registerElement("DetachedContainer", () => require("ui/proxy-view-container").ProxyViewContainer, + { skipAddToDom: true }); diff --git a/nativescript-angular/file-system/ns-file-system.ts b/nativescript-angular/file-system/ns-file-system.ts index 704ae45e4..f70381494 100644 --- a/nativescript-angular/file-system/ns-file-system.ts +++ b/nativescript-angular/file-system/ns-file-system.ts @@ -1,5 +1,5 @@ -import {Injectable} from '@angular/core'; -import {knownFolders, Folder} from 'file-system'; +import {Injectable} from "@angular/core"; +import {knownFolders, Folder} from "file-system"; // Allows greater flexibility with `file-system` and Angular // Also provides a way for `file-system` to be mocked for testing @@ -9,4 +9,4 @@ export class NSFileSystem { public currentApp(): Folder { return knownFolders.currentApp(); } -} \ No newline at end of file +} diff --git a/nativescript-angular/forms.ts b/nativescript-angular/forms.ts index aa5204ff8..e449fc79f 100644 --- a/nativescript-angular/forms.ts +++ b/nativescript-angular/forms.ts @@ -1,11 +1,11 @@ import { NgModule } from "@angular/core"; import { FormsModule } from "@angular/forms"; -import { TextValueAccessor } from './value-accessors/text-value-accessor'; -import { CheckedValueAccessor } from './value-accessors/checked-value-accessor'; -import { DateValueAccessor } from './value-accessors/date-value-accessor'; -import { TimeValueAccessor } from './value-accessors/time-value-accessor'; -import { NumberValueAccessor } from './value-accessors/number-value-accessor'; -import { SelectedIndexValueAccessor } from './value-accessors/selectedIndex-value-accessor'; +import { TextValueAccessor } from "./value-accessors/text-value-accessor"; +import { CheckedValueAccessor } from "./value-accessors/checked-value-accessor"; +import { DateValueAccessor } from "./value-accessors/date-value-accessor"; +import { TimeValueAccessor } from "./value-accessors/time-value-accessor"; +import { NumberValueAccessor } from "./value-accessors/number-value-accessor"; +import { SelectedIndexValueAccessor } from "./value-accessors/selectedIndex-value-accessor"; export const FORMS_DIRECTIVES = [ TextValueAccessor, diff --git a/nativescript-angular/http.ts b/nativescript-angular/http.ts index 11cd2c1f6..ac5d8631a 100644 --- a/nativescript-angular/http.ts +++ b/nativescript-angular/http.ts @@ -1,6 +1,6 @@ import { Http, XHRBackend, RequestOptions -} from '@angular/http'; +} from "@angular/http"; import { NSXSRFStrategy, NSHttp } from "./http/ns-http"; import { NSFileSystem } from "./file-system/ns-file-system"; @@ -17,9 +17,10 @@ export function nsXSRFStrategyFactory() { @NgModule({ providers: [ - { provide: XSRFStrategy, useFactory: nsXSRFStrategyFactory }, + {provide: XSRFStrategy, useFactory: nsXSRFStrategyFactory}, NSFileSystem, - { provide: Http, useFactory: nsHttpFactory, deps: [XHRBackend, RequestOptions, NSFileSystem] } + {provide: Http, useFactory: nsHttpFactory, + deps: [XHRBackend, RequestOptions, NSFileSystem]} ], imports: [ HttpModule, diff --git a/nativescript-angular/http/ns-http.ts b/nativescript-angular/http/ns-http.ts index 5c504dcff..8e9b8e1fa 100644 --- a/nativescript-angular/http/ns-http.ts +++ b/nativescript-angular/http/ns-http.ts @@ -1,8 +1,15 @@ -import {Injectable} from '@angular/core'; -import {Http, ConnectionBackend, RequestOptionsArgs, ResponseOptions, ResponseType, Response} from '@angular/http'; -import {Observable} from 'rxjs/Observable'; -import 'rxjs/add/observable/fromPromise'; -import {NSFileSystem} from '../file-system/ns-file-system'; +import {Injectable} from "@angular/core"; +import { + Http, + ConnectionBackend, + RequestOptionsArgs, + ResponseOptions, + ResponseType, + Response +} from "@angular/http"; +import {Observable} from "rxjs/Observable"; +import "rxjs/add/observable/fromPromise"; +import {NSFileSystem} from "../file-system/ns-file-system"; export class NSXSRFStrategy { public configureRequest(_req: any) { @@ -21,9 +28,9 @@ export class NSHttp extends Http { * Uses a local file if `~/` resource is requested. */ get(url: string, options?: RequestOptionsArgs): Observable { - if (url.indexOf('~') === 0 || url.indexOf('/') === 0) { + if (url.indexOf("~") === 0 || url.indexOf("/") === 0) { // normalize url - url = url.replace('~', '').replace('/', ''); + url = url.replace("~", "").replace("/", ""); // request from local app resources return Observable.fromPromise(new Promise((resolve, reject) => { let app = this.nsFileSystem.currentApp(); @@ -35,7 +42,7 @@ export class NSHttp extends Http { reject(responseOptions(err, 400, url)); }); } else { - reject(responseOptions('Not Found', 404, url)); + reject(responseOptions("Not Found", 404, url)); } })); } else { @@ -48,7 +55,7 @@ function responseOptions(body: string | Object, status: number, url: string): Re return new Response(new ResponseOptions({ body: body, status: status, - statusText: 'OK', + statusText: "OK", type: status === 200 ? ResponseType.Default : ResponseType.Error, url: url })); diff --git a/nativescript-angular/index.ts b/nativescript-angular/index.ts index ef3f466dc..e146bd674 100644 --- a/nativescript-angular/index.ts +++ b/nativescript-angular/index.ts @@ -4,4 +4,4 @@ export * from "./router"; export * from "./forms"; export * from "./http"; export * from "./directives"; -export * from "./common/detached-loader"; \ No newline at end of file +export * from "./common/detached-loader"; diff --git a/nativescript-angular/lang-facade.ts b/nativescript-angular/lang-facade.ts index fabf8883d..883c3662f 100644 --- a/nativescript-angular/lang-facade.ts +++ b/nativescript-angular/lang-facade.ts @@ -1,3 +1,4 @@ +/* tslint:disable */ //Copied unexported functions from @angular/core/src/facade/lang var globalScope = global; export var global = globalScope; @@ -32,16 +33,16 @@ export function isArray(obj: any): boolean { // When Symbol.iterator doesn't exist, retrieves the key used in es6-shim declare var Symbol: any; -var _symbolIterator: any = null; +let _symbolIterator: any = null; export function getSymbolIterator(): string|symbol { if (isBlank(_symbolIterator)) { if (isPresent((globalScope).Symbol) && isPresent(Symbol.iterator)) { _symbolIterator = Symbol.iterator; } else { // es6-shim specific logic - var keys = Object.getOwnPropertyNames(Map.prototype); - for (var i = 0; i < keys.length; ++i) { - var key = keys[i]; + let keys = Object.getOwnPropertyNames(Map.prototype); + for (let i = 0; i < keys.length; ++i) { + let key = keys[i]; if (key !== 'entries' && key !== 'size' && (Map as any).prototype[key] === Map.prototype['entries']) { _symbolIterator = key; @@ -66,10 +67,10 @@ export class DateWrapper { } export function setValueOnPath(global: any, path: string, value: any) { - var parts = path.split('.'); - var obj: any = global; + let parts = path.split('.'); + let obj: any = global; while (parts.length > 1) { - var name = parts.shift(); + let name = parts.shift(); if (obj.hasOwnProperty(name) && isPresent(obj[name])) { obj = obj[name]; } else { diff --git a/nativescript-angular/nativescript.module.ts b/nativescript-angular/nativescript.module.ts index 4f5e7a93a..a1fa97fac 100644 --- a/nativescript-angular/nativescript.module.ts +++ b/nativescript-angular/nativescript.module.ts @@ -1,12 +1,12 @@ -import 'globals'; -import './zone.js/dist/zone-nativescript'; +import "globals"; +import "./zone.js/dist/zone-nativescript"; -import 'reflect-metadata'; -import './polyfills/array'; -import './polyfills/console'; +import "reflect-metadata"; +import "./polyfills/array"; +import "./polyfills/console"; -import { CommonModule } from '@angular/common'; -import { NativeScriptRootRenderer, NativeScriptRenderer } from './renderer'; +import { CommonModule } from "@angular/common"; +import { NativeScriptRootRenderer, NativeScriptRenderer } from "./renderer"; import { DetachedLoader } from "./common/detached-loader"; import { ModalDialogHost, ModalDialogService } from "./directives/dialogs"; import { @@ -15,11 +15,11 @@ import { Renderer, RootRenderer, NgModule, NO_ERRORS_SCHEMA, -} from '@angular/core'; +} from "@angular/core"; import { defaultPageProvider, defaultFrameProvider, defaultDeviceProvider } from "./platform-providers"; -import { NS_DIRECTIVES } from './directives'; +import { NS_DIRECTIVES } from "./directives"; import * as nativescriptIntl from "nativescript-intl"; global.Intl = nativescriptIntl; diff --git a/nativescript-angular/package.json b/nativescript-angular/package.json index 3a908783f..1e66972eb 100644 --- a/nativescript-angular/package.json +++ b/nativescript-angular/package.json @@ -14,10 +14,11 @@ "url": "https://github.com/NativeScript/nativescript-angular.git" }, "scripts": { - "postinstall": "node postinstall.js", - "ngc": "ngc -p tsconfig.json", - "tsc": "tsc -p tsconfig.json", - "prepublish": "npm run tsc && npm run ngc" + "tslint": "tslint --project tsconfig.json --config tslint.json", + "postinstall": "node postinstall.js", + "ngc": "ngc -p tsconfig.json", + "tsc": "tsc -p tsconfig.json", + "prepublish": "npm run tsc && npm run ngc" }, "dependencies": { "nativescript-intl": "~0.0.4", @@ -40,6 +41,7 @@ "tns-core-modules": ">=2.4.0 || >=2.4.0-2016", "zone.js": "^0.6.21", "typescript": "^2.0.2", + "tslint": "~4.0.1", "@angular/compiler-cli": "~2.2.1" }, "nativescript": {} diff --git a/nativescript-angular/parse5_adapter.ts b/nativescript-angular/parse5_adapter.ts index 3c4782940..c6a5f2b3a 100644 --- a/nativescript-angular/parse5_adapter.ts +++ b/nativescript-angular/parse5_adapter.ts @@ -1,3 +1,4 @@ +/* tslint:disable */ /** * @license * Copyright Google Inc. All Rights Reserved. @@ -13,9 +14,9 @@ import {DomAdapter, setRootDomAdapter} from './private_import_platform-browser'; import {isPresent, isBlank, setValueOnPath} from "./lang-facade"; import {SelectorMatcher, CssSelector} from '@angular/compiler'; -var parser: any /** TODO #9100 */ = null; -var serializer: any /** TODO #9100 */ = null; -var treeAdapter: any /** TODO #9100 */ = null; +let parser: any /** TODO #9100 */ = null; +let serializer: any /** TODO #9100 */ = null; +let treeAdapter: any /** TODO #9100 */ = null; const _attrToPropMap: {[key: string]: string} = { 'class': 'className', diff --git a/nativescript-angular/platform-common.ts b/nativescript-angular/platform-common.ts index 4598083a7..df1f43171 100644 --- a/nativescript-angular/platform-common.ts +++ b/nativescript-angular/platform-common.ts @@ -1,9 +1,9 @@ // Initial imports and polyfills -import 'globals'; -import './zone.js/dist/zone-nativescript'; -import 'reflect-metadata'; -import './polyfills/array'; -import './polyfills/console'; +import "globals"; +import "./zone.js/dist/zone-nativescript"; +import "reflect-metadata"; +import "./polyfills/array"; +import "./polyfills/console"; import { Type, @@ -16,22 +16,22 @@ import { Provider, Sanitizer, OpaqueToken, -} from '@angular/core'; +} from "@angular/core"; -//Work around a TS bug requiring an import of OpaqueToken without using it +// Work around a TS bug requiring an import of OpaqueToken without using it if (global.___TS_UNUSED) { - () => { + (() => { return OpaqueToken; - } + })(); } import { rendererLog, rendererError } from "./trace"; -import { PAGE_FACTORY, PageFactory, defaultPageFactoryProvider } from './platform-providers'; +import { PAGE_FACTORY, PageFactory, defaultPageFactoryProvider } from "./platform-providers"; import * as application from "application"; import { topmost, NavigationEntry } from "ui/frame"; -import { Page } from 'ui/page'; -import { TextView } from 'ui/text-view'; +import { Page } from "ui/page"; +import { TextView } from "ui/text-view"; import * as nativescriptIntl from "nativescript-intl"; global.Intl = nativescriptIntl; @@ -72,15 +72,18 @@ export class NativeScriptPlatformRef extends PlatformRef { this.bootstrapApp(); - return null; //Make the compiler happy + return null; // Make the compiler happy } - bootstrapModule(moduleType: Type, compilerOptions: CompilerOptions | CompilerOptions[] = []): Promise> { + bootstrapModule( + moduleType: Type, + compilerOptions: CompilerOptions | CompilerOptions[] = [] + ): Promise> { this._bootstrapper = () => this.platform.bootstrapModule(moduleType, compilerOptions); this.bootstrapApp(); - return null; //Make the compiler happy + return null; // Make the compiler happy } private bootstrapApp() { @@ -147,15 +150,15 @@ export class NativeScriptPlatformRef extends PlatformRef { } let onLoadedHandler = function () { - page.off('loaded', onLoadedHandler); - //profiling.stop('application-start'); - rendererLog('Page loaded'); + page.off("loaded", onLoadedHandler); + // profiling.stop("application-start"); + rendererLog("Page loaded"); - //profiling.start('ng-bootstrap'); - rendererLog('BOOTSTRAPPING...'); + // profiling.start("ng-bootstrap"); + rendererLog("BOOTSTRAPPING..."); bootstrapAction().then((moduleRef) => { - //profiling.stop('ng-bootstrap'); - rendererLog('ANGULAR BOOTSTRAP DONE.'); + // profiling.stop("ng-bootstrap"); + rendererLog("ANGULAR BOOTSTRAP DONE."); lastBootstrappedModule = new WeakRef(moduleRef); if (resolve) { @@ -163,7 +166,7 @@ export class NativeScriptPlatformRef extends PlatformRef { } return moduleRef; }, (err) => { - rendererError('ERROR BOOTSTRAPPING ANGULAR'); + rendererError("ERROR BOOTSTRAPPING ANGULAR"); let errorMessage = err.message + "\n\n" + err.stack; rendererError(errorMessage); @@ -177,7 +180,7 @@ export class NativeScriptPlatformRef extends PlatformRef { }); }; - page.on('loaded', onLoadedHandler); + page.on("loaded", onLoadedHandler); return page; } diff --git a/nativescript-angular/platform-providers.ts b/nativescript-angular/platform-providers.ts index 98fbb374c..ff47f2800 100644 --- a/nativescript-angular/platform-providers.ts +++ b/nativescript-angular/platform-providers.ts @@ -1,18 +1,18 @@ -import { topmost, Frame } from 'ui/frame'; -import { Page } from 'ui/page'; -import { OpaqueToken } from '@angular/core'; +import { topmost, Frame } from "ui/frame"; +import { Page } from "ui/page"; +import { OpaqueToken } from "@angular/core"; import { device } from "platform"; import * as platform from "platform"; -export const APP_ROOT_VIEW = new OpaqueToken('App Root View'); -export const DEVICE = new OpaqueToken('platfrom device'); -export const PAGE_FACTORY = new OpaqueToken('page factory'); +export const APP_ROOT_VIEW = new OpaqueToken("App Root View"); +export const DEVICE = new OpaqueToken("platfrom device"); +export const PAGE_FACTORY = new OpaqueToken("page factory"); -//Work around a TS bug requiring an import of platform.Device without using it +// Work around a TS bug requiring an import of platform.Device without using it if (global.___TS_UNUSED) { - () => { + (() => { return platform; - } + })(); } export function getDefaultPage(): Page { @@ -31,13 +31,13 @@ export const defaultDeviceProvider = { provide: DEVICE, useValue: device }; export type PageFactory = (options: PageFactoryOptions) => Page; export interface PageFactoryOptions { - isBootstrap?: boolean, - isLivesync?:boolean, - isModal?: boolean, - isNavigation?: boolean, - componentType?: any + isBootstrap?: boolean; + isLivesync?: boolean; + isModal?: boolean; + isNavigation?: boolean; + componentType?: any; } export const defaultPageFactory: PageFactory = function (_opts: PageFactoryOptions) { return new Page(); -} +}; export const defaultPageFactoryProvider = { provide: PAGE_FACTORY, useValue: defaultPageFactory }; diff --git a/nativescript-angular/platform-static.ts b/nativescript-angular/platform-static.ts index 9c9d7c32e..b6a3c65fb 100644 --- a/nativescript-angular/platform-static.ts +++ b/nativescript-angular/platform-static.ts @@ -1,14 +1,19 @@ // Always import platform-common first - because polyfills -import { NativeScriptPlatformRef, AppOptions, COMMON_PROVIDERS, PlatformFactory } from "./platform-common"; +import { + NativeScriptPlatformRef, + AppOptions, + COMMON_PROVIDERS, + PlatformFactory +} from "./platform-common"; -import { platformCore, PlatformRef, createPlatformFactory } from '@angular/core'; +import { platformCore, PlatformRef, createPlatformFactory } from "@angular/core"; // "Static" platform const _platformNativeScript: PlatformFactory = createPlatformFactory( - platformCore, 'nativeScript', [...COMMON_PROVIDERS]); + platformCore, "nativeScript", [...COMMON_PROVIDERS]); export function platformNativeScript(options?: AppOptions, extraProviders?: any[]): PlatformRef { - //Return raw platform to advanced users only if explicitly requested + // Return raw platform to advanced users only if explicitly requested if (options && options.bootInExistingPage === true) { return _platformNativeScript(extraProviders); } else { diff --git a/nativescript-angular/platform.ts b/nativescript-angular/platform.ts index 60d3fbdc5..809d6a486 100644 --- a/nativescript-angular/platform.ts +++ b/nativescript-angular/platform.ts @@ -1,29 +1,34 @@ // Always import platform-common first - because polyfills -import { NativeScriptPlatformRef, AppOptions, PlatformFactory, COMMON_PROVIDERS } from "./platform-common"; +import { + NativeScriptPlatformRef, + AppOptions, + PlatformFactory, + COMMON_PROVIDERS +} from "./platform-common"; import { ElementSchemaRegistry, ResourceLoader, COMPILER_PROVIDERS, platformCoreDynamic -} from '@angular/compiler'; +} from "@angular/compiler"; import { COMPILER_OPTIONS, PlatformRef, OpaqueToken, createPlatformFactory -} from '@angular/core'; +} from "@angular/core"; -//Work around a TS bug requiring an import of OpaqueToken without using it +// Work around a TS bug requiring an import of OpaqueToken without using it if (global.___TS_UNUSED) { - () => { + (() => { return OpaqueToken; - } + })(); } -import { NativeScriptElementSchemaRegistry } from './dom-adapter'; -import { FileSystemResourceLoader } from './resource-loader'; +import { NativeScriptElementSchemaRegistry } from "./dom-adapter"; +import { FileSystemResourceLoader } from "./resource-loader"; export { NativeScriptModule } from "./nativescript.module"; @@ -43,10 +48,13 @@ export const NS_COMPILER_PROVIDERS = [ // Dynamic platform const _platformNativeScriptDynamic: PlatformFactory = createPlatformFactory( - platformCoreDynamic, 'nativeScriptDynamic', [...COMMON_PROVIDERS, ...NS_COMPILER_PROVIDERS]); + platformCoreDynamic, "nativeScriptDynamic", [...COMMON_PROVIDERS, ...NS_COMPILER_PROVIDERS]); -export function platformNativeScriptDynamic(options?: AppOptions, extraProviders?: any[]): PlatformRef { - //Return raw platform to advanced users only if explicitly requested +export function platformNativeScriptDynamic( + options?: AppOptions, + extraProviders?: any[] +): PlatformRef { + // Return raw platform to advanced users only if explicitly requested if (options && options.bootInExistingPage === true) { return _platformNativeScriptDynamic(extraProviders); } else { diff --git a/nativescript-angular/polyfills/array.ts b/nativescript-angular/polyfills/array.ts index 20f86c833..a08882398 100644 --- a/nativescript-angular/polyfills/array.ts +++ b/nativescript-angular/polyfills/array.ts @@ -1,25 +1,25 @@ if (!(Array.prototype).fill) { (Array.prototype).fill = function(value) { - - var O = Object(this); - var len = parseInt(O.length, 10); - var start = arguments[1]; - var relativeStart = parseInt(start, 10) || 0; - var k = relativeStart < 0 - ? Math.max( len + relativeStart, 0) + + let O = Object(this); + let len = parseInt(O.length, 10); + let start = arguments[1]; + let relativeStart = parseInt(start, 10) || 0; + let k = relativeStart < 0 + ? Math.max( len + relativeStart, 0) : Math.min( relativeStart, len ); - var end = arguments[2]; - var relativeEnd = end === undefined - ? len - : (parseInt( end) || 0) ; - var final = relativeEnd < 0 + let end = arguments[2]; + let relativeEnd = end === undefined + ? len + : (parseInt(end, 10) || 0) ; + let final = relativeEnd < 0 ? Math.max(len + relativeEnd, 0) : Math.min(relativeEnd, len); - + for (; k < final; k++) { O[k] = value; } - + return O; }; } @@ -29,16 +29,16 @@ if (!(Array).from) { let results: Array = []; if (iterable.next) { - //Iterator objects - let step = null; - while (step = iterable.next()) { - if (step.done) + // Iterator objects + for (let step = null; ; step = iterable.next()) { + if (step.done) { break; - else + } else { results.push(step.value); + } } } else { - //Array-like objects + // Array-like objects results = [].slice.call(iterable); } diff --git a/nativescript-angular/polyfills/console.ts b/nativescript-angular/polyfills/console.ts index 2bdd97dda..383ae203e 100644 --- a/nativescript-angular/polyfills/console.ts +++ b/nativescript-angular/polyfills/console.ts @@ -4,4 +4,4 @@ if (!console.group) { if (!console.groupEnd) { console.groupEnd = () => {}; -} \ No newline at end of file +} diff --git a/nativescript-angular/private_import_core.ts b/nativescript-angular/private_import_core.ts index f2512b86f..b629c7c8c 100644 --- a/nativescript-angular/private_import_core.ts +++ b/nativescript-angular/private_import_core.ts @@ -6,32 +6,32 @@ * found in the LICENSE file at https://angular.io/license */ -import {__core_private__ as r} from '@angular/core'; +import {__core_private__ as r} from "@angular/core"; export type RenderDebugInfo = typeof r._RenderDebugInfo; -export var RenderDebugInfo: typeof r.RenderDebugInfo = r.RenderDebugInfo; +export let RenderDebugInfo: typeof r.RenderDebugInfo = r.RenderDebugInfo; -export var ReflectionCapabilities: typeof r.ReflectionCapabilities = r.ReflectionCapabilities; +export let ReflectionCapabilities: typeof r.ReflectionCapabilities = r.ReflectionCapabilities; export type DebugDomRootRenderer = typeof r._DebugDomRootRenderer; -export var DebugDomRootRenderer: typeof r.DebugDomRootRenderer = r.DebugDomRootRenderer; -export var reflector: typeof r.reflector = r.reflector; +export let DebugDomRootRenderer: typeof r.DebugDomRootRenderer = r.DebugDomRootRenderer; +export let reflector: typeof r.reflector = r.reflector; export type NoOpAnimationPlayer = typeof r._NoOpAnimationPlayer; -export var NoOpAnimationPlayer: typeof r.NoOpAnimationPlayer = r.NoOpAnimationPlayer; +export let NoOpAnimationPlayer: typeof r.NoOpAnimationPlayer = r.NoOpAnimationPlayer; export type AnimationPlayer = typeof r._AnimationPlayer; -export var AnimationPlayer: typeof r.AnimationPlayer = r.AnimationPlayer; +export let AnimationPlayer: typeof r.AnimationPlayer = r.AnimationPlayer; export type AnimationSequencePlayer = typeof r._AnimationSequencePlayer; -export var AnimationSequencePlayer: typeof r.AnimationSequencePlayer = r.AnimationSequencePlayer; +export let AnimationSequencePlayer: typeof r.AnimationSequencePlayer = r.AnimationSequencePlayer; export type AnimationGroupPlayer = typeof r._AnimationGroupPlayer; -export var AnimationGroupPlayer: typeof r.AnimationGroupPlayer = r.AnimationGroupPlayer; +export let AnimationGroupPlayer: typeof r.AnimationGroupPlayer = r.AnimationGroupPlayer; export type AnimationKeyframe = typeof r._AnimationKeyframe; -export var AnimationKeyframe: typeof r.AnimationKeyframe = r.AnimationKeyframe; +export let AnimationKeyframe: typeof r.AnimationKeyframe = r.AnimationKeyframe; export type AnimationStyles = typeof r._AnimationStyles; -export var AnimationStyles: typeof r.AnimationStyles = r.AnimationStyles; -export var prepareFinalAnimationStyles: typeof r.prepareFinalAnimationStyles = +export let AnimationStyles: typeof r.AnimationStyles = r.AnimationStyles; +export let prepareFinalAnimationStyles: typeof r.prepareFinalAnimationStyles = r.prepareFinalAnimationStyles; -export var balanceAnimationKeyframes: typeof r.balanceAnimationKeyframes = +export let balanceAnimationKeyframes: typeof r.balanceAnimationKeyframes = r.balanceAnimationKeyframes; -export var clearStyles: typeof r.clearStyles = r.clearStyles; -export var collectAndResolveStyles: typeof r.collectAndResolveStyles = r.collectAndResolveStyles; +export let clearStyles: typeof r.clearStyles = r.clearStyles; +export let collectAndResolveStyles: typeof r.collectAndResolveStyles = r.collectAndResolveStyles; diff --git a/nativescript-angular/private_import_platform-browser.ts b/nativescript-angular/private_import_platform-browser.ts index d15eed339..946ea58c0 100644 --- a/nativescript-angular/private_import_platform-browser.ts +++ b/nativescript-angular/private_import_platform-browser.ts @@ -6,9 +6,9 @@ * found in the LICENSE file at https://angular.io/license */ -import {__platform_browser_private__ as _} from '@angular/platform-browser'; +import {__platform_browser_private__ as _} from "@angular/platform-browser"; export type DomAdapter = typeof _._DomAdapter; -export var DomAdapter: typeof _.DomAdapter = _.DomAdapter; -export var setRootDomAdapter: typeof _.setRootDomAdapter = _.setRootDomAdapter; -export var getDOM: typeof _.getDOM = _.getDOM; +export let DomAdapter: typeof _.DomAdapter = _.DomAdapter; +export let setRootDomAdapter: typeof _.setRootDomAdapter = _.setRootDomAdapter; +export let getDOM: typeof _.getDOM = _.getDOM; diff --git a/nativescript-angular/renderer.ts b/nativescript-angular/renderer.ts index 728edf378..98403e836 100644 --- a/nativescript-angular/renderer.ts +++ b/nativescript-angular/renderer.ts @@ -1,22 +1,22 @@ import { Inject, Injectable, Optional, NgZone, Renderer, RootRenderer, RenderComponentType, -} from '@angular/core'; +} from "@angular/core"; import { AnimationPlayer } from "@angular/core"; import { AnimationStyles, AnimationKeyframe } from "./private_import_core"; import {APP_ROOT_VIEW, DEVICE} from "./platform-providers"; import {isBlank} from "./lang-facade"; import {View} from "ui/core/view"; import * as application from "application"; -import {topmost} from 'ui/frame'; -import {Page} from 'ui/page'; +import {topmost} from "ui/frame"; +import {Page} from "ui/page"; import {ViewUtil, NgView} from "./view-util"; import {rendererLog as traceLog} from "./trace"; import {escapeRegexSymbols} from "utils/utils"; import { Device } from "platform"; import * as nsAnimationDriver from "./animation-driver"; -var nsAnimationDriverModule: typeof nsAnimationDriver; +let nsAnimationDriverModule: typeof nsAnimationDriver; function ensureAnimationDriverModule() { if (!nsAnimationDriverModule) { @@ -24,8 +24,8 @@ function ensureAnimationDriverModule() { } } -//CONTENT_ATTR not exported from dom_renderer - we need it for styles application. -export const COMPONENT_VARIABLE = '%COMP%'; +// CONTENT_ATTR not exported from dom_renderer - we need it for styles application. +export const COMPONENT_VARIABLE = "%COMP%"; export const CONTENT_ATTR = `_ngcontent-${COMPONENT_VARIABLE}`; @@ -50,7 +50,7 @@ export class NativeScriptRootRenderer implements RootRenderer { this._viewUtil = new ViewUtil(device); } - private _registeredComponents: Map = new Map(); + private _registeredComponents = new Map(); public get rootView(): View { if (!this._rootView) { @@ -70,7 +70,8 @@ export class NativeScriptRootRenderer implements RootRenderer { renderComponent(componentProto: RenderComponentType): Renderer { let renderer = this._registeredComponents.get(componentProto.id); if (isBlank(renderer)) { - renderer = new NativeScriptRenderer(this, componentProto, this.animationDriver, this._zone); + renderer = new NativeScriptRenderer(this, componentProto, + this.animationDriver, this._zone); this._registeredComponents.set(componentProto.id, renderer); } return renderer; @@ -101,7 +102,7 @@ export class NativeScriptRenderer extends Renderer { const realCSS = this.replaceNgAttribute(cssString, this.componentProtoId); application.addCss(realCSS); } - traceLog('NativeScriptRenderer created'); + traceLog("NativeScriptRenderer created"); } private attrReplacer = new RegExp(escapeRegexSymbols(CONTENT_ATTR), "g"); @@ -117,26 +118,26 @@ export class NativeScriptRenderer extends Renderer { } selectRootElement(selector: string): NgView { - traceLog('selectRootElement: ' + selector); + traceLog("selectRootElement: " + selector); const rootView = this.rootRenderer.rootView; - rootView.nodeName = 'ROOT'; + rootView.nodeName = "ROOT"; return rootView; } createViewRoot(hostElement: NgView): NgView { - traceLog('CREATE VIEW ROOT: ' + hostElement.nodeName); + traceLog("CREATE VIEW ROOT: " + hostElement.nodeName); return hostElement; } projectNodes(parentElement: NgView, nodes: NgView[]): void { - traceLog('NativeScriptRenderer.projectNodes'); + traceLog("NativeScriptRenderer.projectNodes"); nodes.forEach((node) => { this.viewUtil.insertChild(parentElement, node); }); } attachViewAfter(anchorNode: NgView, viewRootNodes: NgView[]) { - traceLog('NativeScriptRenderer.attachViewAfter: ' + anchorNode.nodeName + ' ' + anchorNode); + traceLog("NativeScriptRenderer.attachViewAfter: " + anchorNode.nodeName + " " + anchorNode); const parent = (anchorNode.parent || anchorNode.templateParent); const insertPosition = this.viewUtil.getChildIndex(parent, anchorNode); @@ -147,7 +148,7 @@ export class NativeScriptRenderer extends Renderer { } detachView(viewRootNodes: NgView[]) { - traceLog('NativeScriptRenderer.detachView'); + traceLog("NativeScriptRenderer.detachView"); for (let i = 0; i < viewRootNodes.length; i++) { let node = viewRootNodes[i]; this.viewUtil.removeChild(node.parent, node); @@ -157,16 +158,18 @@ export class NativeScriptRenderer extends Renderer { public destroyView(_hostElement: NgView, _viewAllNodes: NgView[]) { traceLog("NativeScriptRenderer.destroyView"); // Seems to be called on component dispose only (router outlet) - //TODO: handle this when we resolve routing and navigation. + // TODO: handle this when we resolve routing and navigation. } setElementProperty(renderElement: NgView, propertyName: string, propertyValue: any) { - traceLog("NativeScriptRenderer.setElementProperty " + renderElement + ': ' + propertyName + " = " + propertyValue); + traceLog("NativeScriptRenderer.setElementProperty " + renderElement + ": " + + propertyName + " = " + propertyValue); this.viewUtil.setProperty(renderElement, propertyName, propertyValue); } setElementAttribute(renderElement: NgView, attributeName: string, attributeValue: string) { - traceLog("NativeScriptRenderer.setElementAttribute " + renderElement + ': ' + attributeName + " = " + attributeValue); + traceLog("NativeScriptRenderer.setElementAttribute " + renderElement + ": " + + attributeName + " = " + attributeValue); return this.setElementProperty(renderElement, attributeName, attributeValue); } @@ -184,21 +187,17 @@ export class NativeScriptRenderer extends Renderer { this.viewUtil.setStyleProperty(renderElement, styleName, styleValue); } - /** - * Used only in debug mode to serialize property changes to comment nodes, - * such as