From 6abeb86e2e8486294ec03733d898b637916c71de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Andr=C3=A9=20Vadla=20Ravn=C3=A5s?= Date: Tue, 18 May 2021 22:49:20 +0200 Subject: [PATCH] Port to the latest decorators API --- lib/service/interface.js | 66 +++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 24 deletions(-) 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; }; }