I'm not sure if there are yet any 'best practices', I really think there's only 'one' practice ;-) But I'm eager to learn any other takes, so if anyone can comment on this, please do not hesitate!
I think the general idea is just to define your event; the UI5 framework then automatically generates methods for registering (attach<YourEvent>
), deregistering (detach<YourEvent>
), and firing events (fire<YourEvent>
).
For example:
return ControlToExtend.extend("your.custom.Control", {
metadata: {
properties: {
// etc...
},
aggregations: {
"_myButton": {
type: "sap.m.Button",
multiple : false,
visibility: "hidden"
},
// etc...
},
associations: {
// etc...
},
events: {
yourCustomEvent: {
allowPreventDefault: true,
parameters: {
"passAlong": { type: "string" }
}
}
}
},
init: function() {
ControlToExntend.prototype.init.apply(this, arguments);
var oControl = this, oMyButton;
oMyButton = new Button({ // Button required from "sap/m/Button"
// ...,
press: function (oEvent) {
oControl.fireYourCustomEvent({
passAlong: "Some dummy data to pass along"
});
}
});
this.setAggregation("_myButton", oMyButton);
},
// etc...
});
Hope this explains a bit.