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

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

05 Feb 2021 11:19PM UTC coverage: 77.151% (-6.1%) from 83.209%
#3048

push

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

quotesOnKeys bugfix

305 of 412 branches covered (74.03%)

Branch coverage included in aggregate %.

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

106 existing lines in 5 files now uncovered.

529 of 669 relevant lines covered (79.07%)

42.14 hits per line

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

66.67
/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✔
10
        if (this.objects[rjvId] === undefined) {
20✔
11
            this.objects[rjvId] = {};
7✔
12
        }
13
        if (this.objects[rjvId][name] === undefined) {
20✔
14
            this.objects[rjvId][name] = {};
10✔
15
        }
16
        this.objects[rjvId][name][key] = value;
20✔
17
    };
18

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

30
    handleAction = action => {
1✔
31
        const { rjvId, data, name } = action;
6✔
32
        switch (name) {
6!
33
            case 'RESET':
34
                this.emit('reset-' + rjvId);
3✔
35
                break;
3✔
36
            case 'VARIABLE_UPDATED':
37
                action.data.updated_src = this.updateSrc(rjvId, data);
1!
38
                this.set(rjvId, 'action', 'variable-update', {
1✔
39
                    ...data,
1✔
40
                    type: 'variable-edited'
1✔
41
                });
42
                this.emit('variable-update-' + rjvId);
43
                break;
1✔
44
            case 'VARIABLE_REMOVED':
1✔
45
                action.data.updated_src = this.updateSrc(rjvId, data);
1✔
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,
56
                    type: 'variable-added'
1✔
57
                });
1✔
58
                this.emit('variable-update-' + rjvId);
59
                break;
60
            case 'ADD_VARIABLE_KEY_REQUEST':
61
                this.set(rjvId, 'action', 'new-key-request', data);
1✔
62
                this.emit('add-key-request-' + rjvId);
1✔
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];
1✔
94
            }
95
        } else {
1✔
96
            //update copied variable at specified namespace
97
            if (name !== null) {
98
                walk[name] = new_value;
1✔
99
            } else {
100
                updated_src = new_value;
1✔
101
            }
102
        }
103

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

×
106
        return updated_src;
107
    };
108

1!
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') {
116
            result = { ...src };
1!
117
        }
1✔
118
        if (idx !== undefined) {
119
            result[idx] = this.deepCopy(src[idx], copy_namespace);
×
120
        }
121
        return result;
122
    };
123
}
1✔
124

125
const attributeStore = new ObjectAttributes();
1✔
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