@crnk/angular-ngrx
Version:
Angular helper library for ngrx-json-api and crnk:
86 lines • 4.38 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 { Directive, EventEmitter, forwardRef, Inject, Input, OnChanges, OnDestroy, Optional, Output, Self } from '@angular/core';
import { AsyncValidatorFn, ControlValueAccessor, NG_ASYNC_VALIDATORS, NG_VALIDATORS, NG_VALUE_ACCESSOR, NgControl, Validator, ValidatorFn } from '@angular/forms';
import { selectValueAccessor, setUpControl } from './crnk.expression.form.utils';
import { ExpressionAccessor, Path } from '../crnk.expression';
import { CrnkControl } from './crnk.expression.form.model.base';
var expressionControlBinding = {
provide: NgControl,
useExisting: forwardRef(function () { return ExpressionDirective; })
};
var ExpressionDirective = /** @class */ (function (_super) {
__extends(ExpressionDirective, _super);
/**
* NOTE that in contract to NgModel we do not use @Host for parent. This would enforce that the
* components are direct children of the forms component. TODO investigate whether there is
* any better solutions (maybe something similar to FormGroup). It does not seem like it is possible
* to expose an existing ControlContainer again with @Component.providers as it would lead to a circular
* dependency (there is no provider for children only, but itself as well).
*/
function ExpressionDirective(validators, asyncValidators, valueAccessors) {
var _this = _super.call(this) || this;
_this.crnkExpressionChange = new EventEmitter();
_this._rawValidators = validators || [];
_this._rawAsyncValidators = asyncValidators || [];
_this.valueAccessor = selectValueAccessor(_this, valueAccessors);
return _this;
}
Object.defineProperty(ExpressionDirective.prototype, "pathModel", {
get: function () {
return this._pathModel;
},
set: function (pathModel) {
this._pathModel = pathModel;
this._control['_pathModel'] = pathModel;
var expressionAccessor = this.valueAccessor;
if (expressionAccessor.setExpression) {
expressionAccessor.setExpression(pathModel);
}
},
enumerable: true,
configurable: true
});
ExpressionDirective.prototype.ngOnDestroy = function () {
};
ExpressionDirective.prototype._setUpControl = function () {
this._setUpStandalone();
this._registered = true;
};
ExpressionDirective.prototype._setUpStandalone = function () {
setUpControl(this._control, this);
this._control.updateValueAndValidity({ emitEvent: false });
};
ExpressionDirective.prototype.viewToModelUpdate = function (newValue) {
this.viewModel = newValue;
this.crnkExpressionChange.emit(newValue);
};
ExpressionDirective.decorators = [
{ type: Directive, args: [{
selector: '[crnkExpression]',
providers: [expressionControlBinding],
exportAs: 'crnkExpression'
},] },
];
/** @nocollapse */
ExpressionDirective.ctorParameters = function () { return [
{ type: Array, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [NG_VALIDATORS,] },] },
{ type: Array, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [NG_ASYNC_VALIDATORS,] },] },
{ type: Array, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [NG_VALUE_ACCESSOR,] },] },
]; };
ExpressionDirective.propDecorators = {
"pathModel": [{ type: Input, args: ['crnkExpression',] },],
"crnkExpressionChange": [{ type: Output, args: ['crnkExpressionChange',] },],
};
return ExpressionDirective;
}(CrnkControl));
export { ExpressionDirective };
//# sourceMappingURL=crnk.expression.form.model.default.js.map