File tree Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 1
1
import { PostModelActionCallback , PostModelActionHandleHook } from '../functions/hook/post-model-action-handle.hook.js' ;
2
+ import {
3
+ PostModelTransactionCallback ,
4
+ PostModelTransactionHandleHook ,
5
+ } from '../functions/hook/post-model-transaction-handle.hook.js' ;
2
6
import { AModule } from '../functions/module/module.abstract.js' ;
3
7
import { ModelSerializationService } from '../services/serialization/model/model-serialization.service.js' ;
4
8
import { Container } from './container.js' ;
5
9
6
10
export function Module ( {
7
11
postModelActionHandles = [ ] ,
12
+ postModelTransactionHandles = [ ] ,
8
13
} : {
9
- postModelActionHandles : { ACTION_NAME : string ; callback : PostModelActionCallback } [ ] ;
14
+ postModelActionHandles ?: { ACTION_NAME : string ; callback : PostModelActionCallback } [ ] ;
15
+ postModelTransactionHandles ?: { callback : PostModelTransactionCallback } [ ] ;
10
16
} ) : ( constructor : any ) => void {
11
17
return function ( constructor : any ) {
12
18
Container . get ( ModelSerializationService ) . then ( ( modelSerializationService ) => {
@@ -18,5 +24,9 @@ export function Module({
18
24
for ( const { ACTION_NAME , callback } of postModelActionHandles ) {
19
25
PostModelActionHandleHook . register ( ACTION_NAME , callback ) ;
20
26
}
27
+
28
+ for ( const { callback } of postModelTransactionHandles ) {
29
+ PostModelTransactionHandleHook . register ( callback ) ;
30
+ }
21
31
} ;
22
32
}
Original file line number Diff line number Diff line change
1
+ import { DiffMetadata } from '../diff/diff-metadata.js' ;
2
+ import { AHook } from './hook.abstract.js' ;
3
+
4
+ export type PostModelTransactionCallback = ( modelTransaction : DiffMetadata [ ] [ ] ) => Promise < void > ;
5
+
6
+ export class PostModelTransactionHandleHook extends AHook {
7
+ private static readonly callbacks : PostModelTransactionCallback [ ] = [ ] ;
8
+
9
+ static async apply ( modelTransaction : DiffMetadata [ ] [ ] ) : Promise < void > {
10
+ for ( const callback of this . callbacks ) {
11
+ await callback ( modelTransaction ) ;
12
+ }
13
+ }
14
+
15
+ static register ( callback : PostModelTransactionCallback ) : PostModelTransactionHandleHook {
16
+ this . callbacks . push ( callback ) ;
17
+ return this ;
18
+ }
19
+ }
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import { Container } from '../../decorators/container.js';
10
10
import { Factory } from '../../decorators/factory.decorator.js' ;
11
11
import { DiffMetadata } from '../../functions/diff/diff-metadata.js' ;
12
12
import { Diff , DiffAction } from '../../functions/diff/diff.js' ;
13
+ import { PostModelTransactionHandleHook } from '../../functions/hook/post-model-transaction-handle.hook.js' ;
13
14
import { IModelAction } from '../../models/model-action.interface.js' ;
14
15
import { OverlayDataRepository } from '../../overlays/overlay-data.repository.js' ;
15
16
import { IResourceAction } from '../../resources/resource-action.interface.js' ;
@@ -289,6 +290,9 @@ export class TransactionService {
289
290
yield resourceTransaction ;
290
291
}
291
292
293
+ // Run post transaction hooks.
294
+ await PostModelTransactionHandleHook . apply ( modelTransaction ) ;
295
+
292
296
return modelTransaction ;
293
297
}
294
298
You can’t perform that action at this time.
0 commit comments