(
node: Solid.SourceMapValue | Solid.Computation,
onUpdate: ValueUpdateListener,
symbol: symbol,
)
| 96 | * Patches the owner/signal value, firing the callback on each update immediately as it happened. |
| 97 | */ |
| 98 | export function observeValueUpdate( |
| 99 | node: Solid.SourceMapValue | Solid.Computation, |
| 100 | onUpdate: ValueUpdateListener, |
| 101 | symbol: symbol, |
| 102 | ): void { |
| 103 | let map = SignalUpdateListeners.get(node) |
| 104 | if (!map) { |
| 105 | SignalUpdateListeners.set(node, (map = new Map())) |
| 106 | let value = node.value |
| 107 | Object.defineProperty(node, 'value', { |
| 108 | get: () => value, |
| 109 | set: newValue => { |
| 110 | for (const fn of map!.values()) fn(newValue, value) |
| 111 | value = newValue |
| 112 | }, |
| 113 | }) |
| 114 | } |
| 115 | map.set(symbol, onUpdate) |
| 116 | } |
| 117 | |
| 118 | export function removeValueUpdateObserver( |
| 119 | node: Solid.SourceMapValue | Solid.Computation, |
no test coverage detected
searching dependent graphs…