<commit_before>'use strict';

/*!
 * Relacx v2.0
 *
 * Copyright 2017, <NAME>
 * Released under the MIT license
 * https://github.com/webXtended/Relacx
 * Date: 2017-09-19
 */
(function (name, context, definition) {
    if (typeof module != 'undefined') {
        module.exports = definition();
    } else if (typeof define == 'function') {
        define(definition);
    } else {
        context[name] = definition();
    }
})('Relacx', window, function () {
    var controllers = {};
    var actionListeners = {};

    var BaseComponent = function (_React$Component) {
        babelHelpers.inherits(BaseComponent, _React$Component);

        function BaseComponent(props) {
            babelHelpers.classCallCheck(this, BaseComponent);

            var _this = babelHelpers.possibleConstructorReturn(this, (BaseComponent.__proto__ || Object.getPrototypeOf(BaseComponent)).call(this, props));

            var properties = {};

            for (var key in _this.props.props) {
                properties[key] = _this.props.props[key];
            }

            _this.properties = properties;
            return _this;
        }

        babelHelpers.createClass(BaseComponent, [{
            key: 'componentWillMount',
            value: function componentWillMount() {
                if (this.props.parentController) {
                    this.props.init.prototype.uber = this.props.parentController;
                }

                var controller = new this.props.init(this, this.props.compController);

                this.controller = controller;
                this.setState(this.props.state);

                if (controllers[this.props.comp.name]) {
                    controllers[this.props.comp.name].setComponentController(controller);
                }

                if (this.props.callback) {
                    this.props.callback(controller);
                }
            }
        }, {
            key: 'componentWillReceiveProps',
            value: function componentWillReceiveProps(props) {
                this.setState(props.state);
            }
        }, {
            key: 'render',
            value: function render() {

                var Element = this.props.comp;

                this.properties.controller = this.controller;
                this.properties.state = this.state;
                return React.createElement(Element, this.properties);
            }
        }]);
        return BaseComponent;
    }(React.Component);

    ;

    function setItemFromObjectKey(obj, key, item) {
        var key = key.split(".");
        var data = obj;
        var prop;
        for (var i = 1; i < key.length - 1; i++) {
            prop = key[i];
            data = data[prop];
        }
        data[key.pop()] = item;
        return obj;
    }

    function getBaseController() {
        function Controller(component, controller) {
            var that = this;
            var childComponents = [];
            this.childKeys = "root";

            this.componentController = controller;
            this.constructor.prototype = controller;

            this.action = function (name) {
                var args = Array.prototype.slice.call(arguments);
                args.shift();
                var fn = Function.prototype.bind.apply(this.componentController[name], [that].concat(args));
                return fn;
            };
            this.setState = function (obj, key) {
                if (key) {
                    var data = setItemFromObjectKey(component.state, key, obj);
                    data = JSON.parse(JSON.stringify(data));
                    component.setState(data);
                } else {
                    component.setState(obj);
                }
            };
            this.getState = function () {
                return component.state;
            };

            this.getChildInstances = function () {
                return childComponents;
            };
            this.addChildInstance = function (instance) {
                childComponents.push(instance);
            };
        }

        return Controller;
    }

    function getChildController(parent, childPath) {
        function Controller(component, controller) {
            var that = this;
            var key = childPath;

            this.childKeys = childPath;

            this.componentController = controller;

            this.action = function (name) {
                var args = Array.prototype.slice.call(arguments);
                args.shift();
                var fn = Function.prototype.bind.apply(this.componentController[name], [that].concat(args));
                return fn;
            };

            this.setState = function (obj, prevKey) {
                var keyList = parent.props.controller.childKeys;
                parent.props.controller.setState(obj, [keyList, prevKey || key].join("."));
            };

            this.getState = function () {
                return component.state;
            };
        }

        return Controller;
    }

    function render(Component, container, options) {
        var Controller = getBaseController();
        var properties = controllers[Component.name] || {};

        var baseComponent = React.createElement(BaseComponent, { init: Controller,
            comp: Component,
            props: options.props,
            state: options.state,
            callback: options.callback });

        if (container) {
            ReactDOM.render(baseComponent, container, function () {
                if (options.afterRender && typeof options.afterRender === 'function') {
                    options.afterRender();
                }
            });
        } else {
            return baseComponent;
        }
    }
<commit_msg>Update relacx.js<commit_after>'use strict';

/*!
 * Relacx v2.0
 *
 * Copyright 2017, <NAME>
 * Released under the MIT license
 * https://github.com/webXtended/Relacx
 * Date: 2017-09-19
 */
(function (name, context, definition) {
    if (typeof module != 'undefined') {
        module.exports = definition();
    } else if (typeof define == 'function') {
        define(definition);
    } else {
        context[name] = definition();
    }
})('Relacx', window, function () {
    var controllers = {};
    var actionListeners = {};

    var BaseComponent = function (_React$Component) {
        babelHelpers.inherits(BaseComponent, _React$Component);

        function BaseComponent(props) {
            babelHelpers.classCallCheck(this, BaseComponent);

            var _this = babelHelpers.possibleConstructorReturn(this, (BaseComponent.__proto__ || Object.getPrototypeOf(BaseComponent)).call(this, props));

            var properties = {};

            for (var key in _this.props.props) {
                properties[key] = _this.props.props[key];
            }

            _this.properties = properties;
            return _this;
        }

        babelHelpers.createClass(BaseComponent, [{
            key: 'componentWillMount',
            value: function componentWillMount() {
                if (this.props.parentController) {
                    this.props.init.prototype.uber = this.props.parentController;
                }

                var controller = new this.props.init(this, this.props.compController);

                this.controller = controller;
                this.setState(this.props.state);

                if (controllers[this.props.comp.name]) {
                    controllers[this.props.comp.name].setComponentController(controller);
                }

                if (this.props.callback) {
                    this.props.callback(controller);
                }
            }
        }, {
            key: 'componentWillReceiveProps',
            value: function componentWillReceiveProps(props) {
                this.setState(props.state);
            }
        }, {
            key: 'render',
            value: function render() {

                var Element = this.props.comp;

                this.properties.controller = this.controller;
                this.properties.state = this.state;
                return React.createElement(Element, this.properties);
            }
        }]);
        return BaseComponent;
    }(React.Component);

    ;

    function setItemFromObjectKey(obj, key, item) {
        var key = key.split(".");
        var data = obj;
        var prop;
        for (var i = 1; i < key.length - 1; i++) {
            prop = key[i];
            data = data[prop];
        }
        data[key.pop()] = item;
        return obj;
    }

    function getBaseController() {
        function Controller(component, controller) {
            var that = this;
            var childComponents = [];
            this.childKeys = "root";

            this.componentController = controller;
            this.constructor.prototype = controller;

            this.action = function (name) {
                var args = Array.prototype.slice.call(arguments);
                args.shift();
                var fn = Function.prototype.bind.apply(this.componentController[name], [that].concat(args));
                return fn;
            };
            this.setState = function (obj, key) {
                if (key) {
                    var data = setItemFromObjectKey(component.state, key, obj);
                    data = JSON.parse(JSON.stringify(data));
                    component.setState(data);
                } else {
                    component.setState(obj);
                }
            };
            this.getState = function () {
                return component.state;
            };

            this.getChildInstances = function () {
                return childComponents;
            };
            this.addChildInstance = function (instance) {
                childComponents.push(instance);
            };
        }

        return Controller;
    }

    function getChildController(parent, childPath) {
        function Controller(component, controller) {
            var that = this;
            var key = childPath;

            this.childKeys = childPath;

            this.componentController = controller;

            this.action = function (name) {
                var args = Array.prototype.slice.call(arguments);
                args.shift();
                var fn = Function.prototype.bind.apply(this.componentController[name], [that].concat(args));
                return fn;
            };

            this.setState = function (obj, prevKey) {
                var keyList = parent.props.controller.childKeys;
                parent.props.controller.setState(obj, [keyList, prevKey || key].join("."));
            };

            this.getState = function () {
                return component.state;
            };
        }

        return Controller;
    }

    function render(Component, container, options) {
        var Controller = getBaseController();
        var properties = controllers[Component.name] || {};
        options.props = options.props || {};
        options.state = options.state || {};

        var baseComponent = React.createElement(BaseComponent, { init: Controller,
            comp: Component,
            props: options.props,
            state: options.state,
            callback: options.callback });

        if (container) {
            ReactDOM.render(baseComponent, container, function () {
                if (options.afterRender && typeof options.afterRender === 'function') {
                    options.afterRender();
                }
            });
        } else {
            return baseComponent;
        }
    }

{'fraction_non_alphanumeric': 0.10875742702144149, 'fraction_numerical': 0.002755532592783949, 'mean_word_length': 1.6034521407756108, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '1300874', 'n_tokens_mistral': 2922, 'n_tokens_neox': 2773, 'n_words': 581}