* First evaluation: track deps, subscribe, call handler if non-null. * Both undefined and null are treated as "no value yet" to support * left-side-wins initialization in bind.
()
| 54 | * left-side-wins initialization in bind. |
| 55 | */ |
| 56 | initialize() { |
| 57 | var reactivity = this._reactivity; |
| 58 | |
| 59 | // Evaluate expression with tracking enabled - any symbol, property, |
| 60 | // or attribute reads during this call are recorded as dependencies. |
| 61 | var prev = reactivity._currentEffect; |
| 62 | reactivity._currentEffect = this; |
| 63 | try { |
| 64 | this._lastValue = this.expression(); |
| 65 | } catch (e) { |
| 66 | console.error("Error in reactive expression:", e); |
| 67 | } |
| 68 | reactivity._currentEffect = prev; |
| 69 | |
| 70 | // Wire up subscriptions so we're notified when dependencies change |
| 71 | reactivity._subscribeEffect(this); |
| 72 | |
| 73 | // If we got a value, push it to the handler immediately. |
| 74 | // null/undefined means "no value yet" - skip to let the other |
| 75 | // side of a bind initialize first (left-side-wins semantics). |
| 76 | if (this._lastValue != null) { |
| 77 | try { |
| 78 | this.handler(this._lastValue); |
| 79 | } catch (e) { |
| 80 | console.error("Error in reactive handler:", e); |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Re-evaluate expression with dependency tracking, compare with last |
no test coverage detected