Skip to content

Commit 57cc62f

Browse files
committed
🎨 refactor: setting-utils args
1 parent 56be185 commit 57cc62f

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

‎src/index.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ export default class PluginSample extends Plugin {
163163
}
164164
});
165165

166-
this.settingUtils = new SettingUtils(this, STORAGE_NAME);
166+
this.settingUtils = new SettingUtils({
167+
plugin: this, name: STORAGE_NAME
168+
});
167169
this.settingUtils.addItem({
168170
key: "Input",
169171
value: "",

‎src/libs/setting-utils.ts‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @Author : frostime
44
* @Date : 2023-12-17 18:28:19
55
* @FilePath : /src/libs/setting-utils.ts
6-
* @LastEditTime : 2024-04-28 17:43:43
6+
* @LastEditTime : 2024-04-28 17:49:31
77
* @Description :
88
*/
99

@@ -49,20 +49,26 @@ export class SettingUtils {
4949
settings: Map<string, ISettingItem> = new Map();
5050
elements: Map<string, HTMLElement> = new Map();
5151

52-
constructor(plugin: Plugin, name?: string, callback?: (data: any) => void, width?: string, height?: string) {
53-
this.name = name ?? 'settings';
54-
this.plugin = plugin;
52+
constructor(args: {
53+
plugin: Plugin,
54+
name?: string,
55+
callback?: (data: any) => void,
56+
width?: string,
57+
height?: string
58+
}) {
59+
this.name = args.name ?? 'settings';
60+
this.plugin = args.plugin;
5561
this.file = this.name.endsWith('.json') ? this.name : `${this.name}.json`;
5662
this.plugin.setting = new Setting({
57-
width: width,
58-
height: height,
63+
width: args.width,
64+
height: args.height,
5965
confirmCallback: () => {
6066
for (let key of this.settings.keys()) {
6167
this.updateValueFromElement(key);
6268
}
6369
let data = this.dump();
64-
if (callback !== undefined) {
65-
callback(data);
70+
if (args.callback !== undefined) {
71+
args.callback(data);
6672
}
6773
this.plugin.data[this.name] = data;
6874
this.save();

0 commit comments

Comments
 (0)