all files / src/message/ message.js

100% Statements 5/5
100% Branches 5/5
100% Functions 4/4
100% Lines 5/5
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                      10×       10×               17×               15×                          
/**
 * Class represents Message
 */
class Message {
 
    /**
     * create new action
     * @param {string} action
     * @param {object|null} data
     */
    constructor(action, data = null) {
        this.action = (action && typeof action === 'string')
            ? action
            : null;
 
        this.data = data;
    }
 
    /**
     * get action message key
     * @return {string}
     */
    getAction() {
        return this.action;
    }
 
    /**
     * get message data
     * @return {Object|null}
     */
    getData() {
        return this.data;
    }
 
    /**
     * checks if message contains data
     * @return {boolean}
     */
    hasData() {
        return (this.data !== null);
    }
}
 
export {
    Message,
};