Following on from Trouble migrating from Au1 to Au2 where certain technical APIs are being utilized, I have made tremendous progress. The last sticking point, I think, is the difference between the configuration object supplied to Au2’s #enhance
and the configuration object supplied to Au1’s #enhance
. If I can wrangle this, I’ll be able to do a full write-up here on Discourse that discusses the migration path.
Specifically, how do we migrate
const view = this.templatingEngine.enhance({
element: element,
bindingContext: itemBindingContext,
overrideContext: itemOverrideContext,
resources: viewResources,
});
to this
this.au.enhance({
component: { items: this.items },
host: itemList,
});
Explanation of the references is the former (what follows is Au1 code):
- element: markup that looks like this:
<dx-template name="content">A Button</dx-template>
. - bindingContext: from
scope.bindingContext
. - overrideContext: from
scope.overrideContext
. - resources:
scope.owningView.resources
.
The scope
, as used above, is passed down from the third-party component wrapper (written by me) and defined as
bind(bindingContext, overrideContext) {
super.binding();
const scope = {
owningView: this.owningView,
bindingContext: bindingContext,
overrideContext: overrideContext,
};
...
}
where this.owningView
originates in Aurelia’s created
hook of the wrapper. I store it on the wrapper’s instance.
Finally, as you can see from the Au1 code, I need to get back a view. The reason for that is that right after the call to templatingEngine.enhance
, I have to do this:
// Register a Dx remove event, dxremove, so that we have an opportunity
// to call the Aurelia "destroy" lifecycle callbacks (careful to call
// #detach first, then #unbind)
dxEventOn(newElement, 'dxremove', () => {
view.detached();
view.unbind();
});
where newElement
is simply a clone of the dx-template
that gets appended to the rendering container provided by the third-party component (the rendering container shouldn’t be relevant in Au2 as it isn’t in Au1, either). I’m already aware that the lifecycle hooks have different names. Most likely, this will become:
// Register a Dx remove event, dxremove, so that we have an opportunity
// to call the Aurelia "destroy" lifecycle callbacks (careful to call
// #detach first, then #unbind)
dxEventOn(newElement, 'dxremove', () => {
view.detaching();
view.unbinding();
});
if, indeed, Au2 offers view parity with IEnhancedView
.