Skip to content

Commit 506d704

Browse files
committed
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 parent 8219ac3 commit 506d704

File tree

8 files changed

+92
-46
lines changed

8 files changed

+92
-46
lines changed

dist/aurelia-templating.d.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ import {
2424
import {
2525
Binding,
2626
createOverrideContext,
27+
bindingMode,
2728
ValueConverterResource,
2829
BindingBehaviorResource,
2930
subscriberCollection,
30-
bindingMode,
3131
ObserverLocator,
3232
EventManager
3333
} from 'aurelia-binding';
@@ -238,6 +238,30 @@ export declare interface DynamicComponentGetViewStrategy {
238238
getViewStrategy(): string | ViewStrategy;
239239
}
240240

241+
/**
242+
* An optional interface describing the configuration object that can be specified to customize bindable properties.
243+
*/
244+
/**
245+
* An optional interface describing the configuration object that can be specified to customize bindable properties.
246+
*/
247+
export declare interface BindablePropertyConfig {
248+
249+
/**
250+
* The default binding mode of the property.
251+
*/
252+
defaultBindingMode?: bindingMode;
253+
254+
/**
255+
* The name of a view model method to invoke when the property is updated.
256+
*/
257+
changeHandler?: string;
258+
259+
/**
260+
* The name of the property.
261+
*/
262+
name?: string;
263+
}
264+
241265
/**
242266
* Instructs the composition engine how to dynamically compose a component.
243267
*/
@@ -1673,9 +1697,9 @@ export declare class BindableProperty {
16731697

16741698
/**
16751699
* Creates an instance of BindableProperty.
1676-
* @param nameOrConfig The name of the property or a cofiguration object.
1700+
* @param nameOrConfig The name of the property or a configuration object.
16771701
*/
1678-
constructor(nameOrConfig: string | Object);
1702+
constructor(nameOrConfig: string | BindablePropertyConfig);
16791703

16801704
/**
16811705
* Registers this bindable property with particular Class and Behavior instance.
@@ -1876,7 +1900,7 @@ export declare function customElement(name: string): any;
18761900
* @param defaultBindingMode The default binding mode to use when the attribute is bound with .bind.
18771901
* @param aliases The array of aliases to associate to the custom attribute.
18781902
*/
1879-
export declare function customAttribute(name: string, defaultBindingMode?: number, aliases?: string[]): any;
1903+
export declare function customAttribute(name: string, defaultBindingMode?: bindingMode, aliases?: string[]): any;
18801904

18811905
/**
18821906
* Decorator: Applied to custom attributes. Indicates that whatever element the
@@ -1889,7 +1913,7 @@ export declare function templateController(target?: any): any;
18891913
* Decorator: Specifies that a property is bindable through HTML.
18901914
* @param nameOrConfigOrTarget The name of the property, or a configuration object.
18911915
*/
1892-
export declare function bindable(nameOrConfigOrTarget?: string | Object, key?: any, descriptor?: any): any;
1916+
export declare function bindable(nameOrConfigOrTarget?: string | BindablePropertyConfig, key?: any, descriptor?: any): any;
18931917

18941918
/**
18951919
* Decorator: Specifies that the decorated custom attribute has options that

dist/aurelia-templating.js

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {DOM,PLATFORM,FEATURE} from 'aurelia-pal';
44
import {relativeToFile} from 'aurelia-path';
55
import {TemplateRegistryEntry,Loader} from 'aurelia-loader';
66
import {inject,Container,resolver} from 'aurelia-dependency-injection';
7-
import {Binding,createOverrideContext,ValueConverterResource,BindingBehaviorResource,subscriberCollection,bindingMode,ObserverLocator,EventManager} from 'aurelia-binding';
7+
import {Binding,createOverrideContext,bindingMode,ValueConverterResource,BindingBehaviorResource,subscriberCollection,ObserverLocator,EventManager} from 'aurelia-binding';
88
import {TaskQueue} from 'aurelia-task-queue';
99

1010
/**
@@ -2177,6 +2177,24 @@ interface DynamicComponentGetViewStrategy {
21772177
getViewStrategy(): string|ViewStrategy;
21782178
}
21792179

2180+
/**
2181+
* An optional interface describing the configuration object that can be specified to customize bindable properties.
2182+
*/
2183+
interface BindablePropertyConfig {
2184+
/**
2185+
* The default binding mode of the property.
2186+
*/
2187+
defaultBindingMode?: bindingMode;
2188+
/**
2189+
* The name of a view model method to invoke when the property is updated.
2190+
*/
2191+
changeHandler?: string;
2192+
/**
2193+
* The name of the property.
2194+
*/
2195+
name?: string;
2196+
}
2197+
21802198
function getAnimatableElement(view) {
21812199
if (view.animatableElement !== undefined) {
21822200
return view.animatableElement;
@@ -4520,9 +4538,9 @@ function getObserver(instance, name) {
45204538
export class BindableProperty {
45214539
/**
45224540
* Creates an instance of BindableProperty.
4523-
* @param nameOrConfig The name of the property or a cofiguration object.
4541+
* @param nameOrConfig The name of the property or a configuration object.
45244542
*/
4525-
constructor(nameOrConfig: string | Object) {
4543+
constructor(nameOrConfig: string | BindablePropertyConfig) {
45264544
if (typeof nameOrConfig === 'string') {
45274545
this.name = nameOrConfig;
45284546
} else {
@@ -4706,11 +4724,11 @@ export class BindableProperty {
47064724
}
47074725

47084726
observer = observerLookup[name] = new BehaviorPropertyObserver(
4709-
this.owner.taskQueue,
4710-
viewModel,
4711-
name,
4712-
selfSubscriber
4713-
);
4727+
this.owner.taskQueue,
4728+
viewModel,
4729+
name,
4730+
selfSubscriber
4731+
);
47144732

47154733
Object.defineProperty(viewModel, name, {
47164734
configurable: true,
@@ -5759,7 +5777,7 @@ function validateBehaviorName(name, type) {
57595777
* @param instance The resource instance.
57605778
*/
57615779
export function resource(instance: Object): any {
5762-
return function(target) {
5780+
return function (target) {
57635781
metadata.define(metadata.resource, instance, target);
57645782
};
57655783
}
@@ -5796,8 +5814,8 @@ export function customElement(name: string): any {
57965814
* @param defaultBindingMode The default binding mode to use when the attribute is bound with .bind.
57975815
* @param aliases The array of aliases to associate to the custom attribute.
57985816
*/
5799-
export function customAttribute(name: string, defaultBindingMode?: number, aliases?: string[]): any {
5800-
return function(target) {
5817+
export function customAttribute(name: string, defaultBindingMode?: bindingMode, aliases?: string[]): any {
5818+
return function (target) {
58015819
let r = metadata.getOrCreateOwn(metadata.resource, HtmlBehaviorResource, target);
58025820
r.attributeName = validateBehaviorName(name, 'custom attribute');
58035821
r.attributeDefaultBindingMode = defaultBindingMode;
@@ -5823,7 +5841,7 @@ export function templateController(target?): any {
58235841
* Decorator: Specifies that a property is bindable through HTML.
58245842
* @param nameOrConfigOrTarget The name of the property, or a configuration object.
58255843
*/
5826-
export function bindable(nameOrConfigOrTarget?: string | Object, key?, descriptor?): any {
5844+
export function bindable(nameOrConfigOrTarget?: string | BindablePropertyConfig, key?, descriptor?): any {
58275845
let deco = function(target, key2, descriptor2) {
58285846
let actualTarget = key2 ? target.constructor : target; //is it on a property or a class?
58295847
let r = metadata.getOrCreateOwn(metadata.resource, HtmlBehaviorResource, actualTarget);
@@ -5929,7 +5947,7 @@ export function processContent(processor: boolean | Function): any {
59295947
* element container.
59305948
*/
59315949
export function containerless(target?): any {
5932-
let deco = function(t) {
5950+
let deco = function (t) {
59335951
let r = metadata.getOrCreateOwn(metadata.resource, HtmlBehaviorResource, t);
59345952
r.containerless = true;
59355953
};
@@ -5962,14 +5980,14 @@ export function useView(path: string): any {
59625980
* @param dependencies A list of dependencies that the template has.
59635981
* @param dependencyBaseUrl A base url from which the dependencies will be loaded.
59645982
*/
5965-
export function inlineView(markup:string, dependencies?:Array<string|Function|Object>, dependencyBaseUrl?:string): any {
5983+
export function inlineView(markup: string, dependencies?: Array<string | Function | Object>, dependencyBaseUrl?: string): any {
59665984
return useViewStrategy(new InlineViewStrategy(markup, dependencies, dependencyBaseUrl));
59675985
}
59685986

59695987
/**
59705988
* Decorator: Indicates that the component has no view.
59715989
*/
5972-
export function noView(targetOrDependencies?:Function|Array<any>, dependencyBaseUrl?:string): any {
5990+
export function noView(targetOrDependencies?: Function | Array<any>, dependencyBaseUrl?: string): any {
59735991
let target;
59745992
let dependencies;
59755993
if (typeof targetOrDependencies === 'function') {

dist/es2015/aurelia-templating.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { DOM, PLATFORM, FEATURE } from 'aurelia-pal';
66
import { relativeToFile } from 'aurelia-path';
77
import { TemplateRegistryEntry, Loader } from 'aurelia-loader';
88
import { inject, Container, resolver } from 'aurelia-dependency-injection';
9-
import { Binding, createOverrideContext, ValueConverterResource, BindingBehaviorResource, subscriberCollection, bindingMode, ObserverLocator, EventManager } from 'aurelia-binding';
9+
import { Binding, createOverrideContext, bindingMode, ValueConverterResource, BindingBehaviorResource, subscriberCollection, ObserverLocator, EventManager } from 'aurelia-binding';
1010
import { TaskQueue } from 'aurelia-task-queue';
1111

1212
export const animationEvent = {
@@ -630,7 +630,7 @@ export let ViewLocator = (_temp2 = _class7 = class ViewLocator {
630630
}, _class7.viewStrategyMetadataKey = 'aurelia:view-strategy', _temp2);
631631

632632
function mi(name) {
633-
throw new Error(`BindingLanguage must implement ${ name }().`);
633+
throw new Error(`BindingLanguage must implement ${name}().`);
634634
}
635635

636636
export let BindingLanguage = class BindingLanguage {
@@ -1060,7 +1060,7 @@ function register(lookup, name, resource, type) {
10601060
let existing = lookup[name];
10611061
if (existing) {
10621062
if (existing !== resource) {
1063-
throw new Error(`Attempted to register ${ type } when one with the same name already exists. Name: ${ name }.`);
1063+
throw new Error(`Attempted to register ${type} when one with the same name already exists. Name: ${name}.`);
10641064
}
10651065

10661066
return;
@@ -2998,7 +2998,7 @@ export let ViewEngine = (_dec8 = inject(Loader, Container, ViewCompiler, ModuleA
29982998

29992999
importIds = dependencies.map(x => x.src);
30003000
names = dependencies.map(x => x.name);
3001-
logger.debug(`importing resources for ${ registryEntry.address }`, importIds);
3001+
logger.debug(`importing resources for ${registryEntry.address}`, importIds);
30023002

30033003
if (target) {
30043004
let viewModelRequires = metadata.get(ViewEngine.viewModelRequireMetadataKey, target);
@@ -3013,7 +3013,7 @@ export let ViewEngine = (_dec8 = inject(Loader, Container, ViewCompiler, ModuleA
30133013
names.push(req.as);
30143014
}
30153015
}
3016-
logger.debug(`importing ViewModel resources for ${ compileInstruction.associatedModuleId }`, importIds.slice(templateImportCount));
3016+
logger.debug(`importing ViewModel resources for ${compileInstruction.associatedModuleId}`, importIds.slice(templateImportCount));
30173017
}
30183018
}
30193019

@@ -3026,7 +3026,7 @@ export let ViewEngine = (_dec8 = inject(Loader, Container, ViewCompiler, ModuleA
30263026
let resourceModule = this.moduleAnalyzer.analyze(normalizedId, viewModelModule, moduleMember);
30273027

30283028
if (!resourceModule.mainResource) {
3029-
throw new Error(`No view model found in module "${ moduleImport }".`);
3029+
throw new Error(`No view model found in module "${moduleImport}".`);
30303030
}
30313031

30323032
resourceModule.initialize(this.container);
@@ -3442,7 +3442,7 @@ export let BindableProperty = class BindableProperty {
34423442
} else if ('propertyChanged' in viewModel) {
34433443
selfSubscriber = (newValue, oldValue) => viewModel.propertyChanged(name, newValue, oldValue);
34443444
} else if (changeHandlerName !== null) {
3445-
throw new Error(`Change handler ${ changeHandlerName } was specified but not declared on the class.`);
3445+
throw new Error(`Change handler ${changeHandlerName} was specified but not declared on the class.`);
34463446
}
34473447

34483448
if (defaultValue !== undefined) {
@@ -4353,7 +4353,7 @@ export let ElementConfigResource = class ElementConfigResource {
43534353
function validateBehaviorName(name, type) {
43544354
if (/[A-Z]/.test(name)) {
43554355
let newName = _hyphenate(name);
4356-
LogManager.getLogger('templating').warn(`'${ name }' is not a valid ${ type } name and has been converted to '${ newName }'. Upper-case letters are not allowed because the DOM is not case-sensitive.`);
4356+
LogManager.getLogger('templating').warn(`'${name}' is not a valid ${type} name and has been converted to '${newName}'. Upper-case letters are not allowed because the DOM is not case-sensitive.`);
43574357
return newName;
43584358
}
43594359
return name;

dist/native-modules/aurelia-templating.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { DOM, PLATFORM, FEATURE } from 'aurelia-pal';
1212
import { relativeToFile } from 'aurelia-path';
1313
import { TemplateRegistryEntry, Loader } from 'aurelia-loader';
1414
import { inject, Container, resolver } from 'aurelia-dependency-injection';
15-
import { Binding, createOverrideContext, ValueConverterResource, BindingBehaviorResource, subscriberCollection, bindingMode, ObserverLocator, EventManager } from 'aurelia-binding';
15+
import { Binding, createOverrideContext, bindingMode, ValueConverterResource, BindingBehaviorResource, subscriberCollection, ObserverLocator, EventManager } from 'aurelia-binding';
1616
import { TaskQueue } from 'aurelia-task-queue';
1717

1818
export var animationEvent = {

dist/system/aurelia-templating.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
System.register(['aurelia-logging', 'aurelia-metadata', 'aurelia-pal', 'aurelia-path', 'aurelia-loader', 'aurelia-dependency-injection', 'aurelia-binding', 'aurelia-task-queue'], function (_export, _context) {
44
"use strict";
55

6-
var LogManager, metadata, Origin, protocol, DOM, PLATFORM, FEATURE, relativeToFile, TemplateRegistryEntry, Loader, inject, Container, resolver, Binding, createOverrideContext, ValueConverterResource, BindingBehaviorResource, subscriberCollection, bindingMode, ObserverLocator, EventManager, TaskQueue, _createClass, _typeof, _class, _temp, _dec, _class2, _dec2, _class3, _dec3, _class4, _dec4, _class5, _dec5, _class6, _class7, _temp2, _dec6, _class8, _class9, _temp3, _class11, _dec7, _class13, _dec8, _class14, _class15, _temp4, _dec9, _class16, _dec10, _class17, _dec11, _class18, animationEvent, Animator, CompositionTransactionNotifier, CompositionTransactionOwnershipToken, CompositionTransaction, capitalMatcher, ViewEngineHooksResource, ElementEvents, EventHandlerImpl, ResourceLoadContext, ViewCompileInstruction, BehaviorInstruction, TargetInstruction, viewStrategy, RelativeViewStrategy, ConventionalViewStrategy, NoViewStrategy, TemplateRegistryViewStrategy, InlineViewStrategy, ViewLocator, BindingLanguage, noNodes, SlotCustomAttribute, PassThroughSlot, ShadowSlot, ShadowDOM, ViewResources, View, ViewSlot, ProviderResolver, providerResolverInstance, BoundViewFactory, ViewFactory, nextInjectorId, lastAUTargetID, ViewCompiler, ResourceModule, ResourceDescription, ModuleAnalyzer, logger, ProxyViewFactory, auSlotBehavior, ViewEngine, Controller, BehaviorPropertyObserver, BindableProperty, lastProviderId, HtmlBehaviorResource, ChildObserver, noMutations, ChildObserverBinder, SwapStrategies, CompositionEngine, ElementConfigResource, defaultShadowDOMOptions, TemplatingEngine;
6+
var LogManager, metadata, Origin, protocol, DOM, PLATFORM, FEATURE, relativeToFile, TemplateRegistryEntry, Loader, inject, Container, resolver, Binding, createOverrideContext, bindingMode, ValueConverterResource, BindingBehaviorResource, subscriberCollection, ObserverLocator, EventManager, TaskQueue, _createClass, _typeof, _class, _temp, _dec, _class2, _dec2, _class3, _dec3, _class4, _dec4, _class5, _dec5, _class6, _class7, _temp2, _dec6, _class8, _class9, _temp3, _class11, _dec7, _class13, _dec8, _class14, _class15, _temp4, _dec9, _class16, _dec10, _class17, _dec11, _class18, animationEvent, Animator, CompositionTransactionNotifier, CompositionTransactionOwnershipToken, CompositionTransaction, capitalMatcher, ViewEngineHooksResource, ElementEvents, EventHandlerImpl, ResourceLoadContext, ViewCompileInstruction, BehaviorInstruction, TargetInstruction, viewStrategy, RelativeViewStrategy, ConventionalViewStrategy, NoViewStrategy, TemplateRegistryViewStrategy, InlineViewStrategy, ViewLocator, BindingLanguage, noNodes, SlotCustomAttribute, PassThroughSlot, ShadowSlot, ShadowDOM, ViewResources, View, ViewSlot, ProviderResolver, providerResolverInstance, BoundViewFactory, ViewFactory, nextInjectorId, lastAUTargetID, ViewCompiler, ResourceModule, ResourceDescription, ModuleAnalyzer, logger, ProxyViewFactory, auSlotBehavior, ViewEngine, Controller, BehaviorPropertyObserver, BindableProperty, lastProviderId, HtmlBehaviorResource, ChildObserver, noMutations, ChildObserverBinder, SwapStrategies, CompositionEngine, ElementConfigResource, defaultShadowDOMOptions, TemplatingEngine;
77

88

99

@@ -735,10 +735,10 @@ System.register(['aurelia-logging', 'aurelia-metadata', 'aurelia-pal', 'aurelia-
735735
}, function (_aureliaBinding) {
736736
Binding = _aureliaBinding.Binding;
737737
createOverrideContext = _aureliaBinding.createOverrideContext;
738+
bindingMode = _aureliaBinding.bindingMode;
738739
ValueConverterResource = _aureliaBinding.ValueConverterResource;
739740
BindingBehaviorResource = _aureliaBinding.BindingBehaviorResource;
740741
subscriberCollection = _aureliaBinding.subscriberCollection;
741-
bindingMode = _aureliaBinding.bindingMode;
742742
ObserverLocator = _aureliaBinding.ObserverLocator;
743743
EventManager = _aureliaBinding.EventManager;
744744
}, function (_aureliaTaskQueue) {

src/bindable-property.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ function getObserver(instance, name) {
3333
export class BindableProperty {
3434
/**
3535
* Creates an instance of BindableProperty.
36-
* @param nameOrConfig The name of the property or a cofiguration object.
36+
* @param nameOrConfig The name of the property or a configuration object.
3737
*/
38-
constructor(nameOrConfig: string | Object) {
38+
constructor(nameOrConfig: string | BindablePropertyConfig) {
3939
if (typeof nameOrConfig === 'string') {
4040
this.name = nameOrConfig;
4141
} else {
@@ -219,11 +219,11 @@ export class BindableProperty {
219219
}
220220

221221
observer = observerLookup[name] = new BehaviorPropertyObserver(
222-
this.owner.taskQueue,
223-
viewModel,
224-
name,
225-
selfSubscriber
226-
);
222+
this.owner.taskQueue,
223+
viewModel,
224+
name,
225+
selfSubscriber
226+
);
227227

228228
Object.defineProperty(viewModel, name, {
229229
configurable: true,

src/decorators.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export function customElement(name: string): any {
5858
* @param defaultBindingMode The default binding mode to use when the attribute is bound with .bind.
5959
* @param aliases The array of aliases to associate to the custom attribute.
6060
*/
61-
export function customAttribute(name: string, defaultBindingMode?: number, aliases?: string[]): any {
61+
export function customAttribute(name: string, defaultBindingMode?: bindingMode, aliases?: string[]): any {
6262
return function(target) {
6363
let r = metadata.getOrCreateOwn(metadata.resource, HtmlBehaviorResource, target);
6464
r.attributeName = validateBehaviorName(name, 'custom attribute');
@@ -85,7 +85,7 @@ export function templateController(target?): any {
8585
* Decorator: Specifies that a property is bindable through HTML.
8686
* @param nameOrConfigOrTarget The name of the property, or a configuration object.
8787
*/
88-
export function bindable(nameOrConfigOrTarget?: string | Object, key?, descriptor?): any {
88+
export function bindable(nameOrConfigOrTarget?: string | BindablePropertyConfig, key?, descriptor?): any {
8989
let deco = function(target, key2, descriptor2) {
9090
let actualTarget = key2 ? target.constructor : target; //is it on a property or a class?
9191
let r = metadata.getOrCreateOwn(metadata.resource, HtmlBehaviorResource, actualTarget);
@@ -191,7 +191,7 @@ export function processContent(processor: boolean | Function): any {
191191
* element container.
192192
*/
193193
export function containerless(target?): any {
194-
let deco = function(t) {
194+
let deco = function (t) {
195195
let r = metadata.getOrCreateOwn(metadata.resource, HtmlBehaviorResource, t);
196196
r.containerless = true;
197197
};
@@ -224,14 +224,14 @@ export function useView(path: string): any {
224224
* @param dependencies A list of dependencies that the template has.
225225
* @param dependencyBaseUrl A base url from which the dependencies will be loaded.
226226
*/
227-
export function inlineView(markup:string, dependencies?:Array<string|Function|Object>, dependencyBaseUrl?:string): any {
227+
export function inlineView(markup: string, dependencies?: Array<string | Function | Object>, dependencyBaseUrl?: string): any {
228228
return useViewStrategy(new InlineViewStrategy(markup, dependencies, dependencyBaseUrl));
229229
}
230230

231231
/**
232232
* Decorator: Indicates that the component has no view.
233233
*/
234-
export function noView(targetOrDependencies?:Function|Array<any>, dependencyBaseUrl?:string): any {
234+
export function noView(targetOrDependencies?: Function | Array<any>, dependencyBaseUrl?: string): any {
235235
let target;
236236
let dependencies;
237237
if (typeof targetOrDependencies === 'function') {

0 commit comments

Comments
 (0)