Skip to content

Commit

Permalink
fix: Proper param handling for x-subscriber-type: global
Browse files Browse the repository at this point in the history
  • Loading branch information
jlacivita committed Sep 12, 2023
1 parent d8b9ada commit 02204e5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions languages/javascript/src/shared/Prop/Router.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export default function (params, callbackOrValue, contextParameterCount) {
} else if (numArgs === contextParameterCount && typeof callbackOrValue === 'function') {
// subscribe
return "subscriber"
} else if (numArgs === 0 && typeof callbackOrValue === 'function') {
// for x-subscriber-type: global
return "subscriber"
} else if (numArgs === (contextParameterCount) && callbackOrValue !== undefined) {
// setter
return "setter"
Expand Down
2 changes: 1 addition & 1 deletion languages/javascript/templates/declarations/property.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
${method.params.annotations}${if.deprecated} * @deprecated ${method.deprecation}
${end.if.deprecated} */
function ${method.name}(): Promise<${method.result.type}>
function ${method.name}(${method.signature.params}): Promise<${method.result.type}>


${method.setter}
Expand Down
12 changes: 10 additions & 2 deletions languages/javascript/templates/methods/property.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
function ${method.name}(${method.params.list}) {
const callbackOrValue = arguments[${method.params.count}]
return Prop.prop('${info.title}', '${method.name}', { ${method.params.list} }, callbackOrValue, ${method.property.immutable}, ${method.property.readonly}, ${method.params.count})
let callbackOrValue = arguments[${method.params.count}]
let params = { ${method.params.list} }

// x-subscriber-type: global
if (arguments.length === 1 && (typeof arguments[0] === 'function')) {
callbackOrValue = arguments[0]
params = {}
}

return Prop.prop('${info.title}', '${method.name}', params, callbackOrValue, ${method.property.immutable}, ${method.property.readonly}, ${method.params.count})
}

0 comments on commit 02204e5

Please sign in to comment.