|
1 | | -import { Lambda, getNextId, invariant, fail, EMPTY_OBJECT, deprecated } from "../utils/utils" |
2 | | -import { isModifierDescriptor } from "../types/modifiers" |
| 1 | +import { Lambda, getNextId, invariant, EMPTY_OBJECT, deprecated } from "../utils/utils" |
3 | 2 | import { Reaction, IReactionPublic, IReactionDisposer } from "../core/reaction" |
4 | 3 | import { untrackedStart, untrackedEnd } from "../core/derivation" |
5 | | -import { action, isAction, runInAction } from "./action" |
| 4 | +import { action, isAction } from "./action" |
6 | 5 | import { IEqualsComparer, comparer } from "../types/comparer" |
7 | 6 |
|
8 | 7 | export interface IAutorunOptions { |
@@ -110,7 +109,6 @@ export function reaction<T>( |
110 | 109 | invariant(typeof opts === "object", "Third argument of reactions should be an object") |
111 | 110 | } |
112 | 111 | const name = opts.name || "Reaction@" + getNextId() |
113 | | - const fireImmediately = opts.fireImmediately === true |
114 | 112 | // TODO: creates ugly spy events, use `effect = (r) => runInAction(opts.name, () => effect(r))` instead? |
115 | 113 | const effectAction = action(name, effect) |
116 | 114 | const runSync = !opts.scheduler && !opts.delay |
@@ -140,8 +138,8 @@ export function reaction<T>( |
140 | 138 | changed = firstTime || !equals(value, nextValue) |
141 | 139 | value = nextValue |
142 | 140 | }) |
143 | | - if (firstTime && opts.fireImmediately!) effect(value, r) |
144 | | - if (!firstTime && (changed as boolean) === true) effect(value, r) |
| 141 | + if (firstTime && opts.fireImmediately!) effectAction(value, r) |
| 142 | + if (!firstTime && (changed as boolean) === true) effectAction(value, r) |
145 | 143 | if (firstTime) firstTime = false |
146 | 144 | } |
147 | 145 |
|
|
0 commit comments