Skip to content
Permalink
Browse files

feat(config): rename global config class

  • Loading branch information
RomkeVdMeulen committed Nov 22, 2019
1 parent a52f4c4 commit c4e5fe29e2a9bcd11cfdaba0f70050ef9c894be6
@@ -27,7 +27,7 @@ export * from './implementation/validation-rules';
// Configuration

import { Container } from 'aurelia-dependency-injection';
import { AureliaValidationConfiguration } from './config';
import { GlobalValidationConfiguration } from './config';
import { ValidationMessageParser } from './implementation/validation-message-parser';
import { PropertyAccessorParser } from './property-accessor-parser';
import { ValidationRules } from './implementation/validation-rules';
@@ -47,7 +47,7 @@ import { ValidationRendererCustomAttribute } from './validation-renderer-custom-
export function configure(
// tslint:disable-next-line:ban-types
frameworkConfig: { container: Container, globalResources?: (...resources: any[]) => any },
callback?: (config: AureliaValidationConfiguration) => void
callback?: (config: GlobalValidationConfiguration) => void
) {
// the fluent rule definition API needs the parser to translate messages
// to interpolation expressions.
@@ -56,7 +56,7 @@ export function configure(
ValidationRules.initialize(messageParser, propertyParser);

// configure...
const config = new AureliaValidationConfiguration();
const config = new GlobalValidationConfiguration();
if (callback instanceof Function) {
callback(config);
}
@@ -6,11 +6,11 @@ import { validateTrigger } from './validate-trigger';
/**
* Aurelia Validation Configuration API
*/
export class AureliaValidationConfiguration {
export class GlobalValidationConfiguration {
public static DEFAULT_VALIDATION_TRIGGER = validateTrigger.blur;

private validatorType: { new (...args: any[]): Validator } = StandardValidator;
private validationTrigger = AureliaValidationConfiguration.DEFAULT_VALIDATION_TRIGGER;
private validationTrigger = GlobalValidationConfiguration.DEFAULT_VALIDATION_TRIGGER;

/**
* Use a custom Validator implementation.
@@ -33,6 +33,6 @@ export class AureliaValidationConfiguration {
public apply(container: Container) {
const validator = container.get(this.validatorType);
container.registerInstance(Validator, validator);
container.registerInstance(AureliaValidationConfiguration, this);
container.registerInstance(GlobalValidationConfiguration, this);
}
}
@@ -1,5 +1,5 @@
import { Container } from 'aurelia-dependency-injection';
import { AureliaValidationConfiguration } from './config';
import { GlobalValidationConfiguration } from './config';
import { ValidationController } from './validation-controller';
import { Validator } from './validator';
import { PropertyAccessorParser } from './property-accessor-parser';
@@ -22,7 +22,7 @@ export class ValidationControllerFactory {
validator = this.container.get(Validator) as Validator;
}
const propertyParser = this.container.get(PropertyAccessorParser) as PropertyAccessorParser;
const config = this.container.get(AureliaValidationConfiguration) as AureliaValidationConfiguration;
const config = this.container.get(GlobalValidationConfiguration) as GlobalValidationConfiguration;
return new ValidationController(validator, propertyParser, config);
}

@@ -1,5 +1,5 @@
import { Binding, Expression } from 'aurelia-binding';
import { AureliaValidationConfiguration } from './config';
import { GlobalValidationConfiguration } from './config';
import { Validator } from './validator';
import { validateTrigger } from './validate-trigger';
import { getPropertyInfo } from './property-info';
@@ -16,7 +16,7 @@ import { ValidateEvent } from './validate-event';
* Exposes the current list of validation results for binding purposes.
*/
export class ValidationController {
public static inject = [Validator, PropertyAccessorParser, AureliaValidationConfiguration];
public static inject = [Validator, PropertyAccessorParser, GlobalValidationConfiguration];

// Registered bindings (via the validate binding behavior)
private bindings = new Map<Binding, BindingInfo>();
@@ -58,11 +58,11 @@ export class ValidationController {
constructor(
private validator: Validator,
private propertyParser: PropertyAccessorParser,
config?: AureliaValidationConfiguration,
config?: GlobalValidationConfiguration,
) {
this.validateTrigger = config instanceof AureliaValidationConfiguration
this.validateTrigger = config instanceof GlobalValidationConfiguration
? config.getDefaultValidationTrigger()
: AureliaValidationConfiguration.DEFAULT_VALIDATION_TRIGGER;
: GlobalValidationConfiguration.DEFAULT_VALIDATION_TRIGGER;
}

/**
@@ -1,6 +1,6 @@
import { Container, Optional } from 'aurelia-dependency-injection';
import {
AureliaValidationConfiguration,
GlobalValidationConfiguration,
ValidationControllerFactory,
ValidationController,
Validator,
@@ -12,9 +12,9 @@ describe('ValidationControllerFactory', () => {
const container = new Container();
const standardValidator = {};
container.registerInstance(Validator, standardValidator);
const config = new AureliaValidationConfiguration();
const config = new GlobalValidationConfiguration();
config.defaultValidationTrigger(validateTrigger.manual);
container.registerInstance(AureliaValidationConfiguration, config);
container.registerInstance(GlobalValidationConfiguration, config);
const childContainer = container.createChild();
const factory = childContainer.get(ValidationControllerFactory);
const controller = factory.createForCurrentScope();
@@ -1,5 +1,5 @@
import {
AureliaValidationConfiguration,
GlobalValidationConfiguration,
PropertyAccessorParser,
ValidationController,
Validator,
@@ -11,10 +11,10 @@ describe('ValidationController', () => {
const validator = {} as any as Validator;
const parser = {} as any as PropertyAccessorParser;
const controller = new ValidationController(validator, parser);
expect(controller.validateTrigger).toBe(AureliaValidationConfiguration.DEFAULT_VALIDATION_TRIGGER);
expect(controller.validateTrigger).toBe(GlobalValidationConfiguration.DEFAULT_VALIDATION_TRIGGER);

const trigger = validateTrigger.changeOrBlur;
const config = new AureliaValidationConfiguration();
const config = new GlobalValidationConfiguration();
config.defaultValidationTrigger(trigger);
const controllerWithConfig = new ValidationController(validator, parser, config);
expect(controllerWithConfig.validateTrigger).toBe(trigger);

0 comments on commit c4e5fe2

Please sign in to comment.
You can’t perform that action at this time.