Skip to content

Commit

Permalink
Added the BindablePropertyConfig interface
Browse files Browse the repository at this point in the history
 * 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)
  • Loading branch information
aluanhaddad committed Feb 13, 2018
1 parent 64e73f5 commit 2207bdf
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/bindable-property.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/decorators.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);
Expand Down Expand Up @@ -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<string|Function|Object>, dependencyBaseUrl?:string): any {
export function inlineView(markup: string, dependencies?: Array<string | Function | Object>, dependencyBaseUrl?: string): any {
return useViewStrategy(new InlineViewStrategy(markup, dependencies, dependencyBaseUrl));
}

/**
* Decorator: Indicates that the component has no view.
*/
export function noView(targetOrDependencies?:Function|Array<any>, dependencyBaseUrl?:string): any {
export function noView(targetOrDependencies?: Function | Array<any>, dependencyBaseUrl?: string): any {
let target;
let dependencies;
if (typeof targetOrDependencies === 'function') {
Expand Down
19 changes: 19 additions & 0 deletions src/interfaces.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {bindingMode} from 'aurelia-binding';
import {View} from './view';
import {ViewStrategy} from './view-strategy';

Expand Down Expand Up @@ -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;
}

0 comments on commit 2207bdf

Please sign in to comment.