@@ -51,7 +51,7 @@ export default class Preview implements PreviewInterface {
51
51
*
52
52
* @deprecated please use getOptionValue directly
53
53
*/
54
- public previewData = { } ;
54
+ public previewData : { [ key : string ] : KnockoutObservable < any > } = { } ;
55
55
56
56
/**
57
57
* Fields that should not be considered when evaluating whether an object has been configured.
@@ -605,16 +605,30 @@ export default class Preview implements PreviewInterface {
605
605
* @deprecated this function is only included to preserve backwards compatibility, use getOptionValue directly
606
606
*/
607
607
private populatePreviewData ( ) : void {
608
- const response : { [ key : string ] : ( ) => any } = { } ;
609
608
if ( this . config . fields ) {
610
609
_ . each ( this . config . fields , ( fields ) => {
611
610
_ . keys ( fields ) . forEach ( ( key : string ) => {
612
- response [ key ] = ( ) => {
613
- return this . getOptionValue ( key ) ;
614
- } ;
611
+ this . previewData [ key ] = ko . observable ( "" ) ;
615
612
} ) ;
616
613
} ) ;
617
614
}
618
- this . previewData = response ;
615
+
616
+ // Subscribe to this content types data in the store
617
+ this . contentType . dataStore . subscribe (
618
+ ( data : DataObject ) => {
619
+ _ . forEach ( data , ( value , key ) => {
620
+ const optionValue = this . getOptionValue ( key ) ;
621
+ if ( ko . isObservable ( this . previewData [ key ] ) ) {
622
+ this . previewData [ key ] ( optionValue ) ;
623
+ } else {
624
+ if ( _ . isArray ( optionValue ) ) {
625
+ this . previewData [ key ] = ko . observableArray ( optionValue ) ;
626
+ } else {
627
+ this . previewData [ key ] = ko . observable ( optionValue ) ;
628
+ }
629
+ }
630
+ } ) ;
631
+ } ,
632
+ ) ;
619
633
}
620
634
}
0 commit comments