@@ -120,13 +120,40 @@ var FrameRow = React.createFactory(React.createClass({
120120
121121 displayName : "FrameRow" ,
122122
123+ getInitialState ( ) {
124+ return { } ;
125+ } ,
126+
127+ /**
128+ * Create TreeView sub-components in lifecycle methods so we
129+ * only generate them once and don't run into state issues
130+ * with the TreeView component.
131+ */
132+ componentWillMount ( ) {
133+ if ( this . props . frame ) {
134+ this . setState ( { payload : this . buildPayload ( this . props . frame ) } ) ;
135+ }
136+ } ,
137+
138+ /**
139+ * Create TreeView sub-components in lifecycle methods so we
140+ * only generate them once and don't run into state issues
141+ * with the TreeView component.
142+ */
143+ componentWillReceiveProps ( { frame } ) {
144+ if ( frame !== this . props . frame ) {
145+ this . setState ( { payload : this . buildPayload ( this . props . frame ) } ) ;
146+ }
147+ } ,
148+
123149 /**
124150 * Frames need to be re-rendered only if the selection changes.
125151 * This is an optimization that makes the list rendering a lot faster.
126152 */
127153 shouldComponentUpdate : function ( nextProps , nextState ) {
128- return this . props . frame == nextProps . selection ||
129- this . props . frame == this . props . selection ;
154+ return nextProps . selection !== this . props . selection && (
155+ this . props . frame == nextProps . selection ||
156+ this . props . frame == this . props . selection ) ;
130157 } ,
131158
132159 onClick : function ( ) {
@@ -135,8 +162,35 @@ var FrameRow = React.createFactory(React.createClass({
135162 }
136163 } ,
137164
165+ buildPayload ( frame ) {
166+ var payload ;
167+
168+ // Test support for inline previews.
169+ if ( frame . socketIo ) {
170+ payload = TreeView ( {
171+ key : "preview-socketio" ,
172+ data : { "Socket IO" : frame . socketIo } ,
173+ } ) ;
174+ } else if ( frame . sockJs ) {
175+ payload = TreeView ( {
176+ key : "preview-sockjs" ,
177+ data : { "SockJS" : frame . sockJs } ,
178+ } ) ;
179+ } else if ( frame . json ) {
180+ payload = TreeView ( {
181+ key : "preview-json" ,
182+ data : { "JSON" : frame . json } ,
183+ } ) ;
184+ } else {
185+ // Fall back to showing a string
186+ payload = Str . cropString ( frame . data . payload , 50 ) ;
187+ }
188+ return payload ;
189+ } ,
190+
138191 render : function ( ) {
139192 var frame = this . props . frame ;
193+ var payload = this . state . payload ;
140194 var data = frame . data ;
141195
142196 var className = "frameRow " + ( frame . sent ? "send" : "receive" ) ;
@@ -146,19 +200,11 @@ var FrameRow = React.createFactory(React.createClass({
146200 className += " selected" ;
147201 }
148202
149- var payload = Str . cropString ( data . payload , 50 ) ;
150- var size = Str . formatSize ( data . payload . length ) ;
203+ var size = Str . formatSize ( data . payload . length ) ;
151204 var time = new Date ( data . timeStamp / 1000 ) ;
152205 var timeText = time . getHours ( ) + ":" + time . getMinutes ( ) +
153206 ":" + time . getSeconds ( ) + "." + time . getMilliseconds ( ) ;
154207
155- // Test support for inline previews. The problem is the
156- // state of the TreeView component.
157- /*if (frame.socketIo) {
158- var data = { payload: frame.socketIo };
159- payload = TreeView({key: "detailsTabTree", data: data})
160- }*/
161-
162208 return (
163209 tr ( { className : className , onClick : this . onClick } ,
164210 td ( { className : "direction" } ,
0 commit comments