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

const DEFAULTS = {
    currentUser: null
};

/**
 * State for the API, it stores informations about the logged in user, etc.
 * @type {Record}
 */
class StateApi extends Record(DEFAULTS) {
    static create(state) {
        return state instanceof StateApi ?
            state : new StateApi(state);
    }

    /**
     * Check if reader is an user is loggedin.
     * @return {Boolean}
     */
    get isLoggedIn() {
        return Boolean(this.currentUser);
    }
}

module.exports = StateApi;