summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-core/src/models/SummaryArticle.js
blob: 3651c8a7ff9860c8b472bb0e615b8f27857e8201 (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
const { Record, List } = require('immutable');

const DEFAULTS = {
    title:    '',
    depth:    0,
    path:     '',
    url:      '',
    ref:      '',
    level:    '',
    articles: List()
};

class SummaryArticle extends Record(DEFAULTS) {
    constructor(article) {
        super({
            ...article,
            articles: (new List(article.articles))
                .map(art => new SummaryArticle(art))
        });
    }

    /**
     * Return true if article is an instance of SummaryArticle
     * @param {Mixed} article
     * @return {Boolean}
     */
    static is(article) {
        return (article instanceof SummaryArticle);
    }
}

module.exports = SummaryArticle;