Skip to content

Commit 820953c

Browse files
committed
Range formatter
1 parent c1d5791 commit 820953c

File tree

7 files changed

+56
-33
lines changed

7 files changed

+56
-33
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The library currently has formatters for:
2323
- [x] `Set` & `OrderedSet`
2424
- [x] `Stack`
2525
- [x] `Record`
26-
- [ ] `Range` (let me know if you use this :-), add :+1: to [#21](https://github.com/andrewdavey/immutable-devtools/issues/21))
26+
- [x] `Range`
2727
- [ ] `Repeat` (if you wish this, add :+1: to [#22](https://github.com/andrewdavey/immutable-devtools/issues/22))
2828
- [ ] `Seq` — I do not have an idea how to display it. If you know, [write it down into #23](https://github.com/andrewdavey/immutable-devtools/issues/23)
2929

packages/devtools/index.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<html>
22
<head>
33
<title>Immutable DevTools Demo</title>
4-
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/immutable/3.7.6/immutable.min.js"></script> -->
54
<script src="https://cdnjs.cloudflare.com/ajax/libs/immutable/5.0.3/immutable.js"></script>
6-
<script src="dist/index.js"></script>
7-
<script id="demoScript">
5+
<script id="demoScript" type="module">
6+
import installDevTools from './dist/index.js';
7+
88
var MyRecord = Immutable.Record({
99
value: 'original',
1010
value2: 'original2',
@@ -71,6 +71,8 @@
7171
console.log('Nested Records', nestedRecords)
7272

7373
console.log("Null string", Immutable.List.of("hello", "null", null, 'undefined', undefined));
74+
75+
console.log("Range", Immutable.Range(0, 10, 2));
7476
</script>
7577
</head>
7678
<body>

packages/devtools/src/createFormatters.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,36 @@ export default function createFormatter(Immutable) {
212212
}
213213
};
214214

215+
const RangeFormatter = {
216+
header(o) {
217+
if (!Immutable.isSeq(o))
218+
return null;
219+
220+
// there is no proper way to check if the object is a Range for now
221+
if (
222+
typeof o._start === 'undefined' ||
223+
typeof o._end === 'undefined' ||
224+
typeof o._step === 'undefined' ||
225+
typeof o.toString !== 'function'
226+
) {
227+
return null
228+
}
229+
230+
const out = o.toString().replace(/^Range /, '');
231+
232+
return ['span', ['span', immutableNameStyle, 'Range'], ['span', out]];
233+
},
234+
hasBody: () => false,
235+
};
236+
215237
return {
216238
RecordFormatter,
217239
OrderedMapFormatter,
218240
OrderedSetFormatter,
219241
ListFormatter,
220242
MapFormatter,
221243
SetFormatter,
222-
StackFormatter
244+
StackFormatter,
245+
RangeFormatter
223246
}
224247
}

packages/devtools/src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function install(Immutable) {
2626
MapFormatter,
2727
SetFormatter,
2828
StackFormatter,
29+
RangeFormatter,
2930
} = createFormatters(Immutable);
3031

3132
gw.devtoolsFormatters.push(
@@ -35,7 +36,8 @@ function install(Immutable) {
3536
ListFormatter,
3637
MapFormatter,
3738
SetFormatter,
38-
StackFormatter
39+
StackFormatter,
40+
RangeFormatter
3941
);
4042

4143
installed = true;

packages/extension/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"author": "",
1313
"license": "ISC",
1414
"dependencies": {
15-
"@jdeniau/immutable-devtools": "^0.3.0",
15+
"@jdeniau/immutable-devtools": "workspace:^",
1616
"immutable": "^5.1.2"
1717
},
1818
"devDependencies": {

packages/extension/test-page/test-v5.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,33 @@ function runTests(){
1515
var f = Foo()
1616
console.log("Expand this and check child renders as a Map", f)
1717

18-
window.record = new ABRecord();
19-
window.record2 = new ABRecord({a: 2});
20-
console.log(window.record);
21-
console.log(window.record2);
18+
const record = new ABRecord();
19+
const record2 = new ABRecord({a: 2});
20+
console.log(record);
21+
console.log(record2);
2222

23-
window.orderedMap = Immutable.OrderedMap({key: "value"});
24-
window.orderedMap2 = Immutable.OrderedMap([["key", "value"], ["key2", "value2"]]);
25-
console.log(window.orderedMap);
26-
console.log(window.orderedMap2);
23+
const orderedMap = Immutable.OrderedMap({key: "value"});
24+
const orderedMap2 = Immutable.OrderedMap([["key", "value"], ["key2", "value2"]]);
25+
console.log(orderedMap);
26+
console.log(orderedMap2);
2727

28-
window.orderedSet = Immutable.OrderedSet(["hello", "aaa"]);
29-
console.log(window.orderedSet);
28+
const orderedSet = Immutable.OrderedSet(["hello", "aaa"]);
29+
console.log(orderedSet);
3030

31-
window.list = Immutable.List(["hello", "world"]);
32-
console.log(window.list)
31+
const list = Immutable.List(["hello", "world"]);
32+
console.log(list)
3333

34-
window.map = Immutable.Map({hello: "world"})
35-
console.log(window.map)
34+
const map = Immutable.Map({hello: "world"})
35+
console.log(map)
3636

37-
window.set = Immutable.Set(["hello", "aaa"])
38-
console.log(window.set)
37+
const set = Immutable.Set(["hello", "aaa"])
38+
console.log(set)
3939

40-
window.stack = Immutable.Stack(["hello", "aaa"])
41-
console.log(window.stack)
40+
const stack = Immutable.Stack(["hello", "aaa"])
41+
console.log(stack)
42+
43+
const range = Immutable.Range(0, 10, 2);
44+
console.log(range);
4245

4346
console.log("shoudln't cause error", Immutable.Record.prototype)
4447

yarn.lock

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ __metadata:
10971097
dependencies:
10981098
"@babel/core": "npm:^7.27.1"
10991099
"@babel/preset-env": "npm:^7.27.2"
1100-
"@jdeniau/immutable-devtools": "npm:^0.3.0"
1100+
"@jdeniau/immutable-devtools": "workspace:^"
11011101
"@rollup/plugin-babel": "npm:^6.0.4"
11021102
"@rollup/plugin-node-resolve": "npm:^16.0.1"
11031103
immutable: "npm:^5.1.2"
@@ -1142,13 +1142,6 @@ __metadata:
11421142
languageName: node
11431143
linkType: hard
11441144

1145-
"@jdeniau/immutable-devtools@npm:^0.3.0":
1146-
version: 0.3.0
1147-
resolution: "@jdeniau/immutable-devtools@npm:0.3.0"
1148-
checksum: 10c0/00ff6d165f8cef60ff1f976b722f47bd27e871e852de8473ad3f7b4b4be5919fb10379e80cb9f42df3dcc6875553b376d385a7b861aaffaa24a7bc1366312d36
1149-
languageName: node
1150-
linkType: hard
1151-
11521145
"@jdeniau/immutable-devtools@workspace:^, @jdeniau/immutable-devtools@workspace:packages/devtools":
11531146
version: 0.0.0-use.local
11541147
resolution: "@jdeniau/immutable-devtools@workspace:packages/devtools"

0 commit comments

Comments
 (0)