@@ -10,6 +10,7 @@ import { takeUntil } from 'rxjs/operator/takeUntil';
10
10
11
11
import { STORE_DEVTOOLS_CONFIG , StoreDevtoolsConfig } from './config' ;
12
12
import { LiftedState } from './reducer' ;
13
+ import { PerformAction } from './actions' ;
13
14
import { applyOperators } from './utils' ;
14
15
15
16
export const ExtensionActionTypes = {
@@ -28,11 +29,13 @@ export interface ReduxDevtoolsExtensionConnection {
28
29
unsubscribe ( ) : void ;
29
30
send ( action : any , state : any ) : void ;
30
31
init ( state ?: any ) : void ;
32
+ error ( any : any ) : void ;
31
33
}
32
34
export interface ReduxDevtoolsExtensionConfig {
33
35
features ?: object | boolean ;
34
36
name : string | undefined ;
35
37
instanceId : string ;
38
+ maxAge ?: number ;
36
39
}
37
40
38
41
export interface ReduxDevtoolsExtension {
@@ -51,6 +54,7 @@ export interface ReduxDevtoolsExtension {
51
54
export class DevtoolsExtension {
52
55
private instanceId = `ngrx-store-${ Date . now ( ) } ` ;
53
56
private devtoolsExtension : ReduxDevtoolsExtension ;
57
+ private extensionConnection : ReduxDevtoolsExtensionConnection ;
54
58
55
59
liftedActions$ : Observable < any > ;
56
60
actions$ : Observable < any > ;
@@ -68,7 +72,26 @@ export class DevtoolsExtension {
68
72
return ;
69
73
}
70
74
71
- this . devtoolsExtension . send ( null , state , this . config , this . instanceId ) ;
75
+ // Check to see if the action requires a full update of the liftedState.
76
+ // If it is a simple action generated by the user's app, only send the
77
+ // action and the current state (fast).
78
+ //
79
+ // A full liftedState update (slow: serializes the entire liftedState) is
80
+ // only required when:
81
+ // a) redux-devtools-extension fires the @@Init action (ignored by
82
+ // @ngrx /store-devtools)
83
+ // b) an action is generated by an @ngrx module (e.g. @ngrx/effects/init
84
+ // or @ngrx /store/update-reducers)
85
+ // c) the state has been recomputed due to time-traveling
86
+ // d) any action that is not a PerformAction to err on the side of
87
+ // caution.
88
+ if ( action instanceof PerformAction ) {
89
+ const currentState = state . computedStates [ state . currentStateIndex ] . state ;
90
+ this . extensionConnection . send ( action . action , currentState ) ;
91
+ } else {
92
+ // Requires full state update;
93
+ this . devtoolsExtension . send ( null , state , this . config , this . instanceId ) ;
94
+ }
72
95
}
73
96
74
97
private createChangesObservable ( ) : Observable < any > {
@@ -77,15 +100,19 @@ export class DevtoolsExtension {
77
100
}
78
101
79
102
return new Observable ( subscriber => {
80
- const connection = this . devtoolsExtension . connect ( {
103
+ let extensionOptions : ReduxDevtoolsExtensionConfig = {
81
104
instanceId : this . instanceId ,
82
105
name : this . config . name ,
83
106
features : this . config . features ,
84
- } ) ;
107
+ } ;
108
+ if ( this . config . maxAge !== false /* support === 0 */ ) {
109
+ extensionOptions . maxAge = this . config . maxAge ;
110
+ }
111
+ const connection = this . devtoolsExtension . connect ( extensionOptions ) ;
112
+ this . extensionConnection = connection ;
85
113
connection . init ( ) ;
86
114
87
115
connection . subscribe ( ( change : any ) => subscriber . next ( change ) ) ;
88
-
89
116
return connection . unsubscribe ;
90
117
} ) ;
91
118
}
0 commit comments