comments for signal implmentation

This commit is contained in:
Geoff Doty 2025-03-27 13:59:19 -05:00
parent e72196cb34
commit cecefefa57
1 changed files with 14 additions and 1 deletions

View File

@ -1,14 +1,27 @@
// Signal implementation
/**
* Signal
*
* Creates a signal for reactive state management
*
* @param {any} value - Initial value for the signal
*
* @returns {Object} Signal object with getter, setter, and subscription methods
*/
function signal(value) {
const subscribers = new Set();
return {
// gets current signal value
get value() {
return value;
},
// sets a new value for the signal, notifying all subscribers
set value(newValue) {
value = newValue;
subscribers.forEach(fn => fn());
},
// subscribe to value changes
subscribe(fn) {
subscribers.add(fn);
return () => subscribers.delete(fn);