@@ -120,13 +120,40 @@ var FrameRow = React.createFactory(React.createClass({
120
120
121
121
displayName : "FrameRow" ,
122
122
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
+
123
149
/**
124
150
* Frames need to be re-rendered only if the selection changes.
125
151
* This is an optimization that makes the list rendering a lot faster.
126
152
*/
127
153
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 ) ;
130
157
} ,
131
158
132
159
onClick : function ( ) {
@@ -135,8 +162,35 @@ var FrameRow = React.createFactory(React.createClass({
135
162
}
136
163
} ,
137
164
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
+
138
191
render : function ( ) {
139
192
var frame = this . props . frame ;
193
+ var payload = this . state . payload ;
140
194
var data = frame . data ;
141
195
142
196
var className = "frameRow " + ( frame . sent ? "send" : "receive" ) ;
@@ -146,19 +200,11 @@ var FrameRow = React.createFactory(React.createClass({
146
200
className += " selected" ;
147
201
}
148
202
149
- var payload = Str . cropString ( data . payload , 50 ) ;
150
- var size = Str . formatSize ( data . payload . length ) ;
203
+ var size = Str . formatSize ( data . payload . length ) ;
151
204
var time = new Date ( data . timeStamp / 1000 ) ;
152
205
var timeText = time . getHours ( ) + ":" + time . getMinutes ( ) +
153
206
":" + time . getSeconds ( ) + "." + time . getMilliseconds ( ) ;
154
207
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
-
162
208
return (
163
209
tr ( { className : className , onClick : this . onClick } ,
164
210
td ( { className : "direction" } ,
0 commit comments