Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure transactions are always #505

Merged
merged 1 commit into from
May 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/@glimmer/runtime/lib/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export abstract class Environment {
}

begin() {
assert(!this._transaction, 'Cannot start a nested transaction');
assert(!this._transaction, 'a glimmer transaction was begun, but one already exists. You may have a nested transaction');
this._transaction = new Transaction();
}

Expand Down Expand Up @@ -359,8 +359,9 @@ export abstract class Environment {
}

commit() {
this.transaction.commit();
let transaction = this.transaction;
this._transaction = null;
transaction.commit();
}

attributeFor(element: Simple.Element, attr: string, isTrusting: boolean, namespace?: string): AttributeManager {
Expand Down
31 changes: 31 additions & 0 deletions packages/@glimmer/runtime/test/env-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { TestEnvironment } from "@glimmer/test-helpers";

QUnit.module('env');

QUnit.test('assert against nested transactions', assert => {
let env = new TestEnvironment();
env.begin();
assert.throws(() => env.begin(), 'a glimmer transaction was begun, but one already exists. You may have a nested transaction');
});

QUnit.test('ensure commit cleans up when it can', assert => {
let env = new TestEnvironment();
env.begin();

// ghetto stub
Object.defineProperty(env, 'transaction', {
get() {
return {
scheduledInstallManagers() : void { },
commit() : void {
throw new Error('something failed');
}
};
}
});

assert.throws(() => env.commit(), 'something failed'); // commit failed

// but a previous commit failing, does not cause a future transaction to fail to start
env.begin();
});