Skip to content

Commit baa2140

Browse files
committed
Drop .fromReactive() from ThunderstoreMod and ThunderstoreVersion
As far as I can tell, the conversion isn't really needed. The doc strings of ReactiveObjectConverterInterface claims that access to class methods is lost, but based on testing this is not true. Another claim is that this grants access to object's private fields. The fields can be accessed, but same is true to any ThunderstoreMod object, even if they aren't passed through Vue's methods. Aside from getting a clear TypeScript warning about accessing a private field in IDE (compile time) nothing prevents accessing the field in JS files (run time). Ideally this might speed up OnlineModList rendering, as the unnecessary object creation is skipped.
1 parent 4be3ab5 commit baa2140

File tree

3 files changed

+9
-48
lines changed

3 files changed

+9
-48
lines changed

src/components/views/OnlineModList.vue

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,33 +100,29 @@ export default class OnlineModList extends Vue {
100100
return this.$store.state.tsMods.deprecated;
101101
}
102102
103-
isModDeprecated(key: any) {
104-
const mod: ThunderstoreMod = new ThunderstoreMod().fromReactive(key);
103+
isModDeprecated(mod: ThunderstoreMod) {
105104
return this.deprecationMap.get(mod.getFullName()) || false;
106105
}
107106
108-
isThunderstoreModInstalled(vueMod: any) {
109-
const mod: ThunderstoreMod = new ThunderstoreMod().fromReactive(vueMod);
107+
isThunderstoreModInstalled(mod: ThunderstoreMod) {
110108
return this.localModList.find((local: ManifestV2) => local.getName() === mod.getFullName()) != undefined;
111109
}
112110
113-
showDownloadModal(mod: any) {
114-
const modToDownload = new ThunderstoreMod().fromReactive(mod);
115-
this.$store.commit("openDownloadModModal", modToDownload);
111+
showDownloadModal(mod: ThunderstoreMod) {
112+
this.$store.commit("openDownloadModModal", mod);
116113
}
117114
118115
getReadableDate(date: Date): string {
119116
return valueToReadableDate(date);
120117
}
121118
122-
getReadableCategories(tsMod: ThunderstoreMod) {
123-
const mod = new ThunderstoreMod().fromReactive(tsMod);
119+
getReadableCategories(mod: ThunderstoreMod) {
124120
return mod.getCategories().join(", ");
125121
}
126122
127-
getImageUrl(tsMod: ThunderstoreMod): string {
123+
getImageUrl(mod: ThunderstoreMod): string {
128124
return CdnProvider.replaceCdnHost(
129-
tsMod.getLatestVersion().getIcon()
125+
mod.getLatestVersion().getIcon()
130126
);
131127
}
132128

src/model/ThunderstoreMod.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import ThunderstoreVersion from './ThunderstoreVersion';
2-
import ReactiveObjectConverterInterface from './safety/ReactiveObjectConverter';
32

4-
export default class ThunderstoreMod extends ThunderstoreVersion implements ReactiveObjectConverterInterface {
3+
export default class ThunderstoreMod extends ThunderstoreVersion {
54
private versions: ThunderstoreVersion[] = [];
65
private rating: number = 0;
76
private owner: string = '';
@@ -48,26 +47,6 @@ export default class ThunderstoreMod extends ThunderstoreVersion implements Reac
4847
return mod;
4948
}
5049

51-
public fromReactive(reactive: any): ThunderstoreMod {
52-
this.setName(reactive.name);
53-
this.setFullName(reactive.fullName);
54-
this.setOwner(reactive.owner);
55-
this.setPackageUrl(reactive.packageUrl);
56-
this.setDateCreated(reactive.dateCreated);
57-
this.setDateUpdated(reactive.dateUpdated);
58-
this.setDeprecatedStatus(reactive.deprecated);
59-
this.setPinnedStatus(reactive.pinned);
60-
this.setVersions(reactive.versions.map((x: ThunderstoreVersion) => new ThunderstoreVersion().fromReactive(x)));
61-
this.setDownloadCount(reactive.downloadCount);
62-
this.setRating(reactive.rating);
63-
this.setTotalDownloads(reactive.totalDownloads);
64-
this.setUuid4(reactive.uuid4);
65-
this.setCategories(reactive.categories);
66-
this.setNsfwFlag(reactive.hasNsfwContent);
67-
this.setDonationLink(reactive.donationUrl);
68-
return this;
69-
}
70-
7150
public getVersions(): ThunderstoreVersion[] {
7251
return this.versions;
7352
}

src/model/ThunderstoreVersion.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import VersionNumber from './VersionNumber';
2-
import ReactiveObjectConverterInterface from './safety/ReactiveObjectConverter';
32
import CdnProvider from '../providers/generic/connection/CdnProvider';
43

5-
export default class ThunderstoreVersion implements ReactiveObjectConverterInterface {
4+
export default class ThunderstoreVersion {
65

76
private name: string = '';
87
private versionNumber: VersionNumber = new VersionNumber('0.0.0');
@@ -32,19 +31,6 @@ export default class ThunderstoreVersion implements ReactiveObjectConverterInter
3231
return this;
3332
}
3433

35-
public fromReactive(reactive: any): ThunderstoreVersion {
36-
this.setName(reactive.name);
37-
this.setVersionNumber(new VersionNumber('0.0.0').fromReactive(reactive.versionNumber));
38-
this.setDependencies(reactive.dependencies);
39-
this.setFullName(reactive.fullName);
40-
this.setDescription(reactive.description);
41-
this.setIcon(reactive.icon);
42-
this.enabled = reactive.enabled;
43-
this.setDownloadCount(reactive.downloadCount);
44-
this.setDownloadUrl(reactive.downloadUrl);
45-
return this;
46-
}
47-
4834
public getName(): string {
4935
return this.name;
5036
}

0 commit comments

Comments
 (0)