Skip to content

Commit ed45754

Browse files
Fix oop methods display
1 parent 71f483e commit ed45754

File tree

3 files changed

+47
-43
lines changed

3 files changed

+47
-43
lines changed

web/src/components/ElementOOPInfo.astro

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,6 @@ export interface Props {
99
1010
const { element_name = null, oop_only_methods, oop_compatible_functions } = Astro.props;
1111
12-
let oop_variables_by_var: Record<string, any[]> = {};
13-
for (const func of oop_compatible_functions) {
14-
if (func.oop.variable) {
15-
if (!oop_variables_by_var[func.oop.variable]) {
16-
oop_variables_by_var[func.oop.variable] = [];
17-
}
18-
oop_variables_by_var[func.oop.variable].push({
19-
functionName: func.name,
20-
functionLink: func.link,
21-
functionOop: func.oop,
22-
});
23-
}
24-
}
2512
let oop_constructor = oop_compatible_functions.find(func => func.oop.constructorclass);
2613
---
2714
{element_name && oop_constructor && (
@@ -33,21 +20,36 @@ let oop_constructor = oop_compatible_functions.find(func => func.oop.constructor
3320
</section>
3421
)}
3522

36-
{Object.keys(oop_variables_by_var).length > 0 && (
37-
<section class="oop-variables-section">
38-
<h4><a href="/OOP_Introduction">OOP</a> Variables and Methods</h4>
23+
{oop_compatible_functions.length > 0 && (
24+
<section class="oop-compatible-functions-section">
25+
<h4><a href="/OOP_Introduction">OOP</a> Methods and Variables</h4>
3926
<ul>
40-
{Object.entries(oop_variables_by_var).map(([variableName, functions]) => (
41-
<li>
42-
<code>{variableName}</code>:
43-
{functions.map((func: any, index: number) => (
44-
<Fragment>
45-
<a href={func.functionLink}>{func.functionOop.method}</a>
46-
{index < functions.length - 1 ? ', ' : ''}
47-
</Fragment>
48-
))}
49-
</li>
50-
))}
27+
{oop_compatible_functions.map((funcInfo: any) => (
28+
<li>
29+
{funcInfo.oop.constructorclass ? (
30+
<span>
31+
<strong>Constructor</strong>:
32+
{funcInfo.oop.constructorclass}(...)
33+
</span>
34+
) : (
35+
<>
36+
{funcInfo.oop.method && (
37+
<span style="margin-right: 10px;">
38+
<strong>Method</strong>:
39+
{funcInfo.oop.static ? funcInfo.oop.entity.charAt(0).toUpperCase() + funcInfo.oop.entity.slice(1) : funcInfo.oop.entity}{funcInfo.oop.static ? '.' : ':'}<a href={funcInfo.link} title={funcInfo.name}>{funcInfo.oop.method}</a>(...)
40+
</span>
41+
)}
42+
43+
{funcInfo.oop.variable && (
44+
<span>
45+
<strong>Variable</strong>:
46+
.{funcInfo.oop.variable}
47+
</span>
48+
)}
49+
</>
50+
)}
51+
</li>
52+
))}
5153
</ul>
5254
</section>
5355
)}

web/src/pages/[func].astro

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,27 +108,29 @@ let funcSyntaxes = parseFunctionSyntaxes(func.id, func.data);
108108
<div class="function-oop">
109109
<h4>OOP Syntax <a class="small-text" href="/OOP_Introduction">Help! I don't understand this!</a></h4>
110110
<ul>
111-
{funcInfo.oop.method && (
112-
<li>
113-
<strong>Method</strong>:
114-
<a href={ `/${funcInfo.oop.entity}` }>{funcInfo.oop.entity}</a>{funcInfo.oop.static ? '.' : ':'}{funcInfo.oop.method}(...)
115-
</li>
116-
)}
117-
118-
{funcInfo.oop.variable && (
119-
<li>
120-
<strong>Variable</strong>:
121-
.{funcInfo.oop.variable}
122-
</li>
123-
)}
124111

125-
{funcInfo.oop.constructorclass && (
112+
{funcInfo.oop.constructorclass ? (
126113
<li>
127114
<strong>Constructor</strong>:
128115
{funcInfo.oop.constructorclass}(...)
129116
</li>
130-
)}
117+
) : (
118+
<>
119+
{funcInfo.oop.method && (
120+
<li>
121+
<strong>Method</strong>:
122+
<a href={ `/${funcInfo.oop.entity}` }>{funcInfo.oop.static ? funcInfo.oop.entity.charAt(0).toUpperCase() + funcInfo.oop.entity.slice(1) : funcInfo.oop.entity}</a>{funcInfo.oop.static ? '.' : ':'}{funcInfo.oop.method}(...)
123+
</li>
124+
)}
131125

126+
{funcInfo.oop.variable && (
127+
<li>
128+
<strong>Variable</strong>:
129+
.{funcInfo.oop.variable}
130+
</li>
131+
)}
132+
</>
133+
)}
132134
</ul>
133135
</div>
134136
</>

web/src/utils/functions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type BaseOOP = {
1313
// /!\ constructor is a reserved word in JS/TS, so we use constructorclass
1414
type MethodOOP = BaseOOP & {
1515
method: string;
16-
static?: boolean;
16+
static: boolean;
1717
variable?: string;
1818
constructorclass?: never; // mutually exclusive with constructor
1919
};

0 commit comments

Comments
 (0)