Skip to content

Commit 4767136

Browse files
sbbowersmarcj
authored andcommitted
Added linter and fixed all TS style issues (#38)
* Added linter and fixed all TS style issues * 0.4.0
1 parent 93e798c commit 4767136

File tree

3 files changed

+50
-47
lines changed

3 files changed

+50
-47
lines changed

LocalStorageEmitter.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import {Injectable, OnDestroy} from '@angular/core';
2-
import {NgZone} from '@angular/core';
1+
import {Injectable, OnDestroy} from "@angular/core";
2+
import {NgZone} from "@angular/core";
33

44
export class LocalStorageEmitter {
55

6-
protected static subscribed:any = [];
7-
protected static ngZones:NgZone[] = [];
6+
protected static subscribed: any = [];
7+
protected static ngZones: NgZone[] = [];
88

9-
public static register(ngZone:NgZone) {
10-
let index:number = LocalStorageEmitter.ngZones.indexOf(ngZone);
9+
public static register(ngZone: NgZone) {
10+
let index: number = LocalStorageEmitter.ngZones.indexOf(ngZone);
1111
if (index === -1) {
1212
index = LocalStorageEmitter.ngZones.push(ngZone) - 1;
1313
}
@@ -18,14 +18,14 @@ export class LocalStorageEmitter {
1818
});
1919
}
2020

21-
protected static subscribers:any = [];
21+
protected static subscribers: any = [];
2222

23-
public static subscribe(callback:Function) {
23+
public static subscribe(callback: Function) {
2424
LocalStorageEmitter.subscribers.push(callback);
2525
}
2626

27-
public static unregister(ngZone:NgZone) {
28-
let index:number = LocalStorageEmitter.ngZones.indexOf(ngZone);
27+
public static unregister(ngZone: NgZone) {
28+
let index: number = LocalStorageEmitter.ngZones.indexOf(ngZone);
2929
if (index >= 0) {
3030
LocalStorageEmitter.subscribed[index].unsubscribe();
3131
}
@@ -34,7 +34,7 @@ export class LocalStorageEmitter {
3434

3535
@Injectable()
3636
export class LocalStorageService implements OnDestroy {
37-
constructor(private ngZone:NgZone) {
37+
constructor(private ngZone: NgZone) {
3838
LocalStorageEmitter.register(this.ngZone);
3939
}
4040

@@ -44,10 +44,10 @@ export class LocalStorageService implements OnDestroy {
4444
}
4545

4646
import {Type} from "@angular/core/src/facade/lang";
47-
import {provide} from '@angular/core/src/di';
48-
import {ComponentRef} from '@angular/core';
47+
import {provide} from "@angular/core/src/di";
48+
import {ComponentRef} from "@angular/core";
4949

50-
export function LocalStorageSubscriber(appPromise:Promise<ComponentRef<any>>) {
50+
export function LocalStorageSubscriber(appPromise: Promise<ComponentRef<any>>) {
5151
appPromise.then((bla) => {
5252
bla.injector.get(<Type>LocalStorageService);
5353
});

WebStorage.ts

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,92 @@
1-
import {LocalStorageEmitter} from './LocalStorageEmitter';
1+
import {LocalStorageEmitter} from "./LocalStorageEmitter";
22

3-
interface IWebStorage{
4-
getItem:(key:string) => string;
5-
setItem:(key:string, value: string) => void;
3+
interface IWebStorage {
4+
getItem: (key: string) => string;
5+
setItem: (key: string, value: string) => void;
66
}
77

8-
export function LocalStorage(storageKey?: string){
8+
export function LocalStorage(storageKey?: string) {
99
return WebStorage(storageKey, localStorage);
1010
}
1111

12-
export function SessionStorage(storageKey?: string){
12+
export function SessionStorage(storageKey?: string) {
1313
return WebStorage(storageKey, sessionStorage);
1414
}
1515

16-
function WebStorage(storageKey:string, webStorage: IWebStorage) {
17-
return (target:Object, decoratedPropertyName?:string):void => {
16+
function WebStorage(storageKey: string, webStorage: IWebStorage) {
17+
return (target: Object, decoratedPropertyName?: string): void => {
1818
if (!webStorage) {
1919
return;
2020
}
2121

2222
if (!storageKey) {
23-
storageKey = '' + '/' + decoratedPropertyName;
23+
storageKey = "" + "/" + decoratedPropertyName;
2424
}
2525

26-
Object.defineProperty(target, '_' + decoratedPropertyName + '_mapped', {
26+
Object.defineProperty(target, "_" + decoratedPropertyName + "_mapped", {
2727
enumerable: false,
2828
configurable: true,
2929
writable: true,
3030
value: false
3131
});
3232

33-
var instances:any = [];
34-
var values = {};
33+
let instances: any = [];
34+
let values = {};
3535

36-
var storageValue = webStorage.getItem(storageKey) || null;
37-
var storageValueJSON = storageValue;
38-
if ('string' === typeof storageValue) {
36+
let storageValue = webStorage.getItem(storageKey) || null;
37+
let storageValueJSON = storageValue;
38+
if ("string" === typeof storageValue) {
3939
try {
4040
storageValue = JSON.parse(storageValue);
41-
} catch(e) {
41+
} catch (e) {
4242
storageValue = null;
43-
storageValueJSON = 'null';
43+
storageValueJSON = "null";
4444
}
4545
}
46-
var oldJSONValues = {};
46+
let oldJSONValues = {};
4747

4848
Object.defineProperty(target, decoratedPropertyName, {
4949
get: function () {
50-
if (false === this['_' + decoratedPropertyName + '_mapped']) {
51-
this['_' + decoratedPropertyName + '_mapped'] = instances.length;
50+
if (false === this["_" + decoratedPropertyName + "_mapped"]) {
51+
this["_" + decoratedPropertyName + "_mapped"] = instances.length;
5252

53-
//first registration triggers a setting to localStorage value
53+
// first registration triggers a setting to localStorage value
5454
values[instances.length] = storageValue;
5555
oldJSONValues[instances.length] = storageValueJSON;
5656

5757
instances.push(this);
5858
}
59-
return values[this['_' + decoratedPropertyName + '_mapped']];
59+
return values[this["_" + decoratedPropertyName + "_mapped"]];
6060
},
6161
set: function (newValue) {
62-
if (false === this['_' + decoratedPropertyName + '_mapped']) {
63-
this['_' + decoratedPropertyName + '_mapped'] = instances.length;
62+
if (false === this["_" + decoratedPropertyName + "_mapped"]) {
63+
this["_" + decoratedPropertyName + "_mapped"] = instances.length;
6464

65-
//first registration triggers a setting to localStorage value
65+
// first registration triggers a setting to localStorage value
6666
values[instances.length] = storageValue;
6767
oldJSONValues[instances.length] = storageValueJSON;
6868

6969
instances.push(this);
70-
//first 'set' call is ignored if we have already a value from the localStorage
70+
// first "set" call is ignored if we have already a value from the localStorage
7171
if (storageValue) {
7272
return;
7373
}
7474
}
75-
values[this['_' + decoratedPropertyName + '_mapped']] = newValue;
75+
values[this["_" + decoratedPropertyName + "_mapped"]] = newValue;
7676
},
7777
enumerable: true,
7878
configurable: true
7979
});
8080

8181
LocalStorageEmitter.subscribe(() => {
8282
for (let instance of instances) {
83-
var currentValue = JSON.stringify(instance[decoratedPropertyName]);
84-
var oldJSONValue = oldJSONValues[instance['_' + decoratedPropertyName + '_mapped']];
83+
let currentValue = JSON.stringify(instance[decoratedPropertyName]);
84+
let oldJSONValue = oldJSONValues[instance["_" + decoratedPropertyName + "_mapped"]];
8585
if (currentValue !== oldJSONValue) {
86-
oldJSONValues[instance['_' + decoratedPropertyName + '_mapped']] = currentValue;
86+
oldJSONValues[instance["_" + decoratedPropertyName + "_mapped"]] = currentValue;
8787
webStorage.setItem(storageKey, currentValue);
8888
}
8989
}
9090
});
91-
}
91+
};
9292
}

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{
22
"name": "angular2-localstorage",
3-
"version": "0.3.0",
3+
"version": "0.4.0",
44
"description": "Angular2 decorator to save and restore class properties automatically from LocalStorage.",
55
"main": "index.js",
66
"scripts": {
7-
"postinstall": "typings install",
7+
"lint": "tslint ./*.ts -t verbose",
8+
"tsc": "tsc",
9+
"postinstall": "typings install",
810
"test": "echo \"Error: no test specified\" && exit 1"
911
},
1012
"repository": {
@@ -26,6 +28,7 @@
2628
"es6-shim": "^0.35.0",
2729
"reflect-metadata": "0.1.3",
2830
"rxjs": "5.0.0-beta.6",
31+
"tslint": "^3.7.4",
2932
"typings": "^0.8.1",
3033
"zone.js": "0.6.12"
3134
}

0 commit comments

Comments
 (0)