• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mac-s-g / react-json-view / #3045

05 Feb 2021 11:19PM UTC coverage: 2.313% (-80.9%) from 83.209%
#3045

push

web-flow
Merge pull request #328 from mac-s-g/bump-minor

quotesOnKeys bugfix

0 of 412 branches covered (0.0%)

Branch coverage included in aggregate %.

0 of 2 new or added lines in 1 file covered. (0.0%)

593 existing lines in 29 files now uncovered.

25 of 669 relevant lines covered (3.74%)

0.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

7.62
/src/js/stores/ObjectAttributes.js
1
import { EventEmitter } from 'events';
2
import dispatcher from './../helpers/dispatcher';
3
import { toType } from './../helpers/util';
4

5
//store persistent display attributes for objects and arrays
6
class ObjectAttributes extends EventEmitter {
7
    objects = {};
1✔
8

9
    set = (rjvId, name, key, value) => {
1✔
UNCOV
10
        if (this.objects[rjvId] === undefined) {
×
UNCOV
11
            this.objects[rjvId] = {};
×
12
        }
UNCOV
13
        if (this.objects[rjvId][name] === undefined) {
×
UNCOV
14
            this.objects[rjvId][name] = {};
×
15
        }
UNCOV
16
        this.objects[rjvId][name][key] = value;
×
17
    };
18

19
    get = (rjvId, name, key, default_value) => {
1✔
UNCOV
20
        if (
×
21
            this.objects[rjvId] === undefined ||
×
22
            this.objects[rjvId][name] === undefined ||
23
            this.objects[rjvId][name][key] == undefined
24
        ) {
UNCOV
25
            return default_value;
×
26
        }
UNCOV
27
        return this.objects[rjvId][name][key];
×
28
    };
29

30
    handleAction = action => {
1✔
UNCOV
31
        const { rjvId, data, name } = action;
×
UNCOV
32
        switch (name) {
×
33
            case 'RESET':
UNCOV
34
                this.emit('reset-' + rjvId);
×
UNCOV
35
                break;
×
36
            case 'VARIABLE_UPDATED':
UNCOV
37
                action.data.updated_src = this.updateSrc(rjvId, data);
×
UNCOV
38
                this.set(rjvId, 'action', 'variable-update', {
×
UNCOV
39
                    ...data,
×
UNCOV
40
                    type: 'variable-edited'
×
41
                });
42
                this.emit('variable-update-' + rjvId);
UNCOV
43
                break;
×
UNCOV
44
            case 'VARIABLE_REMOVED':
×
45
                action.data.updated_src = this.updateSrc(rjvId, data);
×
46
                this.set(rjvId, 'action', 'variable-update', {
47
                    ...data,
UNCOV
48
                    type: 'variable-removed'
×
UNCOV
49
                });
×
50
                this.emit('variable-update-' + rjvId);
51
                break;
UNCOV
52
            case 'VARIABLE_ADDED':
×
53
                action.data.updated_src = this.updateSrc(rjvId, data);
×
54
                this.set(rjvId, 'action', 'variable-update', {
55
                    ...data,
UNCOV
56
                    type: 'variable-added'
×
UNCOV
57
                });
×
58
                this.emit('variable-update-' + rjvId);
59
                break;
60
            case 'ADD_VARIABLE_KEY_REQUEST':
61
                this.set(rjvId, 'action', 'new-key-request', data);
×
62
                this.emit('add-key-request-' + rjvId);
×
63
                break;
UNCOV
64
        }
×
UNCOV
65
    };
×
66

67
    updateSrc = (rjvId, request) => {
68
        let {
UNCOV
69
            name,
×
UNCOV
70
            namespace,
×
71
            new_value,
UNCOV
72
            existing_value,
×
UNCOV
73
            variable_removed
×
74
        } = request;
75

76
        namespace.shift();
UNCOV
77

×
UNCOV
78
        //deepy copy src
×
79
        let src = this.get(rjvId, 'global', 'src');
UNCOV
80
        //deep copy of src variable
×
UNCOV
81
        let updated_src = this.deepCopy(src, [...namespace]);
×
UNCOV
82

×
83
        //point at current index
84
        let walk = updated_src;
85
        for (const idx of namespace) {
86
            walk = walk[idx];
1✔
87
        }
88

89
        if (variable_removed) {
90
            if (toType(walk) == 'array') {
91
                walk.splice(name, 1);
92
            } else {
93
                delete walk[name];
×
94
            }
UNCOV
95
        } else {
×
96
            //update copied variable at specified namespace
97
            if (name !== null) {
UNCOV
98
                walk[name] = new_value;
×
99
            } else {
100
                updated_src = new_value;
×
101
            }
102
        }
UNCOV
103

×
UNCOV
104
        this.set(rjvId, 'global', 'src', updated_src);
×
UNCOV
105

×
106
        return updated_src;
107
    };
UNCOV
108

×
UNCOV
109
    deepCopy = (src, copy_namespace) => {
×
UNCOV
110
        const type = toType(src);
×
111
        let result;
UNCOV
112
        let idx = copy_namespace.shift();
×
113
        if (type == 'array') {
114
            result = [...src];
115
        } else if (type == 'object') {
UNCOV
116
            result = { ...src };
×
UNCOV
117
        }
×
118
        if (idx !== undefined) {
119
            result[idx] = this.deepCopy(src[idx], copy_namespace);
×
120
        }
121
        return result;
122
    };
UNCOV
123
}
×
124

UNCOV
125
const attributeStore = new ObjectAttributes();
×
126
dispatcher.register(attributeStore.handleAction.bind(attributeStore));
127
export default attributeStore;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc