Skip to content

Commit 5f68f14

Browse files
authored
Merge pull request #190 from evo-lua/fix-function-components
Display a placeholder in the API reference if availability data is missing
2 parents 2d4479c + 55a5f9b commit 5f68f14

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

src/components/API/API.jsx

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,40 @@ import React from "react";
22

33
import styles from "./styles.module.css";
44

5-
export const Function = ({ since, children }) =>
6-
(since && (
7-
<>
8-
<span className={styles.sinceBlock}>Available since: {since}</span>
9-
<div className={styles.function}>{children}</div>
10-
</>
11-
)) || <></>;
5+
class Function extends React.Component {
6+
render() {
7+
const since = this.props.since;
8+
const children = this.props.children;
9+
10+
const isRunningInDevelopmentMode = process.env.NODE_ENV !== "production";
11+
if (isRunningInDevelopmentMode) {
12+
// Doesn't look like more context can easily be obtained, so let's leave it at that...
13+
const where = location;
14+
const what = `Missing property (since) for (Function) imported from ${where}`;
15+
const message = `${what}`;
16+
if (!since) throw new Error(message);
17+
}
18+
19+
const sinceBlock = (since && (
20+
<>
21+
<span className={styles.sinceBlock}>Available since: {since}</span>
22+
</>
23+
)) || (
24+
<>
25+
<span className={styles.sinceBlock}>
26+
Available since: ¯\_(ツ)_/¯ (Missing availability data - sorry about
27+
that)
28+
</span>
29+
</>
30+
);
31+
return (
32+
<>
33+
{sinceBlock}
34+
<div className={styles.function}>{children}</div>
35+
</>
36+
);
37+
}
38+
}
1239

1340
class NilableInfo extends React.Component {
1441
render() {
@@ -346,6 +373,7 @@ class Blocking extends React.Component {
346373
}
347374

348375
export {
376+
Function,
349377
Parameters,
350378
Parameter,
351379
Returns,

0 commit comments

Comments
 (0)