Skip to content

Commit cc62aae

Browse files
committed
[transactions] Add transaction listener stats
1 parent afaba99 commit cc62aae

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/store.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,10 @@ export type StoreListenerStats = {
596596
* The number of InvalidCellListeners registered with the Store.
597597
*/
598598
invalidCell?: number;
599+
/**
600+
* The number of TransactionListeners registered with the Store.
601+
*/
602+
transaction?: number;
599603
};
600604

601605
/**

src/store.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
965965
cellIds: collPairSize(cellIdsListeners, collSize3),
966966
cell: collPairSize(cellListeners, collSize4),
967967
invalidCell: collPairSize(invalidCellListeners, collSize4),
968+
transaction: collPairSize(finishTransactionListeners),
968969
}
969970
: {};
970971

test/unit/store-advanced.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ describe('Stats', () => {
694694
cellIds: 0,
695695
cell: 0,
696696
invalidCell: 0,
697+
transaction: 0,
697698
};
698699
});
699700

@@ -723,5 +724,20 @@ describe('Stats', () => {
723724
expectedListenerStats[thing] = 0;
724725
expect(store.getListenerStats()).toEqual(expectedListenerStats);
725726
});
727+
test.each([['willFinishTransaction'], ['didFinishTransaction']])(
728+
'%s',
729+
(thing) => {
730+
const addListener =
731+
'add' + thing[0].toUpperCase() + thing.substr(1) + 'Listener';
732+
expect(((store as any)[addListener] as any)((): null => null)).toEqual(
733+
'0',
734+
);
735+
expectedListenerStats.transaction = 1;
736+
expect(store.getListenerStats()).toEqual(expectedListenerStats);
737+
store.delListener('0');
738+
expectedListenerStats.transaction = 0;
739+
expect(store.getListenerStats()).toEqual(expectedListenerStats);
740+
},
741+
);
726742
});
727743
});

0 commit comments

Comments
 (0)