Skip to content

Commit

Permalink
Fix for transaction within transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
Pawel.Majewski committed May 21, 2017
1 parent e0eea85 commit 34fee0b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
1 change: 0 additions & 1 deletion lib/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export function startTransactionAction(name: string, transactionId: number, pare
};
}


export const COMMIT_TRANSACTION_ACTION_TYPE = 'CommitTransactionAction';
export interface CommitTransactionAction extends ActionInTransaction {
type: typeof COMMIT_TRANSACTION_ACTION_TYPE;
Expand Down
14 changes: 9 additions & 5 deletions lib/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,17 @@ function reduceStartTransactionAction(state: StateWithTransactions, action: Star
// and we have to remove cycle
delete beforeState.$$transactions;

let transaction: Transaction = {
id: transactionId,
name: action.payload.transactionName,
beforeState
};
if (action.meta.parentTransactionId) {
transaction.parentId = action.meta.parentTransactionId;
}
// and return state with updated list of transactions
return setTransactionsOnState(Object.assign({}, state),
updateTransaction(transactions, {
id: transactionId,
name: action.payload.transactionName,
beforeState
}));
updateTransaction(transactions, transaction));
}

function reduceRejectTransactionAction(state: StateWithTransactions, action: TransactionActions): any {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/example1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ describe('e2e example1', () => {
dispatch(searchExecutedAction(query));
dispatch(searchSuccessAction(
await service(query)));
transaction('searchTransaction', dispatch, async (): Promise<void> => {
await transaction('searchTransaction', dispatch, async (): Promise<void> => {
dispatch((subdispatch: Dispatch<any>, getState: () => MyState) => {
let beforeState = (<any>getState()).$$transactions[Zone.current.get(TRANSACTION_ID_ZONE_KEY)].beforeState;
expect(beforeState).eql({ search: { query: 'aa', results: [ 'aa' ] } });
Expand Down

0 comments on commit 34fee0b

Please sign in to comment.