@crnk/angular-ngrx
Version:
Angular helper library for ngrx-json-api and crnk:
99 lines • 3.79 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { Input, SimpleChanges } from '@angular/core';
import { AsyncValidatorFn, ControlContainer, ControlValueAccessor, FormControl, NgControl, Validator, ValidatorFn } from '@angular/forms';
import { composeAsyncValidators, composeValidators, isPropertyUpdated } from './crnk.expression.form.utils';
import { Path } from '../crnk.expression';
var resolvedPromise = Promise.resolve(null);
function unimplemented() {
throw new Error('unimplemented');
}
var CrnkControl = /** @class */ (function (_super) {
__extends(CrnkControl, _super);
function CrnkControl() {
var _this = _super !== null && _super.apply(this, arguments) || this;
/** @internal */
_this._parent = null;
_this.name = null;
_this.valueAccessor = null;
/** @internal */
_this._rawValidators = [];
/** @internal */
_this._rawAsyncValidators = [];
/** @internal */
_this._control = new FormControl();
/** @internal */
_this._registered = false;
return _this;
}
Object.defineProperty(CrnkControl.prototype, "control", {
get: function () {
return this._control;
},
set: function (control) {
this._control = control;
},
enumerable: true,
configurable: true
});
Object.defineProperty(CrnkControl.prototype, "validator", {
get: function () {
return composeValidators(this._rawValidators);
},
enumerable: true,
configurable: true
});
Object.defineProperty(CrnkControl.prototype, "asyncValidator", {
get: function () {
return composeAsyncValidators(this._rawAsyncValidators);
},
enumerable: true,
configurable: true
});
CrnkControl.prototype._updateValue = function (value) {
var _this = this;
resolvedPromise.then(function () {
_this.control.setValue(value, { emitViewToModelChange: false });
});
};
CrnkControl.prototype.ngOnChanges = function (changes) {
if (!this._registered) {
this._setUpControl();
}
if ('disabled' in changes) {
this._updateDisabled(changes);
}
if (isPropertyUpdated(changes, this.viewModel)) {
var value = this._pathModel.getValue();
this._updateValue(value);
this.viewModel = value;
}
};
CrnkControl.prototype._updateDisabled = function (changes) {
var _this = this;
var disabledValue = changes['disabled'].currentValue;
var disabled = disabledValue === '' || (disabledValue && disabledValue !== 'false');
resolvedPromise.then(function () {
if (disabled && !_this.control.disabled) {
_this.control.disable();
}
else if (!disabled && _this.control.disabled) {
_this.control.enable();
}
});
};
CrnkControl.propDecorators = {
"disabled": [{ type: Input, args: ['disabled',] },],
};
return CrnkControl;
}(NgControl));
export { CrnkControl };
//# sourceMappingURL=crnk.expression.form.model.base.js.map