MCPcopy
hub / github.com/CopyTranslator/CopyTranslator / set

Method set

src/common/configParser.ts:59–90  ·  view source on GitHub ↗
(
    key: Identifier,
    value: any,
    needCheck: boolean = true,
    preSet: boolean = true
  )

Source from the content-addressed store, hash-verified

57 }
58
59 set(
60 key: Identifier,
61 value: any,
62 needCheck: boolean = true,
63 preSet: boolean = true
64 ) {
65 if (needCheck && !this.checkValid(key, value)) {
66 console.log("invalid config value", key, value);
67 return false;
68 }
69 if (preSet) {
70 bus.gat("preSet", key, value);
71 }
72 const config = { [key]: value };
73 store.dispatch("updateConfig", config);
74 if (this.getRule(key).needSave) {
75 //需要保存的才及时保存
76 const now = Date.now();
77 if (this.lastSave > now) {
78 //就说明我们不需要唤起一次新的保存
79 // console.log("schedule save pass");
80 } else {
81 const interval = 2000; //修改后预定一次保存,在此保存之前的所有修改都不会再预定保存
82 this.lastSave = now + interval;
83 setTimeout(() => {
84 // console.log("schedule save");
85 this.save();
86 }, interval);
87 }
88 }
89 return true;
90 }
91
92 checkValid(key: Identifier, value: any): boolean {
93 if (value == undefined) {

Callers 10

restoreDefaultMethod · 0.95
resetMethod · 0.95
updateSnapshotsMethod · 0.95
resumeMethod · 0.95
setRuleMethod · 0.45
getListenerMapFunction · 0.45
event-bus.tsFile · 0.45
bindFunction · 0.45
objToMapFunction · 0.45
appendMethod · 0.45

Calls 4

checkValidMethod · 0.95
getRuleMethod · 0.95
saveMethod · 0.95
dispatchMethod · 0.80

Tested by

no test coverage detected