<commit_before>angular.module('mwUI.Backbone')

  .directive('mwModel', function () {
    return {
      require: '?ngModel',
      link: function (scope, el, attrs, ngModel) {
        var model, modelAttr;

        var updateNgModel = function () {
          var val = model.get(modelAttr);

          debugger;
          ngModel.$formatters.forEach(function (formatFn) {
            val = formatFn(val);
          });

          ngModel.$setViewValue(val);
          ngModel.$render();
        };

        var updateBackboneModel = function () {
          var obj = {};
          debugger;
          if(model.get(modelAttr) instanceof Backbone.Model){
            if(ngModel.$modelValue && ngModel.$modelValue instanceof Backbone.Model){
              obj = ngModel.$modelValue.toJSON();
            } else if(angular.isObject(ngModel.$modelValue)){
              obj = ngModel.$modelValue;
            } else {
              //obj[modelAttr] = ngModel.$modelValue;
            }
            model.get(modelAttr).set(obj,{fromNgModel: true});
          } else {
            obj[modelAttr] = ngModel.$modelValue;
            model.set(obj, {fromNgModel: true});
          }
        };

        var getModelAttrName = function(){
          var mwModelAttrOption = attrs.mwModelAttr,
              mwModelAttrFromNgModel = attrs.ngModel;

          if(mwModelAttrOption && mwModelAttrOption.length>0){
            return mwModelAttrOption
          } else if(angular.isUndefined(mwModelAttrOption) && mwModelAttrFromNgModel){
            return mwModelAttrFromNgModel.split('.').pop();
          }
        };

        var init = function () {
          model = scope.$eval(attrs.mwModel);
          modelAttr = getModelAttrName();

          if (model && modelAttr) {
            model.on('change:' + modelAttr, function (model, val, options) {
              if (!options.fromNgModel) {
                updateNgModel();
              }
            });

            ngModel.$viewChangeListeners.push(updateBackboneModel);
            ngModel.$parsers.push(function (val) {
              updateBackboneModel();
              return val;
            });

            if(model.get(modelAttr) && ngModel.$modelValue&& model.get(modelAttr) !== ngModel.$modelValue){
              throw new Error('The ng-model and the backbone model can not have different values during initialization!');
            } else if (model.get(modelAttr)) {
              updateNgModel();
            } else if (ngModel.$modelValue) {
              updateBackboneModel();
            }
          }
        };

        if (ngModel) {
          if (scope.mwModel && getModelAttrName()) {
            init();
          } else {
            var offModel = scope.$watch('mwModel', function (val) {
              offModel();
              init();
            });

            var offModelAttr = scope.$watch('mwModelAttr', function (val) {
              offModelAttr();
              init();
            });
          }
        }
      }
    };
  });<commit_msg>removes functionality that ngModel value can be a backbone model to keep stuff simple<commit_after>angular.module('mwUI.Backbone')

  .directive('mwModel', function () {
    return {
      require: '?ngModel',
      link: function (scope, el, attrs, ngModelCtrl) {
        var model, modelAttr;

        var updateNgModel = function () {
          var val = model.get(modelAttr);

          ngModelCtrl.$formatters.forEach(function (formatFn) {
            val = formatFn(val);
          });

          ngModelCtrl.$setViewValue(val);
          ngModelCtrl.$render();
        };

        var updateBackboneModel = function () {
          var obj = {};

          obj[modelAttr] = ngModelCtrl.$modelValue;
          model.set(obj, {fromNgModel: true});
        };

        var getModelAttrName = function () {
          var mwModelAttrOption = attrs.mwModelAttr,
            mwModelAttrFromNgModel = attrs.ngModel;

          if (mwModelAttrOption && mwModelAttrOption.length > 0) {
            return mwModelAttrOption
          } else if (angular.isUndefined(mwModelAttrOption) && mwModelAttrFromNgModel) {
            return mwModelAttrFromNgModel.split('.').pop();
          }
        };

        var init = function () {
          model = scope.$eval(attrs.mwModel);
          modelAttr = getModelAttrName();

          if (ngModelCtrl && model && modelAttr) {

            model.on('change:' + modelAttr, function (model, val, options) {
              if (!options.fromNgModel) {
                updateNgModel();
              }
            });

            ngModelCtrl.$viewChangeListeners.push(updateBackboneModel);
            ngModelCtrl.$parsers.push(function (val) {
              updateBackboneModel();
              return val;
            });

            if (model.get(modelAttr) && ngModelCtrl.$modelValue && model.get(modelAttr) !== ngModelCtrl.$modelValue) {
              throw new Error('The ng-model and the backbone model can not have different values during initialization!');
            } else if (model.get(modelAttr)) {
              updateNgModel();
            } else if (ngModelCtrl.$modelValue) {
              updateBackboneModel();
            }
          }
        };

        if (scope.mwModel && getModelAttrName()) {
          init();
        } else {
          var offModel = scope.$watch('mwModel', function (val) {
            offModel();
            init();
          });

          var offModelAttr = scope.$watch('mwModelAttr', function (val) {
            offModelAttr();
            init();
          });
        }
      }
    };
  });
{'fraction_non_alphanumeric': 0.12020688425182807, 'fraction_numerical': 0.0003566969859104691, 'mean_word_length': 1.7249757045675413, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3418033', 'n_tokens_mistral': 1527, 'n_tokens_neox': 1479, 'n_words': 291}