Failed to extend with the initialize Method
I tried to run the example code and it keep prompted error of "Cannot read property 'push' of undefined". I have tried to dumb this whole object and cannot find the cachedRecords and cachedRecordsSize defined in the initialize method. After closer inspection, I have found a log line notifying for no initialize method defined.
My current work around is to directly define this two attributes in the default initialize method.
Could you please fix this?
In current code the abstract class's initialize() function is executed before it is replaced by the custom extend() function. Therefore it always report the missing function.
I modify the the source code here like this to make the overwriting work:
public static extend(args: ConsumerExtension) {
const opts = JSON.parse(process.env.CONSUMER_INSTANCE_OPTS)
class Consumer extends AbstractConsumer {
constructor() {
AbstractConsumer.ABSTRACT_METHODS
.filter(method => {
console.log('see method', method, args[method])
return args[method]
})
.forEach(method => {
console.log('setup:', method)
this[method] = args[method]
})
super(opts)
}
// new code to make sure the initialize() is overwritten
public initialize(callback: (err?: Error) => void) {
if (args.initialize) {
args.initialize(callback)
} else {
super.initialize(callback)
}
}
}
new Consumer()
}
I don't think it is the best fix and I will think about a better solution latter.