Skip to content

Commit

Permalink
functions adjustments
Browse files Browse the repository at this point in the history
only show parameters section if there are parameters
only show results if result is not `void` or user-specified
  • Loading branch information
phryneas committed Jan 22, 2024
1 parent c4c3a28 commit 1d05b70
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
48 changes: 31 additions & 17 deletions docs/shared/ApiDoc/Function.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ export function FunctionSignature({
const getItem = useApiDocContext();
const { displayName, parameters, returnType } = getItem(canonicalReference);

const signature = `${arrow ? "" : "function "}${name ? displayName : ""}(
${parameters
let paramSignature = parameters
.map((p) => {
let pStr = p.name;
if (p.optional) {
Expand All @@ -36,8 +35,15 @@ export function FunctionSignature({
}
return pStr;
})
.join(",\n ")}
)${arrow ? " =>" : ":"} ${returnType}`;
.join(",\n ");

if (paramSignature) {
paramSignature = "\n " + paramSignature + "\n";
}

const signature = `${arrow ? "" : "function "}${
name ? displayName : ""
}(${paramSignature})${arrow ? " =>" : ":"} ${returnType}`;

return highlight ?
<MDX.pre language="ts">
Expand Down Expand Up @@ -94,6 +100,8 @@ export function FunctionDetails({
headingLevel,
result,
}) {
const getItem = useApiDocContext();
const item = getItem(canonicalReference);
return (
<>
<ApiDocHeading
Expand Down Expand Up @@ -122,27 +130,33 @@ export function FunctionDetails({
highlight
/>
<SourceLink canonicalReference={canonicalReference} />
<SubHeading
canonicalReference={canonicalReference}
headingLevel={headingLevel + 1}
>
Parameters
</SubHeading>
<ParameterTable
canonicalReference={canonicalReference}
customOrder={customParameterOrder}
/>
{result === false ? null : (
{item.parameters.length == 0 ? null : (
<>
<SubHeading
canonicalReference={canonicalReference}
headingLevel={headingLevel + 1}
>
Result
Parameters
</SubHeading>
{result || <ReturnType canonicalReference={canonicalReference} />}
<ParameterTable
canonicalReference={canonicalReference}
customOrder={customParameterOrder}
/>
</>
)}
{(
result === false || (result === undefined && item.returnType === "void")
) ?
null
: <>
<SubHeading
canonicalReference={canonicalReference}
headingLevel={headingLevel + 1}
>
Result
</SubHeading>
{result || <ReturnType canonicalReference={canonicalReference} />}
</>}
</>
);
}
Expand Down
2 changes: 1 addition & 1 deletion docs/source/api/core/ObservableQuery.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { InterfaceDetails, FunctionDetails, PropertyDetails, EnumDetails } from

`ApolloClient` Observables extend the Observables implementation provided by [`zen-observable`](https://github.com/zenparsing/zen-observable). Refer to the `zen-observable` documentation for additional context and API options.

<PropertyDetails canonicalReference="@apollo/client!ObservableQuery#result:member(1)" headingLevel={3} />
<FunctionDetails canonicalReference="@apollo/client!ObservableQuery#result:member(1)" headingLevel={3} />
<FunctionDetails canonicalReference="@apollo/client!ObservableQuery#getCurrentResult:member(1)" headingLevel={3} />
<FunctionDetails canonicalReference="@apollo/client!ObservableQuery#refetch:member(1)" headingLevel={3} />
<FunctionDetails canonicalReference="@apollo/client!ObservableQuery#setOptions:member(1)" headingLevel={3} />
Expand Down

0 comments on commit 1d05b70

Please sign in to comment.