summaryrefslogtreecommitdiffstats
path: root/codon.mjs
blob: c5f8328999568d6bc8688b056e841a0ad715a8a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import AminoAcid from './amino-acid.mjs'
import Nucleotide from './nucleotide.mjs'

class Codon {
    constructor(n1, n2, n3) {
        this.bases = [n1, n2, n3]

        const nucleotideList = document.createElement('ol')
        this.bases = [n1, n2, n3].map(base => {
            const n = new Nucleotide(base)
            n.onClick = this._boundNucleotideClickedHandler
            nucleotideList.appendChild(n.elt)
            return n
        })
        this.elt.appendChild(nucleotideList)

        this.aminoAcid = new AminoAcid(n1, n2, n3)
    }

    get elt() {
        if (this._elt === undefined) {
            this._elt = document.createElement('li')
            this._elt.classList.add('codon')
        }
        return this._elt
    }

    get value() {
        return this.bases.map(b => b.value).join('')
    }

    get aminoAcid() {
        return this._aminoAcid
    }

    set aminoAcid(value) {
        this._aminoAcid = value
        const oldElt = this.elt.querySelector('.amino-acid')
        if (oldElt) {
            this.elt.removeChild(oldElt)
        }
        this.elt.appendChild(value.elt)
    }

    lock() {
        this.bases.forEach(n => n.lock())
        this.aminoAcid.lock()
    }

    unlock() {
        this.bases.forEach(n => n.unlock())
        this.aminoAcid.unlock()
    }
}

export default Codon