diff --git a/lib/service/interface.js b/lib/service/interface.js index d693e85..476a9b4 100644 --- a/lib/service/interface.js +++ b/lib/service/interface.js @@ -79,13 +79,18 @@ function property (options) { throw new Error('missing signature for property'); } options.signatureTree = parseSignature(options.signature); - return function (descriptor) { - options.name = options.name || descriptor.key; - assertMemberNameValid(options.name); - descriptor.finisher = function (klass) { - klass.prototype.$properties = klass.prototype.$properties || []; - klass.prototype.$properties[descriptor.key] = options; - }; + return function (target, key, descriptor) { + const name = options.name || key; + assertMemberNameValid(name); + options.name = name; + + let properties = target.$properties; + if (properties === undefined) { + properties = {}; + target.$properties = properties; + } + properties[key] = options; + return descriptor; }; } @@ -152,14 +157,20 @@ function method (options) { options.outSignature = options.outSignature || ''; options.inSignatureTree = parseSignature(options.inSignature); options.outSignatureTree = parseSignature(options.outSignature); - return function (descriptor) { - options.name = options.name || descriptor.key; - assertMemberNameValid(options.name); - options.fn = descriptor.descriptor.value; - descriptor.finisher = function (klass) { - klass.prototype.$methods = klass.prototype.$methods || []; - klass.prototype.$methods[descriptor.key] = options; - }; + + return function (target, key, descriptor) { + const name = options.name || key; + assertMemberNameValid(name); + options.name = name; + options.fn = descriptor.value; + + let methods = target.$methods; + if (methods === undefined) { + methods = {}; + target.$methods = methods; + } + methods[key] = options; + return descriptor; }; } @@ -204,21 +215,28 @@ function signal (options) { // https://stackoverflow.com/questions/1007981/how-to-get-function-parameter-names-values-dynamically options.signature = options.signature || ''; options.signatureTree = parseSignature(options.signature); - return function (descriptor) { - options.name = options.name || descriptor.key; - assertMemberNameValid(options.name); - options.fn = descriptor.descriptor.value; - descriptor.descriptor.value = function () { + + return function (target, key, descriptor) { + const name = options.name || key; + assertMemberNameValid(name); + options.name = name; + options.fn = descriptor.value; + + descriptor.value = function () { if (options.disabled) { throw new Error('tried to call a disabled signal'); } const result = options.fn.apply(this, arguments); this.$emitter.emit('signal', options, result); }; - descriptor.finisher = function (klass) { - klass.prototype.$signals = klass.prototype.$signals || []; - klass.prototype.$signals[descriptor.key] = options; - }; + + let signals = target.$signals; + if (signals === undefined) { + signals = {}; + target.$signals = signals; + } + signals[key] = options; + return descriptor; }; }