kitten-cloud-function
Version:
用于编程猫源码云功能(云变量、云列表等)的客户端工具
71 lines (70 loc) • 1.85 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SingleConfig = void 0;
const other_1 = require("./other");
const signal_1 = require("./signal");
/**
* 单个配置。
*/
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 != other_1.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_1.Signal();
this.upper = upper;
this.store = value;
this.cache = this.getValue();
if (upper instanceof SingleConfig) {
upper.changed.connect((change) => {
if (this.store == other_1.None) {
this.cache = upper.value;
this.changed.emit(change);
}
});
}
}
}
exports.SingleConfig = SingleConfig;