I am creating a NativeScript plugin that wrap a Swift CocoaPod lib.
In my NativeScript plugin, I am using a separate class to add required delegate to main class.
Will it be possible to implement delegate methods in main class and avoid the delegate class completely?
i.e.,
export class MicrosoftBandService extends NSObject implements ConnectionDelegate {
static new(): MicrosoftBandService {
return <MicrosoftBandService>super.new()
}
constructor() {
let _self= this;
this.mbk = MicrosoftBand.alloc().init();
this.mbk.connectDelegate = _self
}
onConnecte() {
//
onDisconnecte() {
//
}
onErrorWithError(error) {
//
}
}
even better, I like to do like this
export class MicrosoftBandService extends MicrosoftBand implements ConnectionDelegate {
static new(): MicrosoftBandService {
return <MicrosoftBandService>super.new()
}
constructor() {
let _self= this;
this.connectDelegate = _self
}
onConnecte() {
//
}
onDisconnecte() {
//
}
onErrorWithError(error) {
//
}
}
I don't know proper syntax to implement constructor with self delegate in TypeScript for NativeScript
My current code works, but I am looking for help to simplify and reduce code by eliminating separate delegate class.