Skip to content
This repository was archived by the owner on Aug 13, 2018. It is now read-only.

Commit a982a50

Browse files
committed
Fix state issues with TreeView in frame-table
1 parent 73f2bbb commit a982a50

File tree

1 file changed

+47
-16
lines changed

1 file changed

+47
-16
lines changed

data/components/frame-table.js

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,32 @@ 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.
@@ -136,22 +162,8 @@ var FrameRow = React.createFactory(React.createClass({
136162
}
137163
},
138164

139-
render: function() {
140-
var frame = this.props.frame;
141-
var data = frame.data;
142-
143-
var className = "frameRow " + (frame.sent ? "send" : "receive");
144-
var tooltipText = frame.sent ? "Sent" : "Received";
145-
146-
if (this.props.selection == frame) {
147-
className += " selected";
148-
}
149-
165+
buildPayload(frame) {
150166
var payload;
151-
var size = Str.formatSize(data.payload.length);
152-
var time = new Date(data.timeStamp / 1000);
153-
var timeText = time.getHours() + ":" + time.getMinutes() +
154-
":" + time.getSeconds() + "." + time.getMilliseconds();
155167

156168
// Test support for inline previews.
157169
if (frame.socketIo) {
@@ -171,9 +183,28 @@ var FrameRow = React.createFactory(React.createClass({
171183
});
172184
} else {
173185
// Fall back to showing a string
174-
payload = Str.cropString(data.payload, 50);
186+
payload = Str.cropString(frame.data.payload, 50);
187+
}
188+
return payload;
189+
},
190+
191+
render: function() {
192+
var frame = this.props.frame;
193+
var payload = this.state.payload;
194+
var data = frame.data;
195+
196+
var className = "frameRow " + (frame.sent ? "send" : "receive");
197+
var tooltipText = frame.sent ? "Sent" : "Received";
198+
199+
if (this.props.selection == frame) {
200+
className += " selected";
175201
}
176202

203+
var size = Str.formatSize(data.payload.length);
204+
var time = new Date(data.timeStamp / 1000);
205+
var timeText = time.getHours() + ":" + time.getMinutes() +
206+
":" + time.getSeconds() + "." + time.getMilliseconds();
207+
177208
return (
178209
tr({className: className, onClick: this.onClick},
179210
td({className: "direction"},

0 commit comments

Comments
 (0)