Skip to content

Commit 8159a6b

Browse files
committed
Fix boolean values not displayed
1 parent 6132881 commit 8159a6b

File tree

3 files changed

+103
-4
lines changed

3 files changed

+103
-4
lines changed

packages/devtools/demo/demo.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,16 @@ console.log(
8383
);
8484

8585
console.log('Range', Immutable.Range(0, 10, 2));
86+
87+
console.log(
88+
'List of scalars',
89+
Immutable.List([
90+
true,
91+
false,
92+
1,
93+
'a',
94+
Symbol('sym'),
95+
new Date(),
96+
BigInt(12345),
97+
])
98+
);

packages/devtools/src/createFormatter.test.ts

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe('List', () => {
77
const list = List();
88

99
const { ListFormatter } = createFormatters({ List, isList });
10-
10+
1111
const formatted = ListFormatter.header(list);
1212
expect(formatted).toEqual([
1313
'span',
@@ -23,4 +23,77 @@ describe('List', () => {
2323
]);
2424
expect(ListFormatter.hasBody(list)).toBe(false);
2525
});
26+
27+
test('List with scalar values', () => {
28+
const list = List([true, false, 1, 'a']);
29+
30+
const { ListFormatter } = createFormatters({ List, isList });
31+
32+
const formatted = ListFormatter.header(list);
33+
expect(formatted).toEqual([
34+
'span',
35+
[
36+
'span',
37+
{
38+
style:
39+
'color: light-dark(rgb(232,98,0), rgb(255, 150, 50)); position: relative',
40+
},
41+
'List',
42+
],
43+
['span', `[${list.size}]`],
44+
]);
45+
expect(ListFormatter.hasBody(list)).toBe(true);
46+
47+
expect(ListFormatter.body!(list)).toEqual([
48+
'ol',
49+
{
50+
style:
51+
'list-style-type: none; padding: 0; margin: 0 0 0 12px; font-style: normal; position: relative',
52+
},
53+
[
54+
'li',
55+
['span', { style: 'color: light-dark( #881391, #D48CE6)' }, '0: '],
56+
[
57+
'span',
58+
{
59+
style: 'color: light-dark(rgb(28, 128, 28), rgb(50, 200, 50))',
60+
},
61+
'true',
62+
],
63+
],
64+
[
65+
'li',
66+
['span', { style: 'color: light-dark( #881391, #D48CE6)' }, '1: '],
67+
[
68+
'span',
69+
{
70+
style: 'color: light-dark(rgb(28, 128, 28), rgb(50, 200, 50))',
71+
},
72+
'false',
73+
],
74+
],
75+
[
76+
'li',
77+
['span', { style: 'color: light-dark( #881391, #D48CE6)' }, '2: '],
78+
[
79+
'span',
80+
{
81+
style: 'color: light-dark(rgb(28, 128, 28), rgb(50, 200, 50))',
82+
},
83+
1,
84+
],
85+
],
86+
[
87+
'li',
88+
['span', { style: 'color: light-dark( #881391, #D48CE6)' }, '3: '],
89+
[
90+
'object',
91+
{
92+
config: undefined,
93+
object: 'a',
94+
},
95+
],
96+
],
97+
]);
98+
});
2699
});

packages/devtools/src/createFormatters.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const orange = 'light-dark(rgb(232,98,0), rgb(255, 150, 50))';
22
const purple = 'light-dark( #881391, #D48CE6)';
33
const gray = 'light-dark(rgb(119,119,119), rgb(201, 201, 201))';
4+
const green = 'light-dark(rgb(28, 128, 28), rgb(50, 200, 50))';
45

56
const listStyle = {
67
style:
@@ -16,6 +17,7 @@ const inlineValuesStyle = {
1617
style: `color: ${gray}; font-style: italic; position: relative`,
1718
};
1819
const nullStyle = { style: `color: ${gray}` };
20+
const numberBooleanStyle = { style: `color: ${green}` };
1921

2022
export type DevToolsFormatter = {
2123
header: (object: any, config?: any) => any;
@@ -63,8 +65,16 @@ export default function createFormatters(
6365
};
6466

6567
const reference = (object: any, config?: any) => {
66-
if (typeof object === 'undefined') return ['span', nullStyle, 'undefined'];
67-
else if (object === null) return ['span', nullStyle, 'null'];
68+
if (typeof object === 'undefined') {
69+
return ['span', nullStyle, 'undefined'];
70+
} else if (object === null) {
71+
return ['span', nullStyle, 'null'];
72+
} else if (typeof object === 'boolean') {
73+
return ['span', numberBooleanStyle, object ? 'true' : 'false'];
74+
} else if (typeof object === 'number') {
75+
return ['span', numberBooleanStyle, object];
76+
}
77+
6878
return ['object', { object, config }];
6979
};
7080

@@ -163,7 +173,10 @@ export default function createFormatters(
163173

164174
const ListFormatter: DevToolsFormatter = {
165175
header(o: any) {
166-
if (!Immutable.isList(o)) return null;
176+
if (!Immutable.isList(o)) {
177+
return null;
178+
}
179+
167180
return renderIterableHeader(o, 'List');
168181
},
169182
hasBody,

0 commit comments

Comments
 (0)