Skip to content

Commit

Permalink
Merge pull request #475 from igncp/master
Browse files Browse the repository at this point in the history
Refactor max iterations exception message
  • Loading branch information
mweststrate authored Aug 11, 2016
2 parents 59a14f0 + fddf32b commit caaf7c8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/core/reaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ export function runReactions() {
// we converge to no remaining reactions after a while.
while (allReactions.length > 0) {
if (++iterations === MAX_REACTION_ITERATIONS)
throw new Error("Reaction doesn't converge to a stable state. Probably there is a cycle in the reactive function: " + allReactions[0].toString());
throw new Error(`Reaction doesn't converge to a stable state after ${MAX_REACTION_ITERATIONS} iterations.`
+ ` Probably there is a cycle in the reactive function: ${allReactions[0]}`);
let remainingReactions = allReactions.splice(0);
for (let i = 0, l = remainingReactions.length; i < l; i++)
remainingReactions[i].runReaction();
Expand Down
21 changes: 20 additions & 1 deletion test/reaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ test("#278 do not rerun if expr output doesn't change structurally", t => {
var values = [];

var d = reaction(mobx.asStructure(
() => users.map(user => user.uppername)
() => users.map(user => user.uppername)
), newValue => {
values.push(newValue);
}, true)
Expand All @@ -245,3 +245,22 @@ test("#278 do not rerun if expr output doesn't change structurally", t => {
]);
t.end();
})

test("throws when the max iterations over reactions are done", t => {
var foo = mobx.observable({
a: 1,
});

mobx.autorun("bar", () => {
var x = foo.a;
foo.a = Math.random();
});

t.throws(
() => foo.a++,
new RegExp("Reaction doesn't converge to a stable state after 100 iterations\\. "
+ "Probably there is a cycle in the reactive function: Reaction\\[bar\\]")
);
mobx.extras.resetGlobalState();
t.end();
})

0 comments on commit caaf7c8

Please sign in to comment.