我打算创造一个反应性的价值"通用类型T
具有以下属性:
预期用途:
// calculates value on demand
function getValue<Number>():Observable<Number>{
// return an observable of some number, takes 1-2 seconds to calculate
}
// sticky observable of value
const value = new StickyValue<Number>(getValue);
// first subscriber triggers calculation
value.subscribe((n) => console.log(n));
// value can be set externally, the subscribers get this value ignoring any triggered calculation result
value.next(500);
// second subscriber gets value that was last set or last calculated
value.subscribe((n) => console.log(n));
假设:calculation()
是一个简单的函数,它返回值
通过评论,我发现BehaviourSubject
已接近尾声。但它仍然不能满足条件2和6。