UNPKG

ferngully-aurelia-tools

Version:

Ferngully Tools for Aurelia

80 lines 3.65 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; import { transient } from "aurelia-framework"; import { includeEventsIn } from "aurelia-event-aggregator"; var ValidationEventAggregator = (function () { function ValidationEventAggregator() { this.instanceErrors = new Map(); includeEventsIn(this); } ValidationEventAggregator.prototype.render = function (instruction) { this.groupInstanceErrors(instruction); var changed = new Set(); for (var _i = 0, _a = instruction.render.concat(instruction.unrender); _i < _a.length; _i++) { var errorInfo = _a[_i]; changed.add(errorInfo.result.object); } this._notify(changed); }; ValidationEventAggregator.prototype.groupInstanceErrors = function (renderInstruction) { for (var _i = 0, _a = renderInstruction.unrender; _i < _a.length; _i++) { var result = _a[_i].result; var instance = result.object; var errorSet = this.instanceErrors.get(instance); if (errorSet) { if (errorSet.has(result)) { errorSet.delete(result); if (errorSet.size === 0) { this.instanceErrors.delete(instance); } } } } for (var _b = 0, _c = renderInstruction.render; _b < _c.length; _b++) { var result = _c[_b].result; var instance = result.object; var errorSet = this.instanceErrors.get(instance); if (!errorSet) { errorSet = new Set(); this.instanceErrors.set(instance, errorSet); } if (!result.valid) { errorSet.add(result); } } }; ValidationEventAggregator.prototype._notify = function (instances) { var _this = this; instances.forEach(function (instance) { var errorSet = _this.instanceErrors.get(instance); _this.publish("validationChanged", { instance: instance, errors: Array.from(errorSet || []) }); }); }; Object.defineProperty(ValidationEventAggregator.prototype, "invalidInstances", { get: function () { var instances = new Set(); if (this.instanceErrors) { this.instanceErrors.forEach(function (errorSet, instance) { instances.add(instance); }); } return Array.from(instances); }, enumerable: true, configurable: true }); ValidationEventAggregator = __decorate([ transient(), __metadata("design:paramtypes", []) ], ValidationEventAggregator); return ValidationEventAggregator; }()); export { ValidationEventAggregator }; //# sourceMappingURL=validation-event-aggregator.js.map