Passed
Pull Request — master (#57)
by Michael
03:00
created

script/nodeviews/AbstractNodeView.js   A

Complexity

Total Complexity 6
Complexity/F 1.5

Size

Lines of Code 48
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
eloc 17
nc 1
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 6
mnd 1
bc 5
fnc 4
bpm 1.25
cpm 1.5
noi 1

3 Functions

Rating   Name   Duplication   Size   Complexity  
A AbstractNodeView.js ➔ constructor 0 7 1
A AbstractNodeView.js ➔ renderNode 0 4 1
A AbstractNodeView.js ➔ unsetPrefixAttributes 0 9 1
1
class AbstractNodeView {
2
    /**
3
     *
4
     * @param {Node} node
5
     * @param {EditorView} view
6
     * @param {function} getPos
7
     */
8
    constructor(node, view, getPos) {
9
        this.node = node;
10
        this.outerView = view;
11
        this.getPos = getPos;
12
13
        this.renderNode(node.attrs);
14
    }
15
16
    /**
17
     * Render the node into this.dom
18
     *
19
     * This method must be overwritten by the subclasses!
20
     *
21
     * @param {object} attrs the attributes for the node
22
     */
23
    renderNode(attrs) {
24
        console.log(this.node, attrs);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
25
        throw Error('renderNode must be implemented by child class!');
26
    }
27
28
    /**
29
     * Helper method to remove all keys with a given prefix from an object
30
     *
31
     * @param {string} prefix
32
     * @param {object} attributes
33
     *
34
     * @return {object} a shallow copy of the initial object with the respective keys removed
35
     */
36
    static unsetPrefixAttributes(prefix, attributes) {
37
        const cleanedAttributes = {};
38
        Object.keys(attributes).forEach((attr) => {
39
            if (attr.substr(0, prefix.length) !== prefix) {
40
                cleanedAttributes[attr] = attributes[attr];
41
            }
42
        });
43
        return cleanedAttributes;
44
    }
45
}
46
47
export default AbstractNodeView;
48
window.AbstractNodeView = AbstractNodeView;
49