diff --git a/ionic/components/app/app.ts b/ionic/components/app/app.ts index c2f41eac12..ec16214ada 100644 --- a/ionic/components/app/app.ts +++ b/ionic/components/app/app.ts @@ -19,7 +19,7 @@ export class IonicApp { private _scrollTime: number = 0; // Our component registry map - private components: any = {}; + private components: {[id: string] : any} = {}; constructor( private _config: Config, @@ -31,7 +31,7 @@ export class IonicApp { * Sets the document title. * @param {string} val Value to set the document title to. */ - setTitle(val) { + setTitle(val: string) { let self = this; if (val !== self._title) { self._title = val; @@ -56,7 +56,7 @@ export class IonicApp { * it will automatically enable the app again. It's basically a fallback incase * something goes wrong during a transition and the app wasn't re-enabled correctly. */ - setEnabled(isEnabled, duration=700) { + setEnabled(isEnabled: boolean, duration: number=700) { this._disTime = (isEnabled ? 0 : Date.now() + duration); if (duration > 32 || isEnabled) { @@ -70,7 +70,7 @@ export class IonicApp { * Boolean if the app is actively enabled or not. * @return {bool} */ - isEnabled() { + isEnabled(): boolean { return (this._disTime < Date.now()); } @@ -86,17 +86,17 @@ export class IonicApp { * Boolean if the app is actively scrolling or not. * @return {bool} */ - isScrolling() { + isScrolling(): boolean { return (this._scrollTime + 64 > Date.now()); } /** * @private * Register a known component with a key, for easy lookups later. - * @param {TODO} id The id to use to register the component - * @param {TODO} component The component to register + * @param {string} id The id to use to register the component + * @param {Object} component The component to register */ - register(id, component) { + register(id: string, component: any) { if (this.components[id] && this.components[id] !== component) { //console.error('Component id "' + id + '" already registered.'); } @@ -106,9 +106,9 @@ export class IonicApp { /** * @private * Unregister a known component with a key. - * @param {TODO} id The id to use to unregister + * @param {string} id The id to use to unregister */ - unregister(id) { + unregister(id: string) { delete this.components[id]; } @@ -116,11 +116,12 @@ export class IonicApp { * @private * Get a registered component with the given type (returns the first) * @param {Object} cls the type to search for - * @return the matching component, or undefined if none was found + * @return {Object} the matching component, or undefined if none was found */ - getRegisteredComponent(cls) { - for(let component of this.components) { - if(component instanceof cls) { + getRegisteredComponent(cls: any): any { + for (let key in this.components) { + const component = this.components[key]; + if (component instanceof cls) { return component; } } @@ -129,10 +130,10 @@ export class IonicApp { /** * @private * Get the component for the given key. - * @param {TODO} key TODO - * @return {TODO} TODO + * @param {string} id TODO + * @return {Object} TODO */ - getComponent(id) { + getComponent(id: string): any { return this.components[id]; } diff --git a/ionic/components/icon/icon.ts b/ionic/components/icon/icon.ts index 879ce4d204..758b81f0d0 100644 --- a/ionic/components/icon/icon.ts +++ b/ionic/components/icon/icon.ts @@ -80,11 +80,11 @@ export class Icon { } @Input() - get name() { + get name(): string { return this._name; } - set name(val) { + set name(val: string) { if (!(/^md-|^ios-|^logo-/.test(val))) { // this does not have one of the defaults // so lets auto add in the mode prefix for them @@ -115,11 +115,11 @@ export class Icon { } @Input() - get isActive() { + get isActive(): boolean { return (this._isActive === undefined || this._isActive === true || this._isActive === 'true'); } - set isActive(val) { + set isActive(val: boolean) { this._isActive = val; this.update(); } @@ -158,8 +158,9 @@ export class Icon { /** * @private + * @param {string} add class name */ - addClass(className) { + addClass(className: string) { this._renderer.setElementClass(this._elementRef, className, true); } diff --git a/ionic/components/label/label.ts b/ionic/components/label/label.ts index 928666bd8a..26a0acbc45 100644 --- a/ionic/components/label/label.ts +++ b/ionic/components/label/label.ts @@ -45,14 +45,15 @@ export class Label { } } - get text() { + get text(): string { return this._elementRef.nativeElement.textContent; } /** * @private + * @param {string} add class name */ - addClass(className) { + addClass(className: string) { this._renderer.setElementClass(this._elementRef, className, true); } diff --git a/ionic/components/label/test/basic/index.ts b/ionic/components/label/test/basic/index.ts new file mode 100644 index 0000000000..ac2d757460 --- /dev/null +++ b/ionic/components/label/test/basic/index.ts @@ -0,0 +1,10 @@ +import {App} from 'ionic/ionic'; + + +@App({ + templateUrl: 'main.html' +}) +class E2EApp { + constructor() { + } +} diff --git a/ionic/components/label/test/basic/main.html b/ionic/components/label/test/basic/main.html new file mode 100644 index 0000000000..bb59e2c46c --- /dev/null +++ b/ionic/components/label/test/basic/main.html @@ -0,0 +1,13 @@ + + + Icons + + + + + + Username + + + + diff --git a/ionic/components/list/list.ts b/ionic/components/list/list.ts index ef74537e58..cc8ace33d5 100644 --- a/ionic/components/list/list.ts +++ b/ionic/components/list/list.ts @@ -24,11 +24,11 @@ import {isDefined} from '../../util'; export class List extends Ion { private _enableSliding: boolean = false; private _virtualScrollingManager: ListVirtualScroll; - + ele: HTMLElement; - itemTemplate; + itemTemplate: any; slidingGesture: ItemSlidingGesture; - + @Input() items; @Input() virtual; @Input() content; @@ -72,7 +72,7 @@ export class List extends Ion { /** * @private */ - setItemTemplate(item) { + setItemTemplate(item: any) { this.itemTemplate = item; } @@ -92,7 +92,7 @@ export class List extends Ion { * ``` * @param {Boolean} shouldEnable whether the item-sliding should be enabled or not */ - enableSlidingItems(shouldEnable) { + enableSlidingItems(shouldEnable: boolean) { if (this._enableSliding !== shouldEnable) { this._enableSliding = shouldEnable; @@ -147,11 +147,11 @@ export class ListHeader { this._id = id; } - public get id() { + public get id(): string { return this._id; } - public set id(val) { + public set id(val: string) { this._id = val; this._renderer.setElementAttribute(this._elementRef, 'id', val); } diff --git a/ionic/components/option/option.ts b/ionic/components/option/option.ts index 14c59f3199..bf3ce9295e 100644 --- a/ionic/components/option/option.ts +++ b/ionic/components/option/option.ts @@ -9,9 +9,9 @@ import {Directive, ElementRef, Input} from 'angular2/core'; }) export class Option { private _checked: boolean = false; - + @Input() value: string; - + constructor(private _elementRef: ElementRef) { this._checked = false; } @@ -20,7 +20,7 @@ export class Option { get checked() { return this._checked; } - + set checked(val: any) { this._checked = (val === 'true' || val === true || val === ''); } diff --git a/ionic/components/show-hide-when/show-hide-when.ts b/ionic/components/show-hide-when/show-hide-when.ts index f213b3ba4f..2130b42704 100644 --- a/ionic/components/show-hide-when/show-hide-when.ts +++ b/ionic/components/show-hide-when/show-hide-when.ts @@ -39,7 +39,7 @@ export class DisplayWhen { } - orientation() { + orientation(): boolean { for (let i = 0; i < this.conditions.length; i++) { if (this.conditions[i] == 'portrait') { @@ -87,7 +87,7 @@ export class ShowWhen extends DisplayWhen { /** * @private */ - get hidden() { + get hidden(): boolean { return !this.isMatch; } @@ -124,7 +124,7 @@ export class HideWhen extends DisplayWhen { /** * @private */ - get hidden() { + get hidden(): boolean { return this.isMatch; } diff --git a/ionic/components/slides/slides.ts b/ionic/components/slides/slides.ts index e5c4956dc5..4888e74870 100644 --- a/ionic/components/slides/slides.ts +++ b/ionic/components/slides/slides.ts @@ -555,28 +555,28 @@ export class Slides extends Ion { /** * @private */ - getIndex() { + getIndex(): number { return this.slider.activeIndex; } /** * @private */ - getNumSlides() { + getNumSlides(): number { return this.slider.slides.length; } /** * @private */ - isAtEnd() { + isAtEnd(): boolean { return this.slider.isEnd; } /** * @private */ - isAtBeginning() { + isAtBeginning(): boolean { return this.slider.isBeginning; } @@ -597,9 +597,9 @@ export class Slides extends Ion { }) export class Slide { private ele: HTMLElement; - + @Input() zoom; - + constructor( elementRef: ElementRef, @Host() slides: Slides diff --git a/ionic/platform/platform.ts b/ionic/platform/platform.ts index ebcd9022f7..78e3662d88 100644 --- a/ionic/platform/platform.ts +++ b/ionic/platform/platform.ts @@ -1,6 +1,6 @@ import {getQuerystring, assign} from '../util/util'; import {ready, windowDimensions, flushDimensionCache} from '../util/dom'; - +import {Config} from '../config/config'; /** * @name Platform @@ -31,7 +31,7 @@ export class Platform { private _ua: string; private _bPlt: string; private _onResizes: Array=[]; - private _readyPromise: any; + private _readyPromise: Promise; private _readyResolve: any; private _engineReady: any; private _resizeTimer: any; @@ -65,7 +65,7 @@ export class Platform { * } * ``` */ - is(platformName) { + is(platformName: string): boolean { return (this._platforms.indexOf(platformName) > -1); } @@ -88,7 +88,7 @@ export class Platform { * } * ``` */ - platforms() { + platforms(): Array { // get the array of active platforms, which also knows the hierarchy, // with the last one the most important return this._platforms; @@ -112,7 +112,7 @@ export class Platform { * @returns {object} An object with various platform info * */ - versions(platformName) { + versions(platformName: string): any { if (arguments.length) { // get a specific platform's version return this._versions[platformName]; @@ -125,7 +125,7 @@ export class Platform { /** * @private */ - version() { + version(): any { for (let platformName in this._versions) { if (this._versions[platformName]) { return this._versions[platformName]; @@ -151,14 +151,14 @@ export class Platform { * ``` * @returns {promise} Returns a promsie when device ready has fired */ - ready() { + ready(): Promise { return this._readyPromise; } /** * @private */ - prepareReady(config) { + prepareReady(config: Config) { let self = this; function resolve() { @@ -185,7 +185,7 @@ export class Platform { * [W3C: Structural markup and right-to-left text in HTML](http://www.w3.org/International/questions/qa-html-dir) * @param {string} dir Examples: `rtl`, `ltr` */ - setDir(dir, updateDocument) { + setDir(dir: string, updateDocument: boolean) { this._dir = (dir || '').toLowerCase(); if (updateDocument !== false) { document.documentElement.setAttribute('dir', dir); @@ -199,7 +199,7 @@ export class Platform { * [W3C: Structural markup and right-to-left text in HTML](http://www.w3.org/International/questions/qa-html-dir) * @returns {string} */ - dir() { + dir(): string { return this._dir; } @@ -210,7 +210,7 @@ export class Platform { * [W3C: Structural markup and right-to-left text in HTML](http://www.w3.org/International/questions/qa-html-dir) * @returns {boolean} */ - isRTL() { + isRTL(): boolean { return (this._dir === 'rtl'); } @@ -223,7 +223,7 @@ export class Platform { * [W3C: Declaring language in HTML](http://www.w3.org/International/questions/qa-html-language-declarations) * @param {string} language Examples: `en-US`, `en-GB`, `ar`, `de`, `zh`, `es-MX` */ - setLang(language, updateDocument) { + setLang(language: string, updateDocument: boolean) { this._lang = language; if (updateDocument !== false) { document.documentElement.setAttribute('lang', language); @@ -237,7 +237,7 @@ export class Platform { * [W3C: Declaring language in HTML](http://www.w3.org/International/questions/qa-html-language-declarations) * @returns {string} */ - lang() { + lang(): string { return this._lang; } @@ -277,7 +277,7 @@ export class Platform { /** * @private */ - setUrl(url) { + setUrl(url: string) { this._url = url; this._qs = getQuerystring(url); } @@ -285,70 +285,70 @@ export class Platform { /** * @private */ - url(val) { + url(): string { return this._url; } /** * @private */ - query(key) { + query(key: string): string { return (this._qs || {})[key]; } /** * @private */ - setUserAgent(userAgent) { + setUserAgent(userAgent: string) { this._ua = userAgent; } /** * @private */ - userAgent(val) { + userAgent(): string { return this._ua || ''; } /** * @private */ - setNavigatorPlatform(navigatorPlatform) { + setNavigatorPlatform(navigatorPlatform: string) { this._bPlt = navigatorPlatform; } /** * @private */ - navigatorPlatform(val) { + navigatorPlatform(): string { return this._bPlt || ''; } /** * @private */ - width() { + width(): number { return windowDimensions().width; } /** * @private */ - height() { + height(): number { return windowDimensions().height; } /** * @private */ - isPortrait() { + isPortrait(): boolean { return this.width() < this.height(); } /** * @private */ - isLandscape() { + isLandscape(): boolean { return !this.isPortrait(); } @@ -375,7 +375,7 @@ export class Platform { /** * @private */ - onResize(cb) { + onResize(cb: Function) { this._onResizes.push(cb); } @@ -393,28 +393,28 @@ export class Platform { /** * @private */ - static registry() { + static registry(): any { return platformRegistry; } /** * @private */ - static get(platformName) { + static get(platformName: string): any { return platformRegistry[platformName] || {}; } /** * @private */ - static setDefault(platformName) { + static setDefault(platformName: string) { platformDefault = platformName; } /** * @private */ - testQuery(queryValue, queryTestValue) { + testQuery(queryValue: string, queryTestValue: string): boolean { let valueSplit = queryValue.toLowerCase().split(';'); return valueSplit.indexOf(queryTestValue) > -1; } @@ -422,7 +422,7 @@ export class Platform { /** * @private */ - testUserAgent(userAgentExpression) { + testUserAgent(userAgentExpression): boolean { let rgx = new RegExp(userAgentExpression, 'i'); return rgx.test(this._ua || ''); } @@ -430,7 +430,7 @@ export class Platform { /** * @private */ - testNavigatorPlatform(navigatorPlatformExpression) { + testNavigatorPlatform(navigatorPlatformExpression: string): boolean { let rgx = new RegExp(navigatorPlatformExpression, 'i'); return rgx.test(this._bPlt); } @@ -438,7 +438,7 @@ export class Platform { /** * @private */ - matchUserAgentVersion(userAgentExpression) { + matchUserAgentVersion(userAgentExpression: RegExp): any { if (this._ua && userAgentExpression) { let val = this._ua.match(userAgentExpression); if (val) { @@ -453,7 +453,7 @@ export class Platform { /** * @private */ - isPlatform(queryTestValue, userAgentExpression) { + isPlatform(queryTestValue: string, userAgentExpression: string): boolean { if (!userAgentExpression) { userAgentExpression = queryTestValue; } @@ -469,7 +469,7 @@ export class Platform { /** * @private */ - load(platformOverride?) { + load(platformOverride?: string) { let rootPlatformNode = null; let engineNode = null; let self = this; @@ -561,7 +561,7 @@ export class Platform { /** * @private */ - matchPlatform(platformName) { + matchPlatform(platformName: string): any { // build a PlatformNode and assign config data to it // use it's getRoot method to build up its hierarchy // depending on which platforms match @@ -581,7 +581,7 @@ export class Platform { } -function insertSuperset(platformNode) { +function insertSuperset(platformNode: PlatformNode) { let supersetPlaformName = platformNode.superset(); if (supersetPlaformName) { // add a platform in between two exist platforms @@ -602,8 +602,9 @@ class PlatformNode { public parent: PlatformNode; public child: PlatformNode; public isEngine: boolean; + public depth: number; - constructor(platformName) { + constructor(platformName: string) { this.c = Platform.get(platformName); this.isEngine = this.c.isEngine; } @@ -612,19 +613,19 @@ class PlatformNode { return this.c.name; } - settings() { + settings(): any { return this.c.settings || {}; } - superset() { + superset(): any { return this.c.superset; } - methods() { + methods(): any { return this.c.methods || {}; } - isMatch(p): boolean { + isMatch(p: Platform): boolean { if (p.platformOverride && !this.isEngine) { return (p.platformOverride === this.c.name); @@ -635,7 +636,7 @@ class PlatformNode { return this.c.isMatch(p); } - version(p) { + version(p: Platform): any { if (this.c.versionParser) { let v = this.c.versionParser(p); if (v) { @@ -650,7 +651,7 @@ class PlatformNode { } } - getRoot(p) { + getRoot(p: Platform): PlatformNode { if (this.isMatch(p)) { let parents = this.getSubsetParents(this.name()); @@ -677,7 +678,7 @@ class PlatformNode { return null; } - getSubsetParents(subsetPlatformName) { + getSubsetParents(subsetPlatformName: string): Array { let platformRegistry = Platform.registry(); let parentPlatformNames = []; diff --git a/ionic/platform/registry.ts b/ionic/platform/registry.ts index 4058c0b91d..27f3d7c8c8 100644 --- a/ionic/platform/registry.ts +++ b/ionic/platform/registry.ts @@ -50,7 +50,7 @@ Platform.register({ 'tablet' ], settings: { - activator: function(p) { + activator: function(p: Platform): string { // md mode defaults to use ripple activator // however, under-powered devices shouldn't use ripple // if this a linux device, and is using Android Chrome v36 (Android 5.0) @@ -75,10 +75,10 @@ Platform.register({ mode: 'md', scrollAssist: true, }, - isMatch(p) { + isMatch(p: Platform): boolean { return p.isPlatform('android', 'android|silk'); }, - versionParser(p) { + versionParser(p: Platform): any { return p.matchUserAgentVersion(/Android (\d+).(\d+)?/); } }); @@ -102,10 +102,10 @@ Platform.register({ swipeBackThreshold: 40, tapPolyfill: isIOSDevice, }, - isMatch(p) { + isMatch(p: Platform): boolean { return p.isPlatform('ios', 'iphone|ipad|ipod'); }, - versionParser(p) { + versionParser(p: Platform): any { return p.matchUserAgentVersion(/OS (\d+)_(\d+)?/); } }); @@ -117,8 +117,8 @@ Platform.register({ settings: { keyboardHeight: 500, }, - isMatch(p) { - return p.isPlatform('ipad'); + isMatch(p: Platform): boolean { + return p.isPlatform('ios', 'ipad'); } }); @@ -128,8 +128,8 @@ Platform.register({ subsets: [ 'phablet' ], - isMatch(p) { - return p.isPlatform('iphone'); + isMatch(p: Platform): boolean { + return p.isPlatform('ios', 'iphone'); } }); @@ -144,10 +144,10 @@ Platform.register({ settings: { mode: 'md', }, - isMatch(p) { + isMatch(p: Platform): boolean { return p.isPlatform('windowsphone', 'windows phone'); }, - versionParser(p) { + versionParser(p: Platform): any { return p.matchUserAgentVersion(/Windows Phone (\d+).(\d+)?/); } }); @@ -167,13 +167,13 @@ Platform.register({ }); } }, - isMatch() { + isMatch(): boolean { return !!(win.cordova || win.PhoneGap || win.phonegap); } }); -function isIOSDevice(p) { +function isIOSDevice(p: Platform) { // shortcut function to be reused internally // checks navigator.platform to see if it's an actual iOS device // this does not use the user-agent string because it is often spoofed diff --git a/ionic/platform/storage/local-storage.ts b/ionic/platform/storage/local-storage.ts index 7d7794d1e7..454537d45c 100644 --- a/ionic/platform/storage/local-storage.ts +++ b/ionic/platform/storage/local-storage.ts @@ -38,7 +38,7 @@ export class LocalStorage extends StorageEngine { * Get the value of a key in LocalStorage * @param {String} key the key you want to lookup in LocalStorage */ - get(key) { + get(key: string): Promise { return new Promise((resolve, reject) => { try { let value = window.localStorage.getItem(key); @@ -54,7 +54,7 @@ export class LocalStorage extends StorageEngine { * @param {String} key the key you want to save to LocalStorage * @param {Any} value the value of the key you're saving */ - set(key, value) { + set(key: string, value: string): Promise { return new Promise((resolve, reject) => { try { window.localStorage.setItem(key, value); @@ -69,7 +69,7 @@ export class LocalStorage extends StorageEngine { * Remove a key from LocalStorage * @param {String} key the key you want to remove from LocalStorage */ - remove(key) { + remove(key: string): Promise { return new Promise((resolve, reject) => { try { window.localStorage.removeItem(key); diff --git a/ionic/platform/storage/sql.ts b/ionic/platform/storage/sql.ts index b5a82c13e2..69b58a9027 100644 --- a/ionic/platform/storage/sql.ts +++ b/ionic/platform/storage/sql.ts @@ -68,7 +68,7 @@ export class SqlStorage extends StorageEngine { this._tryInit(); } - _getBackupLocation(dbFlag) { + _getBackupLocation(dbFlag: number) { switch(dbFlag) { case SqlStorage.BACKUP_LOCAL: return 2; @@ -100,7 +100,7 @@ export class SqlStorage extends StorageEngine { * @param {array} params the additional params to use for query placeholders * @return {Promise} that resolves or rejects with an object of the form { tx: Transaction, res: Result (or err)} */ - query(query, params=[]) { + query(query, params=[]): Promise { return new Promise((resolve, reject) => { try { this._db.transaction((tx) => { @@ -129,7 +129,7 @@ export class SqlStorage extends StorageEngine { * @param {string} key the key * @return {Promise} that resolves or rejects with an object of the form { tx: Transaction, res: Result (or err)} */ - get(key) { + get(key: string): Promise { return new Promise((resolve, reject) => { try { @@ -162,7 +162,7 @@ export class SqlStorage extends StorageEngine { * @param {string} value The value (as a string) * @return {Promise} that resolves or rejects with an object of the form { tx: Transaction, res: Result (or err)} */ - set(key, value) { + set(key: string, value: string): Promise { return new Promise((resolve, reject) => { try { this._db.transaction(tx => { @@ -189,7 +189,7 @@ export class SqlStorage extends StorageEngine { * @param {string} value The value (as a string) * @return {Promise} that resolves or rejects with an object of the form { tx: Transaction, res: Result (or err)} */ - remove(key) { + remove(key: string): Promise { return new Promise((resolve, reject) => { try { this._db.transaction(tx => { diff --git a/ionic/platform/storage/storage.ts b/ionic/platform/storage/storage.ts index b1530c2339..dfd447f14c 100644 --- a/ionic/platform/storage/storage.ts +++ b/ionic/platform/storage/storage.ts @@ -13,13 +13,13 @@ export class Storage { private _strategy: any; - constructor(strategyCls: any, options) { + constructor(strategyCls: IStorageEngine, options: any) { this._strategy = new strategyCls(options); } - get(key) { + get(key: string): any { return this._strategy.get(key); } - getJson(key) { + getJson(key: string): any { try { return JSON.parse(this._strategy.get(key)); } catch(e) { @@ -27,21 +27,28 @@ export class Storage { return null; } } - set(key, value) { + set(key: string, value: any) { return this._strategy.set(key, value); } - remove(key) { + remove(key: string) { return this._strategy.remove(key); } - query(query, params) { + query(query: string, params: any) { return this._strategy.query(query, params); } } +export interface IStorageEngine { + new(options: any): StorageEngine; +} + /** * @private */ export class StorageEngine { + constructor(options={}) { + throw Error("constructor(options={}) not implemented for this storage engine"); + } get(key, value) { throw Error("get() not implemented for this storage engine"); }