@@ -21,7 +21,7 @@ All methods describe the kinds of data they accept and the kinds of data
21
21
they return. For example a function which accepts two numbers and returns
22
22
a number would look like this:
23
23
24
- ``` js
24
+ ``` ts
25
25
sum (first : number , second : number ): number
26
26
```
27
27
@@ -30,17 +30,17 @@ kinds of data, and this is described with a _type variable_, which is
30
30
typically in all-caps. For example, a function which always returns the same
31
31
kind of data it was provided would look like this:
32
32
33
- ``` js
33
+ ``` ts
34
34
identity <T >(value : T ): T
35
35
```
36
36
37
37
Type variables are defined with classes and referred to in methods. For
38
38
example, a class that holds onto a value for you might look like this:
39
39
40
- ``` js
40
+ ``` ts
41
41
class Box <T > {
42
- constructor (value : T )
43
- getValue(): T
42
+ constructor (value : T );
43
+ getValue(): T ;
44
44
}
45
45
```
46
46
@@ -49,9 +49,9 @@ a Collection instead return a new Collection of the same type. The type
49
49
` this ` refers to the same kind of class. For example, a List which returns
50
50
new Lists when you ` push ` a value onto it might look like:
51
51
52
- ` ` ` js
52
+ ``` ts
53
53
class List <T > {
54
- push (value: T ): this
54
+ push(value : T ): this ;
55
55
}
56
56
```
57
57
@@ -64,25 +64,40 @@ collections are iterable themselves!
64
64
For example, to get a value deep within a structure of data, we might use
65
65
8000
code>
` getIn ` which expects an ` Iterable ` path:
66
66
67
- ` ` `
67
+ ``` ts
68
68
getIn (path : Iterable < string | number > ): unknown
69
69
```
70
70
71
71
To use this method, we could pass an array: ` data.getIn([ "key", 2 ]) ` .
72
72
73
- Note: All examples are presented in the modern [ES2015][] version of
74
- JavaScript. Use tools like Babel to support older browsers.
75
-
76
- For example:
77
-
78
- ` ` ` js
79
- // ES2015
80
- const mappedFoo = foo .map ((x ) => x * x);
81
- // ES5
82
- var mappedFoo = foo .map (function (x ) {
83
- return x * x;
84
- });
85
- ` ` `
73
+ ### Inheritance cheatsheet
74
+
75
+ The following diagram shows the inheritance relationships between the
76
+ Immutable.js collections. Click on the image to view it in full size.
77
+
78
+ <span >
79
+ { /*
80
+ SVG files are generated from https://excalidraw.com/#json=Indmlmx6FxIgZXvBbKbmH,OKX0Xpl-pmU1c8ZQueCj6Q
81
+ If you want to update this chart:
82
+ - open the link above
83
+ - edit the chart
84
+ - export it as SVG via "file > export" without background, one time in light mode and one time in dark mode
85
+ - change the link above with the link you will get with "share > shareable link"
86
+ */ }
87
+ </span >
88
+
89
+ <a href = " /Immutable.js-Inheritance-cheatsheet.light.excalidraw.svg" >
90
+ <picture >
91
+ <source
92
+ srcSet = " /Immutable.js-Inheritance-cheatsheet.dark.excalidraw.svg"
93
+ media = " (prefers-color-scheme: dark)"
94
+ />
95
+ <img
96
+ src = " /Immutable.js-Inheritance-cheatsheet.light.excalidraw.svg"
97
+ alt = " Immutable.js Inheritance cheatsheet"
98
+ />
99
+ </picture >
100
+ </a >
86
101
87
102
[ ES2015 ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/New_in_JavaScript/ECMAScript_6_support_in_Mozilla
88
103
[ TypeScript ] : https://www.typescriptlang.org/
0 commit comments