- {doc[0]}
+ {renderDoc}
{pathParts.map((part, idx) => [, part])}
- {renderModuleDescription(doc)}
- {renderModuleMembers(doc[0].members)}
+ {responseRenderModuleDescription}
+ {responseRenderModuleMembers}
diff --git a/src/utils/common.js b/src/utils/common.js
index b933a749..c37e1311 100644
--- a/src/utils/common.js
+++ b/src/utils/common.js
@@ -4,10 +4,10 @@ import jsonata from 'jsonata'; // http://docs.jsonata.org/
import css from '../css/main.module.less';
-export const processDefaultTag = (tags) => {
+export const processDefaultTag = async (tags) => {
// Find any tag field whose `title` is 'default' (won't be there if no default)
const expression = "$[title='default'].description";
- const result = jsonata(expression).evaluate(tags);
+ const result = await jsonata(expression).evaluate(tags);
return result || 'undefined';
};
@@ -33,16 +33,16 @@ export const renderDefaultTag = (defaultStr) => {
return
Default: {defaultStr};
};
-export const hasRequiredTag = (member) => {
+export const hasRequiredTag = async (member) => {
// Find any tag field whose `title` is 'required' (won't be there if not required)
const expression = "$[title='required']";
- const result = jsonata(expression).evaluate(member.tags);
+ const result = await jsonata(expression).evaluate(member.tags);
return !!result;
};
-export const hasDeprecatedTag = (member) => {
+export const hasDeprecatedTag = async (member) => {
// Find any tag field whose `title` is 'deprecated'
const expression = "$[title='deprecated']";
- const result = jsonata(expression).evaluate(member.tags);
+ const result = await jsonata(expression).evaluate(member.tags);
return !!result;
};
diff --git a/src/utils/functions.js b/src/utils/functions.js
index 9d0e20d1..ae4840cf 100644
--- a/src/utils/functions.js
+++ b/src/utils/functions.js
@@ -1,6 +1,8 @@
// Utilities for working with functions. Primary use is in rendering functions
// as part of /wrappers/json.js
+import {useEffect, useState} from 'react';
+
import DocParse from '../components/DocParse.js';
import FloatingAnchor from '../components/FloatingAnchor';
import jsonata from 'jsonata'; // http://docs.jsonata.org/
@@ -12,18 +14,18 @@ import {renderType, jsonataTypeParser} from './types';
import css from '../css/main.module.less';
-const processTypes = (member) => {
+const processTypes = async (member) => {
// see types.jsonataTypeParser
const expression = `$.type.[(
${jsonataTypeParser}
)]`;
- const result = jsonata(expression).evaluate(member);
+ const result = await jsonata(expression).evaluate(member);
return result || [];
};
// Pass `func.returns` for return types
-const renderTypeStrings = (member, separator) => {
- const types = processTypes(member);
+const renderTypeStrings = async (member, separator) => {
+ const types = await processTypes(member);
let typeList = types.map(renderType);
if (separator) {
// eslint-disable-next-line no-sequences
@@ -32,10 +34,10 @@ const renderTypeStrings = (member, separator) => {
return typeList;
};
-const paramIsRestType = (param) => {
+const paramIsRestType = async (param) => {
// Find any type === RestType in any descendant
const expression = "$.**[type='RestType']";
- return jsonata(expression).evaluate(param);
+ return await jsonata(expression).evaluate(param);
};
const paramIsOptional = (param) => {
@@ -46,10 +48,10 @@ const requiredParamCount = (params) => {
return params.length - params.filter(paramIsOptional).length;
};
-const decoratedParamName = (param) => {
+const decoratedParamName = async (param) => {
let name = param.name;
- if (paramIsRestType(param)) {
+ if (await paramIsRestType(param)) {
name = '…' + name;
}
@@ -60,14 +62,15 @@ const decoratedParamName = (param) => {
return name;
};
-const buildParamList = (params) => {
- return params.map(decoratedParamName).join(', ');
+const buildParamList = async (params) => {
+ const paramsListPromise = await Promise.all(await params.map(await decoratedParamName));
+ return paramsListPromise.join(', ');
};
-const paramCountString = (params) => {
+const paramCountString = async (params) => {
const reqCount = requiredParamCount(params);
const hasOptional = reqCount < params.length;
- const hasRest = params.length && paramIsRestType(params[params.length - 1]);
+ const hasRest = params.length && await paramIsRestType(params[params.length - 1]);
let result = reqCount;
let suffix = ' Param';
@@ -81,20 +84,20 @@ const paramCountString = (params) => {
return result;
};
-const renderProperties = (param) => {
+const renderProperties = async (param) => {
if (param.properties) {
return (
Object keys for {param.name}
- {param.properties.map((prop) => {
+ {await Promise.all(param.properties.map(async (prop) => {
// Make the keyName just "key" not "prop.key"
const keyName = prop.name.replace(param.name + '.', '');
return [
- - {keyName} {renderTypeStrings(prop)}
,
+ - {keyName} {await renderTypeStrings(prop)}
,
{prop.description}
];
- })}
+ }))}
);
@@ -103,28 +106,62 @@ const renderProperties = (param) => {
// eslint-disable-next-line enact/prop-types
const Parameters = ({func, params, hasReturns}) => {
+ const [paramType, setParamType] = useState({});
+ const [methodReturnValue, setMethodReturnValue] = useState([]);
+ const [responseParamCountString, setResponseParamCountString] = useState([]);
+ const [responseRenderProperties, setResponseRenderProperties] = useState({});
+
+ useEffect(() => {
+ const renderParamCountString = async () => {
+ const data = await paramCountString(params);
+ setResponseParamCountString(data);
+ };
+ renderParamCountString()
+ .catch(console.error); // eslint-disable-line no-console
+
+ // map over all parameters, extract their type and render properties inside an object with the name of the property/type as the key
+ const renderParamTypeAndPropertiesEffect = Promise.all(params.map(async (param) => {
+ const paramTypeData = await renderTypeStrings(param);
+ setParamType(obj => Object.assign(obj, {[param.name]: paramTypeData}));
+
+ const renderPropertiesData = await renderProperties(param);
+ setResponseRenderProperties(obj => Object.assign(obj, {[param.name]: renderPropertiesData}));
+ }));
+ renderParamTypeAndPropertiesEffect
+ .catch(console.error); // eslint-disable-line no-console
+
+ // get the return value of any methods
+ const renderMethodReturnValue = async () => {
+ const data = await renderTypeStrings(func.returns);
+ setMethodReturnValue(array => [...array, data]);
+ };
+ renderMethodReturnValue()
+ .catch(console.error); // eslint-disable-line no-console
+
+ }, [func.returns, params]);
+
if (params.length === 0 && !hasReturns) return null;
return (
{params.length ?
-
{paramCountString(params)}
+
{responseParamCountString}
{params.map((param, subIndex) => (
- - {param.name} {renderTypeStrings(param)}
+ - {param.name} {paramType[param.name]}
{paramIsOptional(param) ? - optional
: null}
{param.default ? - default: {param.default}
: null}
{param.description}
- {renderProperties(param)}
+ {responseRenderProperties[param.name]}
))}
: null}
{hasReturns ?
Returns
- - {renderTypeStrings(func.returns)}
+ - {methodReturnValue}
{func.returns[0].description}
: null}
@@ -132,9 +169,9 @@ const Parameters = ({func, params, hasReturns}) => {
);
};
-export const renderExportedFunction = (func) => {
+export const renderExportedFunction = async (func) => {
const params = func.params || [];
- const paramStr = buildParamList(params);
+ const paramStr = await buildParamList(params);
const name = func.name;
const hasReturns = !!func.returns.length;
@@ -142,7 +179,7 @@ export const renderExportedFunction = (func) => {
- {name}( {paramStr} ){hasReturns ? {renderTypeStrings(func.returns, '|')} : null}
+ {name}( {paramStr} ){hasReturns ? {await renderTypeStrings(func.returns, '|')} : null}
{func.description}
@@ -152,9 +189,9 @@ export const renderExportedFunction = (func) => {
);
};
-const renderFunction = (func, index, funcName) => {
+const renderFunction = async (func, index, funcName) => {
const params = func.params || [];
- const paramStr = buildParamList(params);
+ const paramStr = await buildParamList(params);
const parent = func.memberof ? func.memberof.match(/[^.]*\.(.*)/) : null;
const name = funcName ? funcName : func.name;
const id = (parent ? parent[1] + '.' : '') + name;
@@ -162,7 +199,7 @@ const renderFunction = (func, index, funcName) => {
return (
- {name}({paramStr}){hasReturns ? {renderTypeStrings(func.returns, '|')} : null}
+ {name}({paramStr}){hasReturns ? {await renderTypeStrings(func.returns, '|')} : null}
{func.description}
{renderSeeTags(func)}
@@ -170,7 +207,7 @@ const renderFunction = (func, index, funcName) => {
);
};
-export const renderConstructor = (member) => {
+export const renderConstructor = async (member) => {
if (!member.constructorComment) {
return;
}
@@ -179,7 +216,7 @@ export const renderConstructor = (member) => {
Constructor
- {renderFunction(member.constructorComment, 1, member.name)}
+ {await renderFunction(member.constructorComment, 1, member.name)}
);
diff --git a/src/utils/modules.js b/src/utils/modules.js
index 3c7a4a07..a239b478 100644
--- a/src/utils/modules.js
+++ b/src/utils/modules.js
@@ -26,44 +26,44 @@ import css from '../css/main.module.less';
const H4 = (props) => FloatingAnchor.inline({component: 'h4', ...props});
-const hasFactoryTag = (member) => {
+const hasFactoryTag = async (member) => {
// Find any tag field whose `title` is 'factory'
const expression = "$[title='factory']";
- const result = jsonata(expression).evaluate(member.tags);
+ const result = await jsonata(expression).evaluate(member.tags);
return !!result;
};
-const hasHOCTag = (member) => {
+const hasHOCTag = async (member) => {
// Find any tag field whose `title` is 'hoc'
const expression = "$[title='hoc']";
- const result = jsonata(expression).evaluate(member.tags);
+ const result = await jsonata(expression).evaluate(member.tags);
return !!result;
};
-const hasUITag = (member) => {
+const hasUITag = async (member) => {
// Find any tag field whose `title` is 'ui'
const expression = "$[title='ui']";
- const result = jsonata(expression).evaluate(member.tags);
+ const result = await jsonata(expression).evaluate(member.tags);
return !!result;
};
-const getExampleTags = (member) => {
+const getExampleTags = async (member) => {
// Find any tag field whose `title` is 'example'
// Updated style that works in jsonata 1.6.4 and always returns array!
const expression = "$.[tags[title='example']]";
- return jsonata(expression).evaluate(member);
+ return await jsonata(expression).evaluate(member);
};
-const getBaseComponents = (member) => {
+const getBaseComponents = async (member) => {
// Find any tag field whose `title` is 'extends' and extract the name(s)
const expression = "$.[tags[title='extends'].name]";
- return jsonata(expression).evaluate(member);
+ return await jsonata(expression).evaluate(member);
};
-const getHocs = (member) => {
+const getHocs = async (member) => {
// Find any tag field whose `title` is 'mixes' and extract the name(s)
const expression = "$.[tags[title='mixes'].name]";
- return jsonata(expression).evaluate(member);
+ return await jsonata(expression).evaluate(member);
};
const MemberHeading = kind({
@@ -95,8 +95,8 @@ const MemberHeading = kind({
}
});
-const renderExtends = member => {
- const baseComponents = getBaseComponents(member);
+const renderExtends = async (member) => {
+ const baseComponents = await getBaseComponents(member);
if (baseComponents.length) {
return (
@@ -112,8 +112,8 @@ const renderExtends = member => {
}
};
-const renderAppliedHocs = (member, isHoc) => {
- const hocs = getHocs(member);
+const renderAppliedHocs = async (member, isHoc) => {
+ const hocs = await getHocs(member);
if (hocs.length) {
return (
@@ -129,12 +129,12 @@ const renderAppliedHocs = (member, isHoc) => {
}
};
-const renderModuleMember = (member, index) => {
- const isHoc = hasHOCTag(member),
- isDeprecated = hasDeprecatedTag(member),
- isFactory = hasFactoryTag(member),
+const renderModuleMember = async (member, index) => {
+ const isHoc = await hasHOCTag(member),
+ isDeprecated = await hasDeprecatedTag(member),
+ isFactory = await hasFactoryTag(member),
isClass = (member.kind === 'class'),
- isUI = hasUITag(member),
+ isUI = await hasUITag(member),
classes = [
css.module,
(isDeprecated ? css.deprecated : null),
@@ -152,7 +152,7 @@ const renderModuleMember = (member, index) => {
return
{member.name}
{deprecationNote}
- {renderExportedFunction(member)}
+ {await renderExportedFunction(member)}
;
case 'constant':
return
@@ -162,15 +162,15 @@ const renderModuleMember = (member, index) => {
{member.description}
{renderSeeTags(member)}
- {renderStaticProperties(member.members, isHoc)}
- {renderInstanceProperties(member.members, isHoc)}
- {renderObjectProperties(member.properties)}
+ {await renderStaticProperties(member.members, isHoc)}
+ {await renderInstanceProperties(member.members, isHoc)}
+ {await renderObjectProperties(member.properties)}
;
case 'typedef':
return