@@ -42,6 +42,11 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
4242define ( [ "require" , "exports" , "rxjs/BehaviorSubject" , "aurelia-framework" , "./history" , "./middleware" , "./aurelia-store" ] , function ( require , exports , BehaviorSubject_1 , aurelia_framework_1 , history_1 , middleware_1 , aurelia_store_1 ) {
4343 "use strict" ;
4444 Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
45+ var PerformanceMeasurement ;
46+ ( function ( PerformanceMeasurement ) {
47+ PerformanceMeasurement [ "StartEnd" ] = "startEnd" ;
48+ PerformanceMeasurement [ "All" ] = "all" ;
49+ } ) ( PerformanceMeasurement = exports . PerformanceMeasurement || ( exports . PerformanceMeasurement = { } ) ) ;
4550 var Store = /** @class */ ( function ( ) {
4651 function Store ( initialState , options ) {
4752 this . initialState = initialState ;
@@ -130,6 +135,7 @@ define(["require", "exports", "rxjs/BehaviorSubject", "aurelia-framework", "./hi
130135 if ( ! this . actions . has ( reducer ) ) {
131136 throw new Error ( "Tried to dispatch an unregistered action " + reducer . name ) ;
132137 }
138+ performance . mark ( "dispatch-start" ) ;
133139 if ( this . options && this . options . logDispatchedActions ) {
134140 this . logger . info ( "Dispatching: " + reducer . name ) ;
135141 }
@@ -138,11 +144,12 @@ define(["require", "exports", "rxjs/BehaviorSubject", "aurelia-framework", "./hi
138144 case 1 :
139145 beforeMiddleswaresResult = _c . sent ( ) ;
140146 result = ( _b = action ) . reducer . apply ( _b , [ beforeMiddleswaresResult ] . concat ( params ) ) ;
147+ performance . mark ( "dispatch-after-reducer-" + reducer . name ) ;
141148 if ( ! result && typeof result !== "object" ) {
142149 throw new Error ( "The reducer has to return a new state" ) ;
143150 }
144151 apply = function ( newState ) { return __awaiter ( _this , void 0 , void 0 , function ( ) {
145- var resultingState ;
152+ var resultingState , measures , marks , totalDuration ;
146153 return __generator ( this , function ( _a ) {
147154 switch ( _a . label ) {
148155 case 0 : return [ 4 /*yield*/ , this . executeMiddlewares ( newState , middleware_1 . MiddlewarePlacement . After ) ] ;
@@ -155,6 +162,21 @@ define(["require", "exports", "rxjs/BehaviorSubject", "aurelia-framework", "./hi
155162 resultingState = history_1 . applyLimits ( resultingState , this . options . history . limit ) ;
156163 }
157164 this . _state . next ( resultingState ) ;
165+ performance . mark ( "dispatch-end" ) ;
166+ if ( this . options ) {
167+ if ( this . options . measurePerformance === PerformanceMeasurement . StartEnd ) {
168+ performance . measure ( "startEndDispatchDuration" , "dispatch-start" , "dispatch-end" ) ;
169+ measures = performance . getEntriesByName ( "startEndDispatchDuration" ) ;
170+ this . logger . info ( "Total duration " + measures [ 0 ] . duration + " of dispatched action " + reducer . name + ":" , measures ) ;
171+ }
172+ else if ( this . options . measurePerformance === PerformanceMeasurement . All ) {
173+ marks = performance . getEntriesByType ( "mark" ) ;
174+ totalDuration = marks [ marks . length - 1 ] . startTime - marks [ 0 ] . startTime ;
175+ this . logger . info ( "Total duration " + totalDuration + " of dispatched action " + reducer . name + ":" , marks ) ;
176+ }
177+ }
178+ performance . clearMarks ( ) ;
179+ performance . clearMeasures ( ) ;
158180 this . updateDevToolsState ( action . name , newState ) ;
159181 return [ 2 /*return*/ ] ;
160182 }
@@ -181,12 +203,12 @@ define(["require", "exports", "rxjs/BehaviorSubject", "aurelia-framework", "./hi
181203 return Array . from ( this . middlewares . values ( ) )
182204 . filter ( function ( middleware ) { return middleware . placement === placement ; } )
183205 . map ( function ( middleware ) { return middleware . reducer ; } )
184- . reduce ( function ( prev , curr ) { return __awaiter ( _this , void 0 , void 0 , function ( ) {
206+ . reduce ( function ( prev , curr , _ , _arr ) { return __awaiter ( _this , void 0 , void 0 , function ( ) {
185207 var result , _a , _b , e_2 ;
186208 return __generator ( this , function ( _c ) {
187209 switch ( _c . label ) {
188210 case 0 :
189- _c . trys . push ( [ 0 , 5 , , 7 ] ) ;
211+ _c . trys . push ( [ 0 , 5 , 7 , 8 ] ) ;
190212 _a = curr ;
191213 return [ 4 /*yield*/ , prev ] ;
192214 case 1 : return [ 4 /*yield*/ , _a . apply ( void 0 , [ _c . sent ( ) , ( placement === middleware_1 . MiddlewarePlacement . After ) ? this . _state . getValue ( ) : undefined ] ) ] ;
@@ -201,9 +223,16 @@ define(["require", "exports", "rxjs/BehaviorSubject", "aurelia-framework", "./hi
201223 case 4 : return [ 2 /*return*/ , _b ] ;
202224 case 5 :
203225 e_2 = _c . sent ( ) ;
226+ if ( this . options && this . options . propagateError ) {
227+ _arr = [ ] ;
228+ throw e_2 ;
229+ }
204230 return [ 4 /*yield*/ , prev ] ;
205231 case 6 : return [ 2 /*return*/ , _c . sent ( ) ] ;
206- case 7 : return [ 2 /*return*/ ] ;
232+ case 7 :
233+ performance . mark ( "dispatch-" + placement + "-" + curr . name ) ;
234+ return [ 7 /*endfinally*/ ] ;
235+ case 8 : return [ 2 /*return*/ ] ;
207236 }
208237 } ) ;
209238 } ) ; } , state ) ;
0 commit comments