Skip to content

Commit 8fd48db

Browse files
committed
refactor(app): More lint-related refactoring
1 parent 3f7b2d0 commit 8fd48db

File tree

16 files changed

+84
-73
lines changed

16 files changed

+84
-73
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"zone.js": "^0.8.12"
4040
},
4141
"devDependencies": {
42-
"@ionic/app-scripts": "2.0.1",
42+
"@ionic/app-scripts": "2.0.2",
4343
"@ionic/cli-plugin-cordova": "1.4.1",
4444
"@ionic/cli-plugin-ionic-angular": "1.3.2",
4545
"typescript": "~2.3.4"

src/app/app.global.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,29 @@ import { Injectable } from '@angular/core';
33
export class AppState {
44
_state = {};
55

6-
// already return a clone of the current state
6+
// already return a clone of the current state
77
get state() {
8-
return this._state = this._clone(this._state);
8+
return this._state = this.clone(this._state);
99
}
10-
// never allow mutation
10+
11+
// never allow mutation
1112
set state(value) {
1213
throw new Error('do not mutate the `.state` directly');
1314
}
15+
1416
get(prop?: any) {
15-
// use our state getter for the clone
17+
// use our state getter for the clone
1618
const state = this.state;
1719
return state.hasOwnProperty(prop) ? state[prop] : state;
1820
}
21+
1922
set(prop: string, value: any) {
20-
// internally mutate our state
23+
// internally mutate our state
2124
return this._state[prop] = value;
2225
}
23-
_clone(object) {
24-
// simple object clone
26+
27+
private clone(object) {
28+
// simple object clone
2529
return JSON.parse(JSON.stringify(object));
2630
}
2731
}

src/app/app.imports.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ import { SwingModule } from 'angular2-swing';
3939
import { BrowserModule } from '@angular/platform-browser';
4040
import { HttpModule } from '@angular/http';
4141

42-
export const Modules = [
42+
export const MODULES = [
4343
SwingModule,
4444
BrowserModule,
4545
HttpModule,
4646
];
4747

48-
export const Pipes = [
48+
export const PIPES = [
4949
TemperaturePipe, MomentPipe, OrderByPipe, CapitalizePipe, ShortenStringPipe
5050
];
5151

52-
export const Providers = [
52+
export const PROVIDERS = [
5353
AlertService,
5454
ToastService,
5555
AppState,
@@ -67,15 +67,15 @@ export const Providers = [
6767
GoogleMaps,
6868
];
6969

70-
export const Components = [
70+
export const COMPONENTS = [
7171
FlashCardComponent,
7272
TimerProgress,
7373
Timer,
7474
ExpandableHeader,
7575
Autosize
7676
];
7777

78-
export const Directives = [
78+
export const DIRECTIVES = [
7979
SlidingDrawer,
8080
Timer,
8181
Autosize,

src/app/app.module.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ import { NgModule, ErrorHandler } from '@angular/core';
33
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
44
import { MyApp } from './app.component';
55

6-
import { Modules, Providers } from './app.imports';
6+
import { MODULES, PROVIDERS } from './app.imports';
77

88
@NgModule({
99
declarations: [
1010
// App Core
1111
MyApp,
1212
],
1313
imports: [
14-
Modules,
14+
MODULES,
1515
IonicModule.forRoot(MyApp),
1616
SharedModule,
1717
],
1818
bootstrap: [IonicApp],
1919
entryComponents: [
2020
MyApp,
2121
],
22-
providers: [Providers, { provide: ErrorHandler, useClass: IonicErrorHandler }]
22+
providers: [PROVIDERS, { provide: ErrorHandler, useClass: IonicErrorHandler }]
2323
})
2424
export class AppModule { }

src/app/shared.module.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import { Components, Directives, Pipes } from './app.imports';
1+
import { COMPONENTS, DIRECTIVES, PIPES } from './app.imports';
22
import { NgModule } from '@angular/core';
33
import { IonicModule } from 'ionic-angular';
44

55
@NgModule({
66
declarations: [
7-
Pipes,
8-
Directives,
9-
Components
7+
PIPES,
8+
DIRECTIVES,
9+
COMPONENTS
1010
],
1111
imports: [
1212
IonicModule,
1313
],
1414
exports: [
15-
Pipes,
16-
Components
15+
PIPES,
16+
COMPONENTS
1717
]
1818
})
1919

src/components/flash-card/flash-card.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ export class FlashCardComponent {
1010
@ViewChild('back') fcBack;
1111
toggled: boolean = false;
1212

13-
constructor(private flashCard: ElementRef) { }
14-
1513
ngAfterViewChecked() {
1614
const frontH = this.fcFront.nativeElement.querySelector('.fc-front').offsetHeight + 40;
1715
const backH = this.fcBack.nativeElement.querySelector('.fc-back').offsetHeight + 40;

src/pages/login/login-background-slider/login-background-slider.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export class LoginBackgroundSliderPage {
3030
}
3131

3232
openResetPassword() {
33+
console.log('Reset password clicked');
3334
}
3435

3536
doLogin() {

src/pages/login/login-background-video/login-background-video.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ export class LoginBackgroundVideoPage {
3030
}
3131

3232
goToSignup() {
33+
console.log('Signup clicked');
3334
}
3435

3536
goToLogin() {
37+
console.log('Login clicked');
3638
}
37-
3839
}

src/pages/login/login-instagram/login-instagram.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ export class LoginInstagramPage {
1616
public loadingCtrl: LoadingController,
1717
public alertCtrl: AlertController,
1818
public app: App
19-
) {
20-
21-
}
19+
) { }
2220

2321
login() {
2422
const loading = this.loadingCtrl.create({
@@ -65,23 +63,23 @@ export class LoginInstagramPage {
6563

6664
updateGradient() {
6765

68-
const c0_0 = this.colors[this.colorIndices[0]];
69-
const c0_1 = this.colors[this.colorIndices[1]];
70-
const c1_0 = this.colors[this.colorIndices[2]];
71-
const c1_1 = this.colors[this.colorIndices[3]];
66+
const c00 = this.colors[this.colorIndices[0]];
67+
const c01 = this.colors[this.colorIndices[1]];
68+
const c10 = this.colors[this.colorIndices[2]];
69+
const c11 = this.colors[this.colorIndices[3]];
7270

7371
const istep = 1 - this.step;
74-
const r1 = Math.round(istep * c0_0[0] + this.step * c0_1[0]);
75-
const g1 = Math.round(istep * c0_0[1] + this.step * c0_1[1]);
76-
const b1 = Math.round(istep * c0_0[2] + this.step * c0_1[2]);
72+
const r1 = Math.round(istep * c00[0] + this.step * c01[0]);
73+
const g1 = Math.round(istep * c00[1] + this.step * c01[1]);
74+
const b1 = Math.round(istep * c00[2] + this.step * c01[2]);
7775
const color1 = 'rgb(' + r1 + ',' + g1 + ',' + b1 + ')';
7876

79-
const r2 = Math.round(istep * c1_0[0] + this.step * c1_1[0]);
80-
const g2 = Math.round(istep * c1_0[1] + this.step * c1_1[1]);
81-
const b2 = Math.round(istep * c1_0[2] + this.step * c1_1[2]);
77+
const r2 = Math.round(istep * c10[0] + this.step * c11[0]);
78+
const g2 = Math.round(istep * c10[1] + this.step * c11[1]);
79+
const b2 = Math.round(istep * c10[2] + this.step * c11[2]);
8280
const color2 = 'rgb(' + r2 + ',' + g2 + ',' + b2 + ')';
8381

84-
this.gradient = '-webkit-gradient(linear, left top, right bottom, from(' + color1 + '), to(' + color2 + '))';
82+
this.gradient = `-webkit-gradient(linear, left top, right bottom, from(${color1}), to(${color2}))`;
8583
this.step += this.gradientSpeed;
8684
if (this.step >= 1) {
8785
this.step %= 1;
@@ -90,10 +88,16 @@ export class LoginInstagramPage {
9088

9189
// pick two new target color indices
9290
// do not pick the same as the current one
93-
this.colorIndices[1] = (this.colorIndices[1] + Math.floor(1 + Math.random() * (this.colors.length - 1))) % this.colors.length;
94-
this.colorIndices[3] = (this.colorIndices[3] + Math.floor(1 + Math.random() * (this.colors.length - 1))) % this.colors.length;
91+
this.colorIndices[1] =
92+
(this.colorIndices[1] + Math.floor(1 + Math.random() * (this.colors.length - 1)))
93+
% this.colors.length;
94+
95+
this.colorIndices[3] =
96+
(this.colorIndices[3] + Math.floor(1 + Math.random() * (this.colors.length - 1)))
97+
% this.colors.length;
9598

9699
}
100+
97101
setInterval(() => { this.updateGradient(); }, 40);
98102
}
99103
}

src/pages/login/login-slider/login-slider.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// import { FormBuilder, FormControl, Validator } from '@angular/forms';
2-
import { Component } from '@angular/core';
3-
import { ViewChild } from '@angular/core';
2+
import { Component, ViewChild } from '@angular/core';
43
import { AlertController, App, LoadingController, NavController, Slides, IonicPage } from 'ionic-angular';
54

65
@IonicPage()

src/pages/miscellaneous/charts/charts.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, ViewChild } from '@angular/core';
22
import { NavController, IonicPage } from 'ionic-angular';
3-
import Chart from 'chart.js';
3+
import chartJs from 'chart.js';
44

55
@IonicPage()
66
@Component({
@@ -30,17 +30,23 @@ export class ChartsPage {
3030

3131
constructor(public navCtrl: NavController) { }
3232

33-
ionViewDidLoad() {
34-
this.barChart = this.getBarChart();
35-
this.doughnutChart = this.getDoughnutChart();
36-
this.halfDoughnutChart = this.getHalfDoughnutChart();
37-
this.lineChart = this.getLineChart();
38-
this.radarChart = this.getRadarChart();
39-
40-
this.polarAreaChart = this.getPolarAreaChart();
41-
this.bubbleChart = this.getBubbleChart();
42-
this.mixedChart = this.getMixedChart();
43-
this.pieChart = this.getPieChart();
33+
ngAfterViewInit() {
34+
setTimeout(() => {
35+
this.barChart = this.getBarChart();
36+
this.doughnutChart = this.getDoughnutChart();
37+
this.halfDoughnutChart = this.getHalfDoughnutChart();
38+
}, 150);
39+
setTimeout(() => {
40+
this.lineChart = this.getLineChart();
41+
this.radarChart = this.getRadarChart();
42+
this.polarAreaChart = this.getPolarAreaChart();
43+
}, 250);
44+
setTimeout(() => {
45+
this.bubbleChart = this.getBubbleChart();
46+
this.mixedChart = this.getMixedChart();
47+
this.pieChart = this.getPieChart();
48+
}, 350);
49+
4450
}
4551

4652
updateData() {
@@ -52,7 +58,7 @@ export class ChartsPage {
5258
}
5359

5460
getChart(context, chartType, data, options?) {
55-
return new Chart(context, {
61+
return new chartJs(context, {
5662
data,
5763
options,
5864
type: chartType,

src/pages/slide/slide-carousel/slide-carousel.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ export class SlideCarouselPage {
119119
comments: [1, 4, 2, 3],
120120
};
121121

122-
123122
// Starting with an empty slider
124123
citiesSlides: any = [];
125124

src/pipes/orderby.pipe.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Pipe, PipeTransform } from '@angular/core';
44
export class OrderByPipe implements PipeTransform {
55
value: string[] = [];
66

7-
static _orderByComparator(a: any, b: any): number {
7+
static orderByComparator(a: any, b: any): number {
88

99
if (a === null || typeof a === 'undefined') { a = 0; }
1010
if (b === null || typeof b === 'undefined') { b = 0; }
@@ -64,8 +64,8 @@ export class OrderByPipe implements PipeTransform {
6464
}
6565

6666
return !desc
67-
? OrderByPipe._orderByComparator(aValue, bValue)
68-
: -OrderByPipe._orderByComparator(aValue, bValue);
67+
? OrderByPipe.orderByComparator(aValue, bValue)
68+
: -OrderByPipe.orderByComparator(aValue, bValue);
6969
});
7070
}
7171
} else {
@@ -92,8 +92,8 @@ export class OrderByPipe implements PipeTransform {
9292
}
9393

9494
const comparison = !desc
95-
? OrderByPipe._orderByComparator(aValue, bValue)
96-
: -OrderByPipe._orderByComparator(aValue, bValue);
95+
? OrderByPipe.orderByComparator(aValue, bValue)
96+
: -OrderByPipe.orderByComparator(aValue, bValue);
9797

9898
// Don't return 0 yet in case of needing to sort by next property
9999
if (comparison !== 0) { return comparison; }

src/pipes/shorten.pipe.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { Pipe } from '@angular/core';
44
name: 'shorten'
55
})
66
export class ShortenStringPipe {
7-
// Shortens the string to a given length.
8-
// Input: {{'This is a very long string' | shorten:18}}
9-
// Output: This is a very lon...
7+
// Shortens the string to a given length.
8+
// Input: {{'This is a very long string' | shorten:18}}
9+
// Output: This is a very lon...
1010
transform(value, maxWidth = 30, suffix = '...') {
1111
if (value && value.length > maxWidth) {
1212
value = value.substring(0, maxWidth) + suffix;

src/providers/util/backbutton.service.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,18 @@
2828
// }
2929

3030
// /**
31-
// * Toggle the left nav menu on back
31+
// * Toggle the left nav menu on back
3232
// * Also will display a toast message stating that the app will close on next back button click
3333
// * @param {boolean} doubleBackToExit
3434
// */
3535
// toggleMenuOnBack(doubleBackToExit = false) {
3636
// this._platform.registerBackButtonAction(() => {
37-
// // Open the menu
37+
// // Open the menu
3838
// this._menuCtrl.toggle();
3939

4040
// if (doubleBackToExit) {
41-
// //If its first time clicking back button, show toast that they need to click back button again
41+
// // If its first time clicking back button,
42+
// // show toast that they need to click back button again
4243
// if (!this._didBackAlready) {
4344
// this._didBackAlready = true;
4445
// this._presentToast("Press back button again to exit");
@@ -72,7 +73,6 @@
7273
// });
7374
// }
7475

75-
7676
// /**
7777
// * Present Content as a toast message
7878
// * @param {string} content
@@ -87,7 +87,6 @@
8787
// toast.present();
8888
// }
8989

90-
9190
// /* Use as follow in your page:
9291
// ionViewDidEnter() {
9392
// // Setup Back Button Behavior
@@ -143,5 +142,4 @@
143142

144143
// }
145144
// }
146-
147-
// }
145+
// }

tslint.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"no-increment-decrement": false,
1212
"no-param-reassign": false,
1313
"no-consecutive-blank-lines": true,
14-
"max-line-length": [ true, 110 ]
14+
"max-line-length": [ true, 110 ],
15+
"variable-name": [true, "allow-leading-underscore"]
1516
},
1617
"rulesDirectory": [
1718
"node_modules/tslint-eslint-rules/dist/rules"

0 commit comments

Comments
 (0)