<commit_before>/*jslint browserify: true */
"use strict";

require('./polyfills.js');
var opendolphin = require('opendolphin');
var ObjectObserver = require('ObjectObserver');
var Map  = require('../bower_components/core.js/library/fn/map');

var exists = require('./utils.js').exists;

var UNKNOWN = 0,
    BASIC_TYPE = 1,
    DOLPHIN_BEAN = 2;

function fromDolphin(classRepository, type, value) {
    return type === DOLPHIN_BEAN? classRepository.beanFromDolphin.get(value) : value;
}

function toDolphin(classRepository, type, value) {
    return type === DOLPHIN_BEAN? classRepository.beanToDolphin.get(value) : value;
}

function modifyList(bean, attribute, from, count, newElements) {
    var list = bean[attribute];
    if (!exists(list)) {
        bean[attribute] = list = [];
    } else if (!Array.isArray(list)) {
        bean[attribute] = list = [list];
    }
    if (typeof newElements === 'undefined') {
        list.splice(from, count);
    } else {
        list.splice(from, count, newElements);
    }
}


function ClassRepository() {
    this.classes = new Map();
    this.beanFromDolphin = new Map();
    this.beanToDolphin = new Map();
    this.classInfos = new Map();
}


ClassRepository.prototype.registerClass = function (model) {
    if (this.classes.has(model.id)) {
        return;
    }

    var classInfo = {};
    model.attributes.forEach(function (attribute) {
        classInfo[attribute.propertyName] = UNKNOWN;

        attribute.onValueChange(function (event) {
            classInfo[attribute.propertyName] = event.newValue;
        });
    });
    this.classes.set(model.id, classInfo);
};


ClassRepository.prototype.unregisterClass = function (model) {
    this.classes['delete'](model.id);
};


ClassRepository.prototype.load = function (model) {
    var _this = this;
    var classInfo = this.classes.get(model.presentationModelType);
    var bean = {};
    model.attributes.filter(function (attribute) {
        return attribute.tag === opendolphin.Tag.value();
    }).forEach(function (attribute) {
        bean[attribute.propertyName] = null;
        attribute.onValueChange(function (event) {
            if (event.oldValue !== event.newValue) {
                bean[attribute.propertyName] = fromDolphin(_this, classInfo[attribute.propertyName], event.newValue);
            }
        });
    });
    var observer = new ObjectObserver(bean);
    observer.open(function (added, removed, changed) {
        Object.keys(added).forEach(function (property) {
            var attribute = model.findAttributeByPropertyName(property);
            if (exists(attribute)) {
                var value = toDolphin(_this, classInfo[property], added[property]);
                attribute.setValue(value);
            }
        });
        Object.keys(removed).forEach(function (property) {
            var attribute = model.findAttributeByPropertyName(property);
            if (exists(attribute)) {
                attribute.setValue(null);
            }
        });
        Object.keys(changed).forEach(function (property) {
            var attribute = model.findAttributeByPropertyName(property);
            if (exists(attribute)) {
                var value = toDolphin(_this, classInfo[property], changed[property]);
                attribute.setValue(value);
            }<commit_msg>Even more printouts<commit_after>/*jslint browserify: true */
"use strict";

require('./polyfills.js');
var opendolphin = require('opendolphin');
var ObjectObserver = require('ObjectObserver');
var Map  = require('../bower_components/core.js/library/fn/map');

var exists = require('./utils.js').exists;

var UNKNOWN = 0,
    BASIC_TYPE = 1,
    DOLPHIN_BEAN = 2;

function fromDolphin(classRepository, type, value) {
    return type === DOLPHIN_BEAN? classRepository.beanFromDolphin.get(value) : value;
}

function toDolphin(classRepository, type, value) {
    return type === DOLPHIN_BEAN? classRepository.beanToDolphin.get(value) : value;
}

function modifyList(bean, attribute, from, count, newElements) {
    var list = bean[attribute];
    if (!exists(list)) {
        bean[attribute] = list = [];
    } else if (!Array.isArray(list)) {
        bean[attribute] = list = [list];
    }
    if (typeof newElements === 'undefined') {
        list.splice(from, count);
    } else {
        list.splice(from, count, newElements);
    }
}


function ClassRepository() {
    this.classes = new Map();
    this.beanFromDolphin = new Map();
    this.beanToDolphin = new Map();
    this.classInfos = new Map();
}


ClassRepository.prototype.registerClass = function (model) {
    if (this.classes.has(model.id)) {
        return;
    }

    var classInfo = {};
    model.attributes.forEach(function (attribute) {
        classInfo[attribute.propertyName] = UNKNOWN;

        attribute.onValueChange(function (event) {
            classInfo[attribute.propertyName] = event.newValue;
        });
    });
    this.classes.set(model.id, classInfo);
};


ClassRepository.prototype.unregisterClass = function (model) {
    this.classes['delete'](model.id);
};


ClassRepository.prototype.load = function (model) {
    var _this = this;
    var classInfo = this.classes.get(model.presentationModelType);
    var bean = {};
    model.attributes.filter(function (attribute) {
        return attribute.tag === opendolphin.Tag.value();
    }).forEach(function (attribute) {
        bean[attribute.propertyName] = null;
        attribute.onValueChange(function (event) {
            if (event.oldValue !== event.newValue) {
                bean[attribute.propertyName] = fromDolphin(_this, classInfo[attribute.propertyName], event.newValue);
            }
        });
    });
    var observer = new ObjectObserver(bean);
    observer.open(function (added, removed, changed) {
        Object.keys(added).forEach(function (property) {
            var attribute = model.findAttributeByPropertyName(property);
            if (exists(attribute)) {
                var value = toDolphin(_this, classInfo[property], added[property]);
                attribute.setValue(value);
            }
        });
        Object.keys(removed).forEach(function (property) {
            var attribute = model.findAttributeByPropertyName(property);
            if (exists(attribute)) {
                attribute.setValue(null);
            }
        });
        Object.keys(changed).forEach(function (property) {

            console.log("I");

            var attribute = model.findAttributeByPropertyName(property);

            console.log("II");

            if (exists(attribute)) {

                console.log("III");

                var value = toDolphin(_this, classInfo[property], changed[property]);

                console.log("IV");

                attribute.setValue(value);

                console.log("V");

            }
{'fraction_non_alphanumeric': 0.13305978898007034, 'fraction_numerical': 0.0008792497069167644, 'mean_word_length': 2.7686361126449475, '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': '7510508', 'n_tokens_mistral': 1957, 'n_tokens_neox': 1892, 'n_words': 365}