8000 Merge pull request #2110 from immutable-js/inheritance-cheatsheet · immutable-js/immutable-js@caf4356 · GitHub
[go: up one dir, main page]

Skip to content

Commit caf4356

Browse files
authored
Merge pull request #2110 from immutable-js/inheritance-cheatsheet
2 parents 1076bbd + 68d47ca commit caf4356

File tree

4 files changed

+45
-26
lines changed

4 files changed

+45
-26
lines changed

website/docs/Intro.mdx

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ All methods describe the kinds of data they accept and the kinds of data
2121
they return. For example a function which accepts two numbers and returns
2222
a number would look like this:
2323

24-
```js
24+
```ts
2525
sum(first: number, second: number): number
2626
```
2727

@@ -30,17 +30,17 @@ kinds of data, and this is described with a _type variable_, which is
3030
typically in all-caps. For example, a function which always returns the same
3131
kind of data it was provided would look like this:
3232

33-
```js
33+
```ts
3434
identity<T>(value: T): T
3535
```
3636

3737
Type variables are defined with classes and referred to in methods. For
3838
example, a class that holds onto a value for you might look like this:
3939

40-
```js
40+
```ts
4141
class Box<T> {
42-
constructor(value: T)
43-
getValue(): T
42+
constructor(value: T);
43+
getValue(): T;
4444
}
4545
```
4646

@@ -49,9 +49,9 @@ a Collection instead return a new Collection of the same type. The type
4949
`this` refers to the same kind of class. For example, a List which returns
5050
new Lists when you `push` a value onto it might look like:
5151

52-
```js
52+
```ts
5353
class List<T> {
54-
push(value: T): this
54+
push(value: T): this;
5555
}
5656
```
5757

@@ -64,25 +64,40 @@ collections are iterable themselves!
6464
For example, to get a value deep within a structure of data, we might use
6565
`getIn` which expects an `Iterable` path:
6666

67-
```
67+
```ts
6868
getIn(path: Iterable<string | number>): unknown
6969
```
7070

7171
To use this method, we could pass an array: `data.getIn([ "key", 2 ])`.
7272

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>
86101

87102
[ES2015]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/New_in_JavaScript/ECMAScript_6_support_in_Mozilla
88103
[TypeScript]: https://www.typescriptlang.org/

0 commit comments

Comments
 (0)
0