mini-framework-z01
Version:
Mini Framework is designed to provide a simple yet powerful approach to building web applications with minimal overhead.
27 lines • 556 B
JavaScript
class Signal {
static currentEffect = null;
constructor(initialValue) {
this._value = initialValue;
this.subscribers = new Set();
this.isSignal = true;
}
get() {
if (Signal.currentEffect) {
this.subscribers.add(Signal.currentEffect);
}
return this._value;
}
set(newValue) {
if (this._value !== newValue) {
this._value = newValue;
this.subscribers.forEach(fn => fn());
}
}
get value() {
return this._value;
}
set value(newValue) {
this.set(newValue);
}
}
export default Signal;