summaryrefslogtreecommitdiffstats
path: root/webapp/components/suggestion/provider.jsx
blob: a5b54fb26705a534d1282d7445a351a9d3367ffc (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
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import SuggestionStore from 'stores/suggestion_store.jsx';

export default class Provider {
    constructor() {
        this.latestPrefix = '';
        this.latestComplete = true;
        this.disableDispatches = false;
    }

    handlePretextChanged(suggestionId, pretext) { // eslint-disable-line no-unused-vars
        // NO-OP for inherited classes to override
    }

    startNewRequest(suggestionId, prefix) {
        this.latestPrefix = prefix;
        this.latestComplete = false;

        // Don't use the dispatcher here since this is only called while handling an event
        SuggestionStore.setSuggestionsPending(suggestionId, true);
    }

    shouldCancelDispatch(prefix) {
        if (this.disableDispatches) {
            return true;
        }

        if (prefix === this.latestPrefix) {
            this.latestComplete = true;
        } else if (this.latestComplete) {
            return true;
        }

        return false;
    }
}