<commit_before>'use strict';

var EVENTS_PREFIX = 'famous:events';
var CORE_PREFIX = 'famous:core';

var DEFAULT_IMPORTS = {
    'famous:core': ['view', 'dom-element', 'ui-element'],
    'famous:events': ['click', 'mouseover', 'mouseenter', 'mouseout']
}

function importDependencies(definition) {
    definition.imports = definition.imports || DEFAULT_IMPORTS;

    if (definition.tree) importTreeDependencies(definition);
    if (definition.events) importEventDependencies(definition);
}

function importTreeDependencies(definition) {
    for (var prefix in definition.imports) {
        var suffixList = definition.imports[prefix];
        for (var i = 0; i < suffixList.length; i++) {
            var re = new RegExp(suffixList[i], "g"); // replace all instances of view globally
            var expandedName = prefix + ':' + suffixList[i];
            definition.tree = definition.tree.replace(re, expandedName); // view -> famous:core:view
        }
    }
}

function importEventDependencies(definition) {
    for (var selector in definition.events) {
        if (selector[0] === '#') {
            var selectorEvents = definition.events[selector];
            for (var event in selectorEvents) {
                if (definition.imports[EVENTS_PREFIX]) {
                    for (var i = 0; i < definition.imports[EVENTS_PREFIX].length; i++) {
                        var suffix = definition.imports[EVENTS_PREFIX][i];
                        if (event === suffix) {
                            var expandedName = EVENTS_PREFIX + ':' + suffix
                            definition.events[selector][expandedName] = definition.events[selector][event];
                            delete definition.events[selector].event;
                        }
                    }
                }
            }
        }
    }
}

module.exports = {
    importDependencies: importDependencies
}<commit_msg>feat: re-implement event importer<commit_after>'use strict';

var VirtualDOM = require('./virtual-dom');

var EVENTS_PREFIX = 'famous:events';
var CORE_PREFIX = 'famous:core';

var DEFAULT_IMPORTS = {
    'famous:core': ['view', 'dom-element', 'ui-element'],
    'famous:events': ['click', 'mouseover', 'mouseenter', 'mouseout']
}

// do replacement here
function importDependencies(definition, options) {
    var imports = getFlatMapping(options.imports || DEFAULT_IMPORTS);

    //if (definition.tree) importTreeDependencies(definition.tree, imports);
    if (definition.events) definition.events = importEventDependencies(definition.events, imports);
}

// TODO:
//      - implement
//      - build new tree
//      - return new tree
function importTreeDependencies(oldTree, imports) {
    return oldTree;
}

function importEventDependencies(oldEvents, imports) {
    var newEvents = {};

    // loop through main events obj
    for (var selector in oldEvents) {

        // determine selector name
        var newSelector = imports[selector] || selector;
        newEvents[newSelector] = {};

        // loop through each selectorEvent
        var selectorEvents = oldEvents[selector];
        for (var event in selectorEvents) {

            // determine event name;
            var newEvent = imports[event] || event;
            newEvents[newSelector][newEvent] = selectorEvents[event];
        }
    }

    return newEvents;
}

// TODO:
//      - handle new feat of replacing behaviors selectors
//          (split into separate fn so events can use it)
//      - build new behaviors
function importBehaviorDependencies(behaviors, imports) {}

function getFlatMapping(imports) {
    var flatMapping = {};
    for (var selector in imports) {
        var array = imports[selector];
        for (var i = 0; i < array.length; i++) {
            flatMapping[array[i]] = selector + ':' + array[i]
        }
    }
    return flatMapping;
}

module.exports = {
    importDependencies: importDependencies
}
{'fraction_non_alphanumeric': 0.11856594110115237, 'fraction_numerical': 0.001024327784891165, 'mean_word_length': 2.593376264949402, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, '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': '714101', 'n_tokens_mistral': 1062, 'n_tokens_neox': 1031, 'n_words': 263}