aurelia-kendoui-bridge
Version:
A set of Telerik KendoUI wrappers for Aurelia allowing developers to easily use KendoUI components in their Aurelia application.
59 lines (48 loc) • 2.12 kB
JavaScript
import {BindableProperty, HtmlBehaviorResource} from 'aurelia-templating';
import {Container} from 'aurelia-dependency-injection';
import {metadata} from 'aurelia-metadata';
import {bindingMode} from 'aurelia-binding';
import {TaskQueue} from 'aurelia-task-queue';
import {ControlProperties} from './control-properties';
import {Util} from './util';
/**
* Creates a BindableProperty for every option defined in a Kendo control
* in the option property of a Kendo control
* @param controlName The Kendo control of which the options should be converted into bindable properties
*/
export function generateBindables(controlName: string, extraProperties = []) {
return function(target, key, descriptor) {
// get or create the HtmlBehaviorResource
// on which we're going to create the BindableProperty's
let behaviorResource = metadata.getOrCreateOwn(metadata.resource, HtmlBehaviorResource, target);
let container = (Container.instance || new Container());
let controlProperties = container.get(ControlProperties);
let util = container.get(Util);
let optionKeys = controlProperties.getProperties(controlName, extraProperties);
optionKeys.push('widget');
optionKeys.push('options');
optionKeys.push('noInit');
for (let i = 0; i < optionKeys.length; i++) {
let option = optionKeys[i];
// set the name of the bindable property to the option
let nameOrConfigOrTarget = {
name: util.getBindablePropertyName(option)
};
if (option === 'widget') {
nameOrConfigOrTarget.defaultBindingMode = bindingMode.twoWay;
}
let prop = new BindableProperty(nameOrConfigOrTarget);
prop.registerWith(target, behaviorResource, descriptor);
}
};
}
export function delayed() {
return function(target, key, descriptor) {
let taskQueue = (Container.instance || new Container()).get(TaskQueue);
let ptr = descriptor.value;
descriptor.value = function(...args) {
taskQueue.queueTask(() => ptr.apply(this, args));
};
return descriptor;
};
}