UNPKG

@darkobits/formation

Version:
38 lines (27 loc) 1.25 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.MockControl = undefined; var _constants = require('../../etc/constants'); var _interfaces = require('../../etc/interfaces'); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var MockControl = exports.MockControl = function MockControl(ngModelCtrl, formCtrl, formScope) { var _this = this; _classCallCheck(this, MockControl); this.name = ngModelCtrl.$name; this.getModelValue = this[_interfaces.GetModelValue]; this.setModelValue = this[_interfaces.SetModelValue]; this[_constants.NG_MODEL_CTRL] = ngModelCtrl; this[_constants.FORM_CONTROLLER] = formCtrl; var cancelWatcher = formScope.$watch(function () { return ngModelCtrl.$modelValue; }, function (newValue) { formCtrl.$setModelValue(_this.name, newValue); }); formScope.$on('$destroy', cancelWatcher); }; _interfaces.GetModelValue.implementedBy(MockControl).as(function () { return this[_constants.FORM_CONTROLLER].$getModelValue(this.name); }); _interfaces.SetModelValue.implementedBy(MockControl).as(function (n) {}); // eslint-disable-line no-unused-vars