kitten-cloud-function
Version:
用于编程猫源码云功能(云变量、云列表等)的客户端工具
67 lines (66 loc) • 1.68 kB
JavaScript
import { None } from "./other";
import { Signal } from "./signal";
/**
* 单个配置。
*/
export class SingleConfig {
/**
* 获取配置值。
*/
get config() {
return this.store;
}
/**
* 设置配置值。
*
* 注意:设置配置值需要进行多级缓存更新,这是一个较慢的操作,建议不要频繁修改配置。
*/
set config(value) {
const originalValue = this.getValue();
this.store = value;
const newValue = this.getValue();
if (originalValue != newValue) {
this.cache = newValue;
this.changed.emit({ originalValue, newValue });
}
}
/**
* 获取配置的生效值。
*
* 当配置值非空时,该值为配置值,否则为上层或上层的生效值。
*/
get value() {
return this.cache;
}
set value(value) {
this.config = value;
}
getValue() {
if (this.store != None) {
return this.store;
}
else if (this.upper instanceof SingleConfig) {
return this.upper.value;
}
else {
return this.upper;
}
}
constructor(upper, value) {
/**
*
*/
this.changed = new Signal();
this.upper = upper;
this.store = value;
this.cache = this.getValue();
if (upper instanceof SingleConfig) {
upper.changed.connect((change) => {
if (this.store == None) {
this.cache = upper.value;
this.changed.emit(change);
}
});
}
}
}