@@ -3,7 +3,7 @@ import React from "react";
33import { toType } from './../../helpers/util' ;
44import {
55 JsonBoolean , JsonFloat , JsonFunction , JsonInteger ,
6- JsonNan , JsonNull , JsonObject , JsonString
6+ JsonNan , JsonNull , JsonObject , JsonString , JsonUndefined
77} from './DataTypes' ;
88import VariableMeta from './../VariableMeta' ;
99
@@ -29,34 +29,47 @@ class rjvObject extends React.Component {
2929
3030 constructor ( props ) {
3131 super ( props ) ;
32+ this . init ( props ) ;
33+ }
3234
33- this . state . expanded = AttributeStore . get (
34- this . state . rjvId ,
35- this . state . state_key ,
36- 'expanded' ,
37- ! this . props . collapsed
38- ) ;
35+ state = { }
36+
37+ init = ( props ) => {
38+ const state = {
39+ rjvId : props . rjvId ,
40+ state_key : props . namespace . join ( '.' ) ,
41+ namespace : props . namespace ,
42+ indentWidth : props . indentWidth ,
43+ expanded : props . jsvRoot
44+ ? ! props . collapsed
45+ : AttributeStore . get (
46+ props . rjvId ,
47+ props . namespace ,
48+ 'expanded' ,
49+ ! props . collapsed
50+ ) ,
51+ object_type : ( props . type == 'array' ? 'array' : 'object' ) ,
52+ parent_type : ( props . type == 'array' ? 'array' : 'object' ) ,
53+ display_name : ( props . name ? props . name : '' )
54+ }
55+
56+ this . state = { ...this . state , ...state } ;
3957 }
4058
41- state = {
42- rjvId : this . props . rjvId ,
43- state_key : this . props . namespace . join ( '.' ) ,
44- namespace : this . props . namespace ,
45- indentWidth : this . props . indentWidth ,
46- expanded : null , //set in constructor
47- object_type : ( this . props . type == 'array' ? 'array' : 'object' ) ,
48- parent_type : ( this . props . type == 'array' ? 'array' : 'object' ) ,
49- display_name : ( this . props . name ? this . props . name : '' )
59+ componentWillReceiveProps ( nextProps ) {
60+ this . init ( nextProps ) ;
61+ this . setState ( this . state ) ;
5062 }
5163
5264 toggleCollapsed = ( ) => {
5365 this . state . expanded = ! this . state . expanded ;
5466 AttributeStore . set (
5567 this . state . rjvId ,
56- this . state . state_key ,
68+ this . state . namespace ,
5769 'expanded' ,
5870 this . state . expanded
5971 ) ;
72+
6073 this . setState ( this . state ) ;
6174 }
6275
@@ -81,9 +94,8 @@ class rjvObject extends React.Component {
8194 getObjectMetaData = ( src ) => {
8295 const size = Object . keys ( src ) . length ;
8396 const { rjvId, theme} = this . props ;
84- const props = { size, rjvId, theme, src} ;
8597 return (
86- < VariableMeta { .. .props } />
98+ < VariableMeta size = { size } { ... this . props } />
8799 ) ;
88100 }
89101
@@ -98,6 +110,7 @@ class rjvObject extends React.Component {
98110 const {
99111 object_type, display_name, expanded
100112 } = this . state ;
113+
101114 //expanded/collapsed icon
102115 let expanded_icon , object_padding_left = 0 ;
103116
@@ -124,7 +137,9 @@ class rjvObject extends React.Component {
124137 ) } >
125138 < span >
126139 < span onClick = { this . toggleCollapsed } { ...Theme ( theme , 'brace-row' ) } >
127- < span class = "icon-container" > { expanded_icon } </ span >
140+ < div class = "icon-container" { ...Theme ( theme , 'icon-container' ) } >
141+ { expanded_icon }
142+ </ div >
128143 {
129144 parent_type == 'array'
130145 ? < span { ...Theme ( theme , 'array-key' ) } key = { namespace } >
@@ -231,6 +246,8 @@ class rjvObject extends React.Component {
231246 return < JsonNull { ...props } /> ;
232247 case 'nan' :
233248 return < JsonNan { ...props } /> ;
249+ case 'undefined' :
250+ return < JsonUndefined { ...props } /> ;
234251 default :
235252 //catch-all for types that weren't anticipated
236253 return < div class = "object-value" { ...props } >
0 commit comments