@@ -3,6 +3,7 @@ import { Component } from 'react';
3
3
import { AppStore } from '../services/' ;
4
4
import { RedocRawOptions } from '../services/RedocNormalizedOptions' ;
5
5
import { loadAndBundleSpec } from '../utils' ;
6
+ import { OpenAPISpec } from '../types' ;
6
7
7
8
interface StoreProviderProps {
8
9
specUrl ?: string ;
@@ -23,6 +24,8 @@ interface StoreProviderState {
23
24
export class StoreProvider extends Component < StoreProviderProps , StoreProviderState > {
24
25
store : AppStore ;
25
26
27
+ private _resolvedSpec : OpenAPISpec ;
28
+
26
29
constructor ( props : StoreProviderProps ) {
27
30
super ( props ) ;
28
31
@@ -43,10 +46,21 @@ export class StoreProvider extends Component<StoreProviderProps, StoreProviderSt
43
46
} ) ;
44
47
45
48
try {
46
- const resolvedSpec = await loadAndBundleSpec ( spec || specUrl ! ) ;
49
+ this . _resolvedSpec = await loadAndBundleSpec ( spec || specUrl ! ) ;
50
+ this . updateStore ( this . _resolvedSpec , specUrl , options ) ;
51
+ } catch ( e ) {
52
+ this . setState ( {
53
+ error : e ,
54
+ } ) ;
55
+ }
56
+ }
57
+
58
+ updateStore ( resolvedSpec , specUrl , options ) {
59
+ try {
47
60
this . setState ( {
48
61
loading : false ,
49
62
store : new AppStore ( resolvedSpec , specUrl , options ) ,
63
+ error : undefined ,
50
64
} ) ;
51
65
} catch ( e ) {
52
66
this . setState ( {
@@ -55,6 +69,16 @@ export class StoreProvider extends Component<StoreProviderProps, StoreProviderSt
55
69
}
56
70
}
57
71
72
+ componentWillReceiveProps ( nextProps ) {
73
+ if ( this . props . specUrl !== nextProps . specUrl || this . props . spec !== nextProps . spec ) {
74
+ setTimeout ( ( ) => this . load ( ) , 0 ) ;
75
+ return ;
76
+ }
77
+ if ( this . props . options !== nextProps . options && this . _resolvedSpec ) {
78
+ this . updateStore ( this . _resolvedSpec , nextProps . specUrl , nextProps . options ) ;
79
+ }
80
+ }
81
+
58
82
setError ( e ?: Error ) {
59
83
this . setState ( {
60
84
error : e ,
0 commit comments