Thanks for your response. We are trying to convert a plugin from Au1 to Au2. We are creating the aurelia plugins using some third party javascript plugins. This decorator is used for generating the bindable properties dynamically into a custom attribute. The core javascript plugin supports certain properties, we need to create the corresponding bindable properties dynamically.Please provide a solution for converting this decorator into Au2
We have tried the below code but it’s not giving the existing container instance. (Please check the image)
constructor(private container: IContainer) {
console.log(container);
const aurelia = new Aurelia();
const rootContainer = aurelia.container;
console.log(rootContainer);
}
This is the code block used in decorator(Au1)
import {BindableProperty, HtmlBehaviorResource} from 'aurelia-templating';
import {Container} from 'aurelia-dependency-injection';
import {metadata} from 'aurelia-metadata';
import {TaskQueue} from 'aurelia-task-queue';
import { bindingMode, BindingEngine } from 'aurelia-binding';
import { Util } from './util';
export function generateBindables(controlName, inputs, twoWayProperties, abbrevProperties, observerCollection):any {
return function(target, key, descriptor) {
let behaviorResource = metadata.getOrCreateOwn(metadata.resource, HtmlBehaviorResource, target);
let container = (Container.instance || new Container());
let util = container.get(Util);
let bindingInstance = container.get(BindingEngine);
inputs.push('options');
inputs.push('widget');
let len = inputs.length;
if (observerCollection) {
target.prototype.arrayObserver = [];
observerCollection.forEach((element) => {
target.prototype.arrayObserver.push(util.getBindablePropertyName(element));
});
target.prototype.bindingInstance = bindingInstance;
}
target.prototype.controlName = controlName;
target.prototype.twoWays = twoWayProperties ? twoWayProperties : [];
target.prototype.abbrevProperties = abbrevProperties ? abbrevProperties : [];
if (len) {
target.prototype.controlProperties = inputs;
for (let i = 0; i < len; i++) {
let option = inputs[i];
if (abbrevProperties && option in abbrevProperties) {
option = abbrevProperties[option];
option.forEach((prop) => {
registerProp(util, prop, target, behaviorResource, descriptor);
});
} else {
registerProp(util, option, target, behaviorResource, descriptor);
}
}
}
};
}
function registerProp(util, option, target, behaviorResource, descriptor) {
let nameOrConfigOrTarget = {
name: util.getBindablePropertyName(option),
defaultBindingMode:null
};
let prop = new BindableProperty(nameOrConfigOrTarget);
prop.registerWith(target, behaviorResource, descriptor);
}
usage
@generateBindables('DatePicker', ['height', 'width', 'cssClass', 'dateFormat'],[],[],[])
We can’t find matching following components in Au2
import {BindableProperty, HtmlBehaviorResource} from 'aurelia-templating';
Also can’t find matching method for “getOrCreateOwn” in Au2
let behaviorResource = metadata.getOrCreateOwn(metadata.resource, HtmlBehaviorResource, target);