<commit_before>/*global FormplayerFrontend */

/**
 * hq.events.js
 *
 * This is framework for allowing messages from HQ
 */
FormplayerFrontend.module("HQ.Events", function(Events, FormplayerFrontend) {

    Events.Receiver = function(allowedHost) {
        this.allowedHost = allowedHost;
        return receiver.bind(this);
    };

    var receiver = function(event) {
        // For Chrome, the origin property is in the event.originalEvent object
        var origin = event.origin || event.originalEvent.origin,
            data = event.data,
            returnValue = null,
            success = true;

        _.defaults(data, {
            success: function() {},
            error: function() {},
            complete: function() {},
        });
        if (!origin.endsWith(this.allowedHost)) {
            throw new Error('Disallowed origin ' + origin);
        }

        if (!data.hasOwnProperty('action')) {
            throw new Error('Message must have action property');
        }
        if (!_.contains(_.values(Events.Actions), data.action)) {
            throw new Error('Invalid action ' + data.action);
        }

        try {
            switch (data.action) {
            case Events.Actions.BACK:
                FormplayerFrontend.trigger('navigation:back');
                break;
            }
        } catch (e) {
            success = false;
            data.error(event, data, returnValue);
        } finally {
            data.complete(event, data, returnValue);
        }
        if (success) {
            data.success(event, data, returnValue);
        }
    };

    Events.Actions = {
        BACK: 'back',
    };
});<commit_msg>Remove ability to have callbacks<commit_after>/*global FormplayerFrontend */

/**
 * hq.events.js
 *
 * This is framework for allowing messages from HQ
 */
FormplayerFrontend.module("HQ.Events", function(Events, FormplayerFrontend) {

    Events.Receiver = function(allowedHost) {
        this.allowedHost = allowedHost;
        return receiver.bind(this);
    };

    var receiver = function(event) {
        // For Chrome, the origin property is in the event.originalEvent object
        var origin = event.origin || event.originalEvent.origin,
            data = event.data,
            success = true;

        if (!origin.endsWith(this.allowedHost)) {
            throw new Error('Disallowed origin ' + origin);
        }

        if (!data.hasOwnProperty('action')) {
            throw new Error('Message must have action property');
        }
        if (!_.contains(_.values(Events.Actions), data.action)) {
            throw new Error('Invalid action ' + data.action);
        }

        switch (data.action) {
        case Events.Actions.BACK:
            FormplayerFrontend.trigger('navigation:back');
            break;
        }
    };

    Events.Actions = {
        BACK: 'back',
    };
});
{'fraction_non_alphanumeric': 0.11942896935933148, 'fraction_numerical': 0.0, 'mean_word_length': 1.9618556701030927, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5711643', 'n_tokens_mistral': 754, 'n_tokens_neox': 735, 'n_words': 178}