@@ -2,7 +2,7 @@ import { ErrorBoundaryForwardedProps, FallbackComponent, withErrorBoundary } fro
22import { TreeState , TreeStore } from '@stoplight/tree-list' ;
33import { Intent , Spinner } from '@stoplight/ui-kit' ;
44import cn from 'classnames' ;
5- import { action , runInAction } from 'mobx' ;
5+ import { action } from 'mobx' ;
66import * as React from 'react' ;
77
88import { JSONSchema4 } from 'json-schema' ;
@@ -13,7 +13,6 @@ import { SchemaTree as SchemaTreeComponent } from './SchemaTree';
1313
1414export interface IJsonSchemaViewer {
1515 schema : JSONSchema4 ;
16- dereferencedSchema ?: JSONSchema4 ;
1716 style ?: object ;
1817 emptyText ?: string ;
1918 defaultExpandedDepth ?: number ;
@@ -33,10 +32,6 @@ export class JsonSchemaViewerComponent extends React.PureComponent<IJsonSchemaVi
3332 protected readonly tree : SchemaTree ;
3433 protected readonly treeState : TreeState ;
3534
36- public state = {
37- computing : false ,
38- } ;
39-
4035 constructor ( props : IJsonSchemaViewer & ErrorBoundaryForwardedProps ) {
4136 super ( props ) ;
4237
@@ -60,10 +55,16 @@ export class JsonSchemaViewerComponent extends React.PureComponent<IJsonSchemaVi
6055 }
6156
6257 protected get schema ( ) {
63- return this . props . dereferencedSchema || this . props . schema ;
58+ return this . props . schema ;
6459 }
6560
6661 protected renderSchema ( ) {
62+ if ( this . tree . count > 1 ) {
63+ for ( const child of this . tree ) {
64+ this . tree . removeNode ( child ) ;
65+ }
66+ }
67+
6768 this . tree . populate ( ) ;
6869 }
6970
@@ -74,17 +75,11 @@ export class JsonSchemaViewerComponent extends React.PureComponent<IJsonSchemaVi
7475 @action
7576 public componentDidUpdate ( prevProps : Readonly < IJsonSchemaViewer > ) {
7677 if ( this . treeStore . defaultExpandedDepth !== this . expandedDepth ) {
77- runInAction ( ( ) => {
78- this . treeStore . defaultExpandedDepth = this . expandedDepth ;
79- } ) ;
80- }
81-
82- if (
83- prevProps . schema !== this . props . schema ||
84- prevProps . dereferencedSchema !== this . props . dereferencedSchema ||
85- prevProps . mergeAllOf !== this . props . mergeAllOf
86- ) {
87- // todo: this doesn't work yet
78+ this . treeStore . defaultExpandedDepth = this . expandedDepth ;
79+ this . tree . expandedDepth = this . expandedDepth ;
80+ this . renderSchema ( ) ;
81+ } else if ( prevProps . schema !== this . props . schema || prevProps . mergeAllOf !== this . props . mergeAllOf ) {
82+ this . tree . schema = this . props . schema ;
8883 this . renderSchema ( ) ;
8984 }
9085 }
@@ -125,6 +120,6 @@ const JsonSchemaFallbackComponent: typeof FallbackComponent = ({ error }) => {
125120
126121export const JsonSchemaViewer = withErrorBoundary < IJsonSchemaViewer > ( JsonSchemaViewerComponent , {
127122 FallbackComponent : JsonSchemaFallbackComponent ,
128- recoverableProps : [ 'schema' , 'dereferencedSchema' ] ,
123+ recoverableProps : [ 'schema' ] ,
129124 reportErrors : false ,
130125} ) ;
0 commit comments