Issues (71)

js/lib/API/storage.js (6 issues)

1
/* global browser, chrome */
2
3
if (typeof API === "undefined") {
0 ignored issues
show
The variable API seems to be never initialized.
Loading history...
4
    var API = {};
5
}
6
7
API.Storage = function() {
0 ignored issues
show
The variable API does not seem to be initialized in case typeof API === "undefined" on line 3 is false. Are you sure this can never be the case?
Loading history...
8
    
9
    var localStorage = API.api.storage.local;
0 ignored issues
show
The variable API does not seem to be initialized in case typeof API === "undefined" on line 3 is false. Are you sure this can never be the case?
Loading history...
10
11
    return {
12
        /**
13
         * Retrieves an item from the local storage
14
         * @param string|array key The key or an array of keys to retrieve
0 ignored issues
show
The parameter string|array does not exist. Did you maybe forget to remove this comment?
Loading history...
15
         * @returns angular_promise
16
         */
17
        get: function(key) {
18
            return new C_Promise(function(){
19
                if (API.promise) {
0 ignored issues
show
The variable API does not seem to be initialized in case typeof API === "undefined" on line 3 is false. Are you sure this can never be the case?
Loading history...
20
                    localStorage.get(key).then((function(item){
21
                        /* jshint ignore:start */
22
                        if (typeof key === "[object Array]") {
23
                            this.call_then(item);
24
                        }
25
26
                        else {
27
                            if (item[key] === undefined) {
28
                                this.call_error("Data not found");
29
                            }
30
                            else {
31
                                this.call_then(item[key]);
32
                            }
33
                        }
34
                        /* jshint ignore:end */
35
                    }).bind(this), (function(error){
36
                        this.call_error(error);
37
                    }).bind(this));
38
                }
39
                else{
40
                    localStorage.get(key, (function(item){
41
                        /* jshint ignore:start */
42
                        if (typeof key === "[object Array]") {
43
                            this.call_then(item);
44
                        }
45
46
                        else {
47
                            if (item[key] === undefined) {
48
                                this.call_error("Data not found");
49
                            }
50
                            else {
51
                                this.call_then(item[key]);
52
                            }
53
                        }
54
                        /* jshint ignore:end */
55
                    }).bind(this));
56
                }
57
            });
58
        },
59
        
60
        set: function(key, value) {
61
            var o = {};
62
            o[key] = value;
63
            
64
            if (API.promise) {
0 ignored issues
show
The variable API does not seem to be initialized in case typeof API === "undefined" on line 3 is false. Are you sure this can never be the case?
Loading history...
65
                return localStorage.set(o);
66
            }
67
            else {
68
                return new C_Promise(function() {
69
                    localStorage.set(o, (function(){
70
                        this.call_then();
71
                    }).bind(this));
72
                });
73
            }
74
        }
75
        
76
    };
77
};