UNPKG

ferngully-aurelia-tools

Version:

Ferngully Tools for Aurelia

71 lines 3.04 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"; let ValidationEventAggregator = class ValidationEventAggregator { constructor() { this.instanceErrors = new Map(); includeEventsIn(this); } render(instruction) { this.groupInstanceErrors(instruction); let changed = new Set(); for (let errorInfo of instruction.render.concat(instruction.unrender)) { changed.add(errorInfo.result.object); } this._notify(changed); } groupInstanceErrors(renderInstruction) { for (let { result } of renderInstruction.unrender) { let instance = result.object; let errorSet = this.instanceErrors.get(instance); if (errorSet) { if (errorSet.has(result)) { errorSet.delete(result); if (errorSet.size === 0) { this.instanceErrors.delete(instance); } } } } for (let { result } of renderInstruction.render) { let instance = result.object; let errorSet = this.instanceErrors.get(instance); if (!errorSet) { errorSet = new Set(); this.instanceErrors.set(instance, errorSet); } if (!result.valid) { errorSet.add(result); } } } _notify(instances) { instances.forEach((instance) => { let errorSet = this.instanceErrors.get(instance); this.publish("validationChanged", { instance: instance, errors: Array.from(errorSet || []) }); }); } get invalidInstances() { let instances = new Set(); if (this.instanceErrors) { this.instanceErrors.forEach((errorSet, instance) => { instances.add(instance); }); } return Array.from(instances); } }; ValidationEventAggregator = __decorate([ transient(), __metadata("design:paramtypes", []) ], ValidationEventAggregator); export { ValidationEventAggregator }; //# sourceMappingURL=validation-event-aggregator.js.map