* Re-evaluate expression with dependency tracking, compare with last * value, and call handler if changed. Returns false if circular * guard tripped (caller should skip this effect). * @returns {boolean} Whether the effect ran successfully
()
| 2953 | * @returns {boolean} Whether the effect ran successfully |
| 2954 | */ |
| 2955 | run() { |
| 2956 | this._consecutiveTriggers++; |
| 2957 | if (this._consecutiveTriggers > 100) { |
| 2958 | console.error( |
| 2959 | "Reactivity loop detected: an effect triggered 100 consecutive times without settling. This usually means an effect is modifying a variable it also depends on.", |
| 2960 | this.element || this |
| 2961 | ); |
| 2962 | return false; |
| 2963 | } |
| 2964 | var reactivity2 = this._reactivity; |
| 2965 | reactivity2._unsubscribeEffect(this); |
| 2966 | var oldDeps = this.dependencies; |
| 2967 | this.dependencies = /* @__PURE__ */ new Map(); |
| 2968 | var prev = reactivity2._currentEffect; |
| 2969 | reactivity2._currentEffect = this; |
| 2970 | var newValue; |
| 2971 | try { |
| 2972 | newValue = this.expression(); |
| 2973 | } catch (e) { |
| 2974 | console.error("Error in reactive expression:", e); |
| 2975 | this.dependencies = oldDeps; |
| 2976 | reactivity2._currentEffect = prev; |
| 2977 | reactivity2._subscribeEffect(this); |
| 2978 | return true; |
| 2979 | } |
| 2980 | reactivity2._currentEffect = prev; |
| 2981 | reactivity2._subscribeEffect(this); |
| 2982 | reactivity2._cleanupOrphanedDeps(oldDeps); |
| 2983 | if (!_sameValue(newValue, this._lastValue)) { |
| 2984 | this._lastValue = newValue; |
| 2985 | try { |
| 2986 | this.handler(newValue); |
| 2987 | } catch (e) { |
| 2988 | console.error("Error in reactive handler:", e); |
| 2989 | } |
| 2990 | } |
| 2991 | return true; |
| 2992 | } |
| 2993 | /** Reset circular guard after cascade settles. */ |
| 2994 | resetTriggerCount() { |
| 2995 | this._consecutiveTriggers = 0; |
no test coverage detected