Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cbbfb9a

Browse filesBrowse files
committed
Fix typescript
1 parent 145ad49 commit cbbfb9a
Copy full SHA for cbbfb9a

File tree

4 files changed

+59
-24
lines changed
Filter options

4 files changed

+59
-24
lines changed

‎website/src/repl/FormatterOutput.tsx

Copy file name to clipboardExpand all lines: website/src/repl/FormatterOutput.tsx
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { toHTML } from 'jsonml-html';
22
import { useEffect, useRef, type JSX } from 'react';
3+
import { Element, JsonMLElementList } from '../worker/jsonml-types';
34

45
/**
56
* immutable-devtools is a console custom formatter.
@@ -8,7 +9,7 @@ import { useEffect, useRef, type JSX } from 'react';
89
* The `jsonml-html` package can convert jsonml to HTML.
910
*/
1011
type Props = {
11-
output: Array<unknown>;
12+
output: JsonMLElementList | Element;
1213
};
1314

1415
export default function FormatterOutput({ output }: Props): JSX.Element {

‎website/src/repl/Repl.tsx

Copy file name to clipboardExpand all lines: website/src/repl/Repl.tsx
+10-6Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ import React, { useEffect, useRef, useState, type JSX } from 'react';
44
import { Editor } from './Editor';
55
import FormatterOutput from './FormatterOutput';
66
import './repl.css';
7+
import { Element, JsonMLElementList } from '../worker/jsonml-types';
78

89
type Props = { defaultValue: string; onRun?: (code: string) => void };
910

1011
function Repl({ defaultValue, onRun }: Props): JSX.Element {
1112
const [code, setCode] = useState<string>(defaultValue);
12-
const [output, setOutput] = useState<{
13-
header: Array<unknown>;
14-
body?: Array<unknown>;
15-
}>({ header: [] });
13+
const [output, setOutput] = useState<JsonMLElementList | Element>([]);
1614
const workerRef = useRef<Worker | null>(null);
1715

1816
useEffect(() => {
@@ -41,9 +39,15 @@ function Repl({ defaultValue, onRun }: Props): JSX.Element {
4139
workerRef.current.postMessage(code);
4240
workerRef.current.onmessage = (event) => {
4341
if (event.data.error) {
44-
setOutput({ header: ['div', 'Error: ' + event.data.error] });
42+
setOutput(['div', 'Error: ' + event.data.error]);
4543
} else {
46-
setOutput(event.data.output);
44+
const { output } = event.data;
45+
46+
if (typeof output === 'object' && !Array.isArray(output)) {
47+
setOutput(['div', { object: output }]);
48+
} else {
49+
setOutput(output);
50+
}
4751
}
4852
};
4953
}

‎website/src/worker/normalizeResult.test.ts

Copy file name to clipboardExpand all lines: website/src/worker/normalizeResult.test.ts
+42-15Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import normalizeResult from './normalizeResult';
66
// eslint-disable-next-line @typescript-eslint/no-require-imports -- import does not work
77
const installDevTools = require('@jdeniau/immutable-devtools');
88

9-
console.log(installDevTools);
10-
119
installDevTools(Immutable);
1210

1311
// hack to get the formatters from immutable-devtools as they are not exported, but they modify the "global" variable
@@ -17,17 +15,15 @@ describe('normalizeResult', () => {
1715
it('should return the correct object', () => {
1816
const result = normalizeResult(immutableFormaters, { a: 1, b: 2 });
1917

20-
expect(result).toEqual({
21-
header: ['span', JSON.stringify({ a: 1, b: 2 })],
22-
body: null,
23-
});
18+
expect(result).toEqual(JSON.stringify({ a: 1, b: 2 }));
2419
});
2520

2621
it('should return the correct object for a list', () => {
2722
const result = normalizeResult(immutableFormaters, Immutable.List(['a']));
2823

29-
expect(result).toEqual({
30-
header: [
24+
expect(result).toEqual([
25+
'span',
26+
[
3127
'span',
3228
[
3329
'span',
@@ -39,7 +35,7 @@ describe('normalizeResult', () => {
3935
],
4036
['span', '[1]'],
4137
],
42-
body: [
38+
[
4339
'ol',
4440
{
4541
style:
@@ -51,7 +47,7 @@ describe('normalizeResult', () => {
5147
['object', { object: 'a', config: undefined }],
5248
],
5349
],
54-
});
50+
]);
5551
});
5652

5753
it('should return the correct object for a deep list', () => {
@@ -60,8 +56,9 @@ describe('normalizeResult', () => {
6056
Immutable.List([Immutable.List(['a'])])
6157
);
6258

63-
expect(result).toEqual({
64-
header: [
59+
expect(result).toEqual([
60+
'span',
61+
[
6562
'span',
6663
[
6764
'span',
@@ -73,7 +70,7 @@ describe('normalizeResult', () => {
7370
],
7471
['span', '[1]'],
7572
],
76-
body: [
73+
[
7774
'ol',
7875
{
7976
style:
@@ -82,9 +79,39 @@ describe('normalizeResult', () => {
8279
[
8380
'li',
8481
['span', { style: 'color: light-dark( #881391, #D48CE6)' }, '0: '],
85-
['object', { object: 'a', config: undefined }],
82+
[
83+
'span',
84+
[
85+
'span',
86+
[
87+
'span',
88+
{
89+
style:
90+
'color: light-dark(rgb(232,98,0), rgb(255, 150, 50)); position: relative',
91+
},
92+
'List',
93+
],
94+
['span', '[1]'],
95+
],
96+
[
97+
'ol',
98+
{
99+
style:
100+
'list-style-type: none; padding: 0; margin: 0 0 0 12px; font-style: normal; position: relative',
101+
},
102+
[
103+
'li',
104+
[
105+
'span',
106+
{ style: 'color: light-dark( #881391, #D48CE6)' },
107+
'0: ',
108+
],
109+
['object', { object: 'a', config: undefined }],
110+
],
111+
],
112+
],
86113
],
87114
],
88-
});
115+
]);
89116
});
90117
});

‎website/src/worker/normalizeResult.ts

Copy file name to clipboardExpand all lines: website/src/worker/normalizeResult.ts
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ function getFormatter(
1818
return immutableFormaters.find((formatter) => formatter.header(result));
1919
}
2020

21-
// console.log(immutableFormaters)
2221
export default function normalizeResult(
2322
immutableFormaters: Array<DevToolsFormatter>,
2423
result: unknown
@@ -42,7 +41,11 @@ export default function normalizeResult(
4241
return normalizeElement(immutableFormaters, result);
4342
}
4443

45-
return result;
44+
if (typeof result === 'string') {
45+
return result;
46+
}
47+
48+
return JSON.stringify(result);
4649
}
4750

4851
const header = formatter.header(result) ?? [];

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.