Skip to content

Commit 787fb55

Browse files
committed
Typo fixes
1 parent 30b137e commit 787fb55

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

src/cache.service.ts

+22-20
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import {Observable, Subject} from 'rxjs/Rx';
44
import {Request, Response, ResponseOptions} from '@angular/http';
55

66
const MESSAGES = {
7-
0: "Cache initialization error: ",
8-
1: "Cache is not enabled.",
9-
2: "Cache entry already expired: ",
10-
3: "No such key: ",
11-
4: "No enteries were deleted, because browser is offline."
12-
}
7+
0: 'Cache initialization error: ',
8+
1: 'Cache is not enabled.',
9+
2: 'Cache entry already expired: ',
10+
3: 'No such key: ',
11+
4: 'No enteries were deleted, because browser is offline.'
12+
};
1313

1414
@Injectable()
1515
export class CacheService {
16-
private ttl: number = 60 * 60; //one hour
16+
private ttl: number = 60 * 60; // one hour
1717
private tableName: string = 'cache';
1818
private cacheKeys: string[] = ['key unique', 'value', 'expire INTEGER', 'type', 'groupKey'];
1919
private storage: SqlStorage;
@@ -123,12 +123,14 @@ export class CacheService {
123123
let expire = new Date().getTime() + (ttl * 1000);
124124
let type = CacheService.isRequest(data) ? 'request' : typeof data;
125125
let value = JSON.stringify(data);
126-
const valuesMap = { key, value, expire, type, groupKey }
127-
const values = Object.keys(valuesMap).map(key => valuesMap[key])
126+
const valuesMap = { key, value, expire, type, groupKey };
127+
const values = Object.keys(valuesMap).map(key => `'${valuesMap[key]}'`);
128+
129+
let query = `INSERT OR REPLACE INTO ${this.tableName} (${Object.keys(valuesMap).join(', ')}) VALUES (${values.join(', ')})`;
128130

129-
let query = `INSERT OR REPLACE INTO ${this.tableName} (${Object.keys(valuesMap).join(', ')}) VALUES (${Object.keys(valuesMap).fill('?').join(', ')})`;
131+
console.log(query);
130132

131-
return this.storage.query(query, values).then(() => data);
133+
return this.storage.query(query).then(() => data);
132134
}
133135

134136
/**
@@ -175,8 +177,8 @@ export class CacheService {
175177
}
176178

177179
return this.getRawItem(key).then(data => {
178-
if (data.expire < new Date().getTime()){
179-
if(this.invalidateOffline) {
180+
if (data.expire < new Date().getTime()) {
181+
if (this.invalidateOffline) {
180182
return Promise.reject(MESSAGES[2] + key);
181183
} else if (this.isOnline()) {
182184
return Promise.reject(MESSAGES[2] + key);
@@ -236,31 +238,31 @@ export class CacheService {
236238
* @param {number} [ttl] - TTL in seconds
237239
* @return {Observable<any>} - data from cache or origin observable
238240
*/
239-
public loadFromDelayedObservable(key: string, observable: any, groupKey?: string, ttl: number = this.ttl, delayType: string = "expired"): Observable<any> {
241+
public loadFromDelayedObservable(key: string, observable: any, groupKey?: string, ttl: number = this.ttl, delayType: string = 'expired'): Observable<any> {
240242
if (!this.enableCache) return observable;
241243

242244
let observableSubject = new Subject();
243245
observable = observable.share();
244246

245247
let subscribeOrigin = () => {
246248
observable.subscribe(res => {
247-
this.saveItem(key, res, groupKey, ttl)
249+
this.saveItem(key, res, groupKey, ttl);
248250
observableSubject.next(res);
249251
}, null, () => {
250252
observableSubject.complete();
251253
});
252-
}
254+
};
253255

254256
this.getItem(key).then((data) => {
255257
observableSubject.next(data);
256-
if(delayType == 'all'){
258+
if (delayType === 'all') {
257259
subscribeOrigin();
258260
}
259261
}, (e) => {
260262
this.getRawItem(key).then(res => {
261263
observableSubject.next(CacheService.decodeRawData(res));
262264
}).then(() => {
263-
subscribeOrigin()
265+
subscribeOrigin();
264266
}).catch(() => subscribeOrigin());
265267
});
266268

@@ -289,7 +291,7 @@ export class CacheService {
289291
return Promise.reject(MESSAGES[2]);
290292
}
291293

292-
if(!this.isOnline() && !ignoreOnlineStatus) {
294+
if (!this.isOnline() && !ignoreOnlineStatus) {
293295
return Promise.reject(MESSAGES[4]);
294296
}
295297

@@ -316,7 +318,7 @@ export class CacheService {
316318
* @return {boolean} - data from cache
317319
*/
318320
public static isRequest(data: any): boolean {
319-
if (data instanceof Request || (typeof data == 'object' && data.hasOwnProperty('_body') && data.hasOwnProperty('status') &&
321+
if (data instanceof Request || (typeof data === 'object' && data.hasOwnProperty('_body') && data.hasOwnProperty('status') &&
320322
data.hasOwnProperty('statusText') && data.hasOwnProperty('type') && data.hasOwnProperty('headers')
321323
&& data.hasOwnProperty('url'))) {
322324
return true;

0 commit comments

Comments
 (0)