<commit_before>
dop.getAction = function(mutations) {

    var action = {},
        index = 0,
        total = mutations.length;

    for (;index<total; ++index)
        if (dop.core.objectIsStillStoredOnPath(mutations[index].object)) // Only need it for arrays but is faster than injectMutation
            dop.util.injectMutationInAction(action, mutations[index]);

    return action;
};

dop.core.objectIsStillStoredOnPath = function(object) {

    var path = dop.getObjectDop(object),
        index = path.length-1,
        parent;

    for (;index>0; --index) {
        parent = (index>1) ? dop.getObjectDop(object)._ : dop.data.object[path[0]];
        if (parent[path[index]] !== object)
            return false;
        object = dop.getObjectProxy(parent);
    }

    return true;
};

dop.util.injectMutationInAction = function(action, mutation) {

    var isMutationArray = mutation.splice!==undefined || mutation.swaps!==undefined,
        path = dop.getObjectDop(mutation.object).slice(0),
        index = 0,
        total = path.length-1,
        object = mutation.object,
        prop = mutation.name,
        value = mutation.value,
        isArray = Array.isArray,
        parent, object;


    if (!isMutationArray) {
        path.push(mutation.name);
        total += 1;
    }

debugger;
    for (;index<total; ++index) {
        parent = action;
        object = action[path[index]];
        action = (dop.util.isObject(object)) ? object : action[path[index]]={};
    }

    if (isArray(mutation.object) || isArray(value)) {//isMutationArray || 

        prop = path[index];
        object = action;
        if (!isMutationArray && isArray(mutation.object)) {
            prop = path[index-1];
            object = parent;
        }

        if (!dop.util.isObject(object[prop]))
            object[prop] = {};


        if (!dop.util.isObject(object[prop][CONS.dop]))
            object[prop][CONS.dop] = [];

        // new array
        if (isArray(value))
            object[prop][CONS.dop].push([0]);

        // splice
        else if (mutation.splice!==undefined)
            action[prop][CONS.dop].push(mutation.splice);

        // swaps
        else if (mutation.swaps!==undefined) {
            var swaps = mutation.swaps.slice(0),
                tochange = (swaps[0]>0) ? 0 : 1;
            swaps[tochange] = swaps[tochange]*-1;
            action[prop][CONS.dop].push(swaps);
        }

        // set
        else
            object[prop][CONS.dop].push([mutation.name, 0, mutation.value]);
    }

    else
        action[prop] = value;
<commit_msg>Making mutations/actions and tests for it<commit_after>
dop.getAction = function(mutations) {

    var action = {},
        index = 0,
        total = mutations.length;

    for (;index<total; ++index)
        if (dop.core.objectIsStillStoredOnPath(mutations[index].object)) // Only need it for arrays but is faster than injectMutation
            dop.util.injectMutationInAction(action, mutations[index]);

    return action;
};

dop.core.objectIsStillStoredOnPath = function(object) {

    var path = dop.getObjectDop(object),
        index = path.length-1,
        parent;

    for (;index>0; --index) {
        parent = (index>1) ? dop.getObjectDop(object)._ : dop.data.object[path[0]];
        if (parent[path[index]] !== object)
            return false;
        object = dop.getObjectProxy(parent);
    }

    return true;
};

dop.util.injectMutationInAction = function(action, mutation) {

    var isMutationArray = mutation.splice!==undefined || mutation.swaps!==undefined,
        path = dop.getObjectDop(mutation.object).slice(0),
        index = 0,
        total = path.length-1,
        object = mutation.object,
        prop = mutation.name,
        value = mutation.value,
        isArray = Array.isArray,
        parent, object;


    if (!isMutationArray) {
        path.push(mutation.name);
        total += 1;
    }

debugger;
    for (;index<total; ++index) {
        parent = action;
        object = action[path[index]];
        action = (dop.util.isObject(object)) ? object : action[path[index]]={};
    }

    if (isArray(mutation.object) || isArray(value)) {

        prop = path[index];
        if (!isMutationArray && isArray(mutation.object)) {
            prop = path[index-1];
            action = parent;
        }

        if (!dop.util.isObject(action[prop]))
            action[prop] = {};


        if (!dop.util.isObject(action[prop][CONS.dop]))
            action[prop][CONS.dop] = [];

        // new array
        if (isArray(value))
            action[prop][CONS.dop].push([0]);

        // splice
        else if (mutation.splice!==undefined)
            action[prop][CONS.dop].push(mutation.splice);

        // swaps
        else if (mutation.swaps!==undefined) {
            var swaps = mutation.swaps.slice(0),
                tochange = (swaps[0]>0) ? 0 : 1;
            swaps[tochange] = swaps[tochange]*-1;
            action[prop][CONS.dop].push(swaps);
        }

        // set
        else
            action[prop][CONS.dop].push([mutation.name, 0, mutation.value]);
    }

    else
        action[prop] = value;

{'fraction_non_alphanumeric': 0.14432789432789433, 'fraction_numerical': 0.006993006993006993, 'mean_word_length': 2.1396341463414634, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '5246489', 'n_tokens_mistral': 1683, 'n_tokens_neox': 1597, 'n_words': 292}