Commit 5974bfc
committed
minor #2406 [Map] Fix and improve TypeScript types, refactor same logic into dedicated methods (to reduce file size) (Kocal)
This PR was squashed before being merged into the 2.x branch.
Discussion
----------
[Map] Fix and improve TypeScript types, refactor same logic into dedicated methods (to reduce file size)
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no <!-- please update src/**/CHANGELOG.md files -->
| Issues | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License | MIT
<!--
Replace this notice by a description of your feature/bugfix.
This will help reviewers and should be a good start for the documentation.
Additionally (see https://symfony.com/releases):
- Always add tests and ensure they pass.
- For new features, provide some code snippets to help understand usage.
- Features and deprecations must be submitted against branch main.
- Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry
- Never break backward compatibility (see https://symfony.com/bc).
-->
This PRs is purely internal, and aims to:
- Making TypeScript happy by fixing types definitions and usages, but also simplify them
- Refactoring methods containing the same logic (ex: `this.create*` or `this....ValueChanged`) methods) to dedicated methods:
```js
createMarker(definition) {
this.dispatchEvent('marker:before-create', { definition });
const marker = this.doCreateMarker(definition);
this.dispatchEvent('marker:after-create', { marker });
marker['`@id`'] = definition['`@id`'];
this.markers.set(definition['`@id`'], marker);
return marker;
}
createPolygon(definition) {
this.dispatchEvent('polygon:before-create', { definition });
const polygon = this.doCreatePolygon(definition);
this.dispatchEvent('polygon:after-create', { polygon });
polygon['`@id`'] = definition['`@id`'];
this.polygons.set(definition['`@id`'], polygon);
return polygon;
}
createPolyline(definition) {
this.dispatchEvent('polyline:before-create', { definition });
const polyline = this.doCreatePolyline(definition);
this.dispatchEvent('polyline:after-create', { polyline });
polyline['`@id`'] = definition['`@id`'];
this.polylines.set(definition['`@id`'], polyline);
return polyline;
}
```
becomes
```js
this.createMarker = this.createDrawingFactory('marker', this.markers, this.doCreateMarker.bind(this));
this.createPolygon = this.createDrawingFactory('polygon', this.polygons, this.doCreatePolygon.bind(this));
this.createPolyline = this.createDrawingFactory('polyline', this.polylines, this.doCreatePolyline.bind(this));
```
and
```js
markersValueChanged() {
if (!this.map) {
return;
}
this.markers.forEach((marker) => {
if (!this.markersValue.find((m) => m['`@id`'] === marker['`@id`'])) {
this.removeMarker(marker);
this.markers.delete(marker['`@id`']);
}
});
this.markersValue.forEach((marker) => {
if (!this.markers.has(marker['`@id`'])) {
this.createMarker(marker);
}
});
if (this.fitBoundsToMarkersValue) {
this.doFitBoundsToMarkers();
}
}
polygonsValueChanged() {
if (!this.map) {
return;
}
this.polygons.forEach((polygon) => {
if (!this.polygonsValue.find((p) => p['`@id`'] === polygon['`@id`'])) {
this.removePolygon(polygon);
this.polygons.delete(polygon['`@id`']);
}
});
this.polygonsValue.forEach((polygon) => {
if (!this.polygons.has(polygon['`@id`'])) {
this.createPolygon(polygon);
}
});
}
polylinesValueChanged() {
if (!this.map) {
return;
}
this.polylines.forEach((polyline) => {
if (!this.polylinesValue.find((p) => p['`@id`'] === polyline['`@id`'])) {
this.removePolyline(polyline);
this.polylines.delete(polyline['`@id`']);
}
});
this.polylinesValue.forEach((polyline) => {
if (!this.polylines.has(polyline['`@id`'])) {
this.createPolyline(polyline);
}
});
}
```
becomes
```js
markersValueChanged() {
if (!this.isConnected) {
return;
}
this.onDrawChanged(this.markers, this.markersValue, this.createMarker, this.doRemoveMarker);
if (this.fitBoundsToMarkersValue) {
this.doFitBoundsToMarkers();
}
}
polygonsValueChanged() {
if (!this.isConnected) {
return;
}
this.onDrawChanged(this.polygons, this.polygonsValue, this.createPolygon, this.doRemovePolygon);
}
polylinesValueChanged() {
if (!this.isConnected) {
return;
}
this.onDrawChanged(this.polylines, this.polylinesValue, this.createPolyline, this.doRemovePolyline);
}
```
Commits
-------
1d33a5f [Map] Create "onDrawChanged" to refactor methods "markersValueChanged"/"polygonsValueChanged"/"polylinesValueChanged" (not identical but follow the same pattern)
d9d9ff9 [Map] Create "createDrawingFactory" to refactor methods "createMarker"/"createPolyline"/"createPolygon" (not identical but follow the same pattern)
a443ad8 [Map] Re-organize methods order, simplify types, don't dirty-append ``@id`` anymoreFile tree
10 files changed
+576
-566
lines changed- src/Map
- assets
- dist
- src
- test
- src/Bridge
- Google/assets
- dist
- src
- Leaflet/assets
- dist
- src
10 files changed
+576
-566
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
8 | 11 | | |
9 | 12 | | |
10 | | - | |
| 13 | + | |
11 | 14 | | |
12 | 15 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
29 | | - | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| 40 | + | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
| |||
55 | 57 | | |
56 | 58 | | |
57 | 59 | | |
58 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
59 | 63 | | |
60 | | - | |
61 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
62 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
63 | 79 | | |
64 | 80 | | |
65 | 81 | | |
66 | 82 | | |
67 | 83 | | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
87 | 97 | | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
| 98 | + | |
| 99 | + | |
96 | 100 | | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
| 101 | + | |
| 102 | + | |
104 | 103 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | 7 | | |
9 | 8 | | |
| 9 | + | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
14 | 18 | | |
15 | | - | |
16 | | - | |
17 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
18 | 22 | | |
19 | 23 | | |
20 | 24 | | |
| |||
25 | 29 | | |
26 | 30 | | |
27 | 31 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
| 32 | + | |
52 | 33 | | |
53 | 34 | | |
54 | 35 | | |
| |||
58 | 39 | | |
59 | 40 | | |
60 | 41 | | |
61 | | - | |
| 42 | + | |
62 | 43 | | |
63 | 44 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
| 45 | + | |
75 | 46 | | |
76 | 47 | | |
77 | 48 | | |
78 | 49 | | |
79 | 50 | | |
80 | | - | |
| 51 | + | |
81 | 52 | | |
82 | 53 | | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
| 54 | + | |
94 | 55 | | |
95 | 56 | | |
96 | | - | |
| 57 | + | |
97 | 58 | | |
98 | 59 | | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
104 | 82 | | |
105 | | - | |
106 | | - | |
107 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
108 | 86 | | |
109 | 87 | | |
110 | 88 | | |
| |||
0 commit comments