From 2207bdf587a38aeea51200a430e9474c6d94482e Mon Sep 17 00:00:00 2001 From: Aluan Haddad Date: Mon, 12 Feb 2018 18:05:40 -0500 Subject: [PATCH] Added the BindablePropertyConfig interface * describes the configuration object that can be passed to customize the bindable decorator and the BindableProperty class * used the interface type appropriate * fixed a few minor typos (spelling) * built and ran tests (+1 squashed commits) --- src/bindable-property.js | 14 +++++++------- src/decorators.js | 8 ++++---- src/interfaces.js | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/bindable-property.js b/src/bindable-property.js index 4cb134d2..a7749ceb 100644 --- a/src/bindable-property.js +++ b/src/bindable-property.js @@ -33,9 +33,9 @@ function getObserver(instance, name) { export class BindableProperty { /** * Creates an instance of BindableProperty. - * @param nameOrConfig The name of the property or a cofiguration object. + * @param nameOrConfig The name of the property or a configuration object. */ - constructor(nameOrConfig: string | Object) { + constructor(nameOrConfig: string | BindablePropertyConfig) { if (typeof nameOrConfig === 'string') { this.name = nameOrConfig; } else { @@ -219,11 +219,11 @@ export class BindableProperty { } observer = observerLookup[name] = new BehaviorPropertyObserver( - this.owner.taskQueue, - viewModel, - name, - selfSubscriber - ); + this.owner.taskQueue, + viewModel, + name, + selfSubscriber + ); Object.defineProperty(viewModel, name, { configurable: true, diff --git a/src/decorators.js b/src/decorators.js index 083b6955..4d730fe7 100644 --- a/src/decorators.js +++ b/src/decorators.js @@ -58,7 +58,7 @@ export function customElement(name: string): any { * @param defaultBindingMode The default binding mode to use when the attribute is bound with .bind. * @param aliases The array of aliases to associate to the custom attribute. */ -export function customAttribute(name: string, defaultBindingMode?: number, aliases?: string[]): any { +export function customAttribute(name: string, defaultBindingMode?: bindingMode, aliases?: string[]): any { return function(target) { let r = metadata.getOrCreateOwn(metadata.resource, HtmlBehaviorResource, target); r.attributeName = validateBehaviorName(name, 'custom attribute'); @@ -85,7 +85,7 @@ export function templateController(target?): any { * Decorator: Specifies that a property is bindable through HTML. * @param nameOrConfigOrTarget The name of the property, or a configuration object. */ -export function bindable(nameOrConfigOrTarget?: string | Object, key?, descriptor?): any { +export function bindable(nameOrConfigOrTarget?: string | BindablePropertyConfig, key?, descriptor?): any { let deco = function(target, key2, descriptor2) { let actualTarget = key2 ? target.constructor : target; //is it on a property or a class? let r = metadata.getOrCreateOwn(metadata.resource, HtmlBehaviorResource, actualTarget); @@ -224,14 +224,14 @@ export function useView(path: string): any { * @param dependencies A list of dependencies that the template has. * @param dependencyBaseUrl A base url from which the dependencies will be loaded. */ -export function inlineView(markup:string, dependencies?:Array, dependencyBaseUrl?:string): any { +export function inlineView(markup: string, dependencies?: Array, dependencyBaseUrl?: string): any { return useViewStrategy(new InlineViewStrategy(markup, dependencies, dependencyBaseUrl)); } /** * Decorator: Indicates that the component has no view. */ -export function noView(targetOrDependencies?:Function|Array, dependencyBaseUrl?:string): any { +export function noView(targetOrDependencies?: Function | Array, dependencyBaseUrl?: string): any { let target; let dependencies; if (typeof targetOrDependencies === 'function') { diff --git a/src/interfaces.js b/src/interfaces.js index 8d6dbd88..ab4d7dc9 100644 --- a/src/interfaces.js +++ b/src/interfaces.js @@ -1,3 +1,4 @@ +import {bindingMode} from 'aurelia-binding'; import {View} from './view'; import {ViewStrategy} from './view-strategy'; @@ -67,3 +68,21 @@ interface DynamicComponentGetViewStrategy { */ getViewStrategy(): string|ViewStrategy; } + +/** +* An optional interface describing the configuration object that can be specified to customize bindable properties. +*/ +interface BindablePropertyConfig { + /** + * The default binding mode of the property. + */ + defaultBindingMode?: bindingMode; + /** + * The name of a view model method to invoke when the property is updated. + */ + changeHandler?: string; + /** + * The name of the property. + */ + name?: string; +}