Skip to content

Commit

Permalink
Cherry picked fix for #603
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Nov 17, 2016
1 parent 65591fb commit d0c4da7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 2.6.3

* Fixed #603: exceptions in transaction breaks future reactions
* Improved typings of `toJS`

# 2.6.2

* Changes related to `toJS` as mentioned in version `2.6.0` where not actually shipped. This has been fixed, so see release notes below.
Expand Down
8 changes: 5 additions & 3 deletions src/core/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import {isSpyEnabled, spyReportStart, spyReportEnd} from "./spy";
*/
export function transaction<T>(action: () => T, thisArg = undefined, report = true): T {
transactionStart(((action as any).name) || "anonymous transaction", thisArg, report);
const res = action.call(thisArg);
transactionEnd(report);
return res;
try {
return action.call(thisArg);
} finally {
transactionEnd(report);
}
}

export function transactionStart<T>(name: string, thisArg = undefined, report = true) {
Expand Down
23 changes: 23 additions & 0 deletions test/observables.js
Original file line number Diff line number Diff line change
Expand Up @@ -1614,3 +1614,26 @@ test('iscomputed', function(t) {
t.equal(mobx.isComputed(x, "b"), true)
t.end()
})

test('603 - transaction should not kill reactions', t => {
var a = observable(1)
var b = 1;
var d = mobx.autorun(() => { b = a.get() })

try {
mobx.transaction(() => {
a.set(2)
throw 3
})

} catch (e) {

}

t.equal(b, 2)
a.set(3)
t.equal(b, 3)

t.end()

})

0 comments on commit d0c4da7

Please sign in to comment.