summaryrefslogtreecommitdiffstats
path: root/web/react/stores/modal_store.jsx
blob: 809f83a596af07575d9fd44e59778d1db53a657c (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
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

const AppDispatcher = require('../dispatcher/app_dispatcher.jsx');
const EventEmitter = require('events').EventEmitter;

const Constants = require('../utils/constants.jsx');
const ActionTypes = Constants.ActionTypes;

class ModalStoreClass extends EventEmitter {
    constructor() {
        super();

        this.addModalListener = this.addModalListener.bind(this);
        this.removeModalListener = this.removeModalListener.bind(this);

        this.handleEventPayload = this.handleEventPayload.bind(this);
        this.dispatchToken = AppDispatcher.register(this.handleEventPayload);
    }

    addModalListener(action, callback) {
        this.on(action, callback);
    }

    removeModalListener(action, callback) {
        this.removeListener(action, callback);
    }

    handleEventPayload(payload) {
        // toggle event handlers should accept a boolean show/hide value and can accept a map of arguments
        const {type, value, ...args} = payload.action;

        switch (type) {
        case ActionTypes.TOGGLE_IMPORT_THEME_MODAL:
        case ActionTypes.TOGGLE_INVITE_MEMBER_MODAL:
        case ActionTypes.TOGGLE_DELETE_POST_MODAL:
            this.emit(type, value, args);
            break;
        }
    }
}

const ModalStore = new ModalStoreClass();
export default ModalStore;